engelsystem/tests/Unit/Logger/LoggerServiceProviderTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.8 KiB
PHP
Raw Normal View History

2017-10-31 13:40:13 +01:00
<?php
namespace Engelsystem\Test\Unit\Logger;
2017-10-31 13:40:13 +01:00
use Engelsystem\Helpers\Authenticator;
use Engelsystem\Logger\Logger;
2017-10-31 13:40:13 +01:00
use Engelsystem\Logger\LoggerServiceProvider;
use Engelsystem\Logger\UserAwareLogger;
2017-10-31 14:15:19 +01:00
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit\Framework\MockObject\MockObject;
2017-10-31 13:40:13 +01:00
use Psr\Log\LoggerInterface;
2017-10-31 14:15:19 +01:00
class LoggerServiceProviderTest extends ServiceProviderTest
2017-10-31 13:40:13 +01:00
{
/**
* @covers \Engelsystem\Logger\LoggerServiceProvider::register
2017-10-31 13:40:13 +01:00
*/
public function testRegister(): void
{
$serviceProvider = new LoggerServiceProvider($this->app);
$serviceProvider->register();
$this->assertInstanceOf(UserAwareLogger::class, $this->app->get('logger'));
$this->assertInstanceOf(UserAwareLogger::class, $this->app->get(LoggerInterface::class));
$this->assertInstanceOf(UserAwareLogger::class, $this->app->get(Logger::class));
$this->assertInstanceOf(UserAwareLogger::class, $this->app->get(UserAwareLogger::class));
}
/**
* @covers \Engelsystem\Logger\LoggerServiceProvider::boot
*/
public function testBoot(): void
{
/** @var Authenticator|MockObject $auth */
$auth = $this->getMockBuilder(Authenticator::class)
->disableOriginalConstructor()
->getMock();
/** @var UserAwareLogger|MockObject $log */
$log = $this->getMockBuilder(UserAwareLogger::class)
2018-08-31 01:55:05 +02:00
->disableOriginalConstructor()
2017-10-31 13:40:13 +01:00
->getMock();
$this->app->instance(Authenticator::class, $auth);
$this->app->instance(UserAwareLogger::class, $log);
2017-10-31 13:40:13 +01:00
$log->expects($this->once())
->method('setAuth')
->with($auth);
2017-10-31 13:40:13 +01:00
$serviceProvider = new LoggerServiceProvider($this->app);
$serviceProvider->boot();
2017-10-31 13:40:13 +01:00
}
}