engelsystem/tests/Unit/Logger/LoggerServiceProviderTest.php

56 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2017-10-31 13:40:13 +01:00
<?php
declare(strict_types=1);
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
2017-10-31 13:40:13 +01:00
{
$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
}
}