2017-10-31 13:40:13 +01:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
namespace Engelsystem\Test\Unit\Logger;
|
2017-10-31 13:40:13 +01:00
|
|
|
|
2020-02-29 20:53:25 +01:00
|
|
|
use Engelsystem\Helpers\Authenticator;
|
|
|
|
use Engelsystem\Logger\Logger;
|
2017-10-31 13:40:13 +01:00
|
|
|
use Engelsystem\Logger\LoggerServiceProvider;
|
2020-04-19 20:41:38 +02:00
|
|
|
use Engelsystem\Logger\UserAwareLogger;
|
2017-10-31 14:15:19 +01:00
|
|
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
2019-04-24 10:45:00 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
/**
|
2020-02-29 20:53:25 +01:00
|
|
|
* @covers \Engelsystem\Logger\LoggerServiceProvider::register
|
2017-10-31 13:40:13 +01:00
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testRegister(): void
|
2017-10-31 13:40:13 +01:00
|
|
|
{
|
2020-02-29 20:53:25 +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
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testBoot(): void
|
2020-02-29 20:53:25 +01:00
|
|
|
{
|
|
|
|
/** @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();
|
|
|
|
|
2020-02-29 20:53:25 +01:00
|
|
|
$this->app->instance(Authenticator::class, $auth);
|
|
|
|
$this->app->instance(UserAwareLogger::class, $log);
|
2017-10-31 13:40:13 +01:00
|
|
|
|
2020-02-29 20:53:25 +01:00
|
|
|
$log->expects($this->once())
|
|
|
|
->method('setAuth')
|
|
|
|
->with($auth);
|
2017-10-31 13:40:13 +01:00
|
|
|
|
2020-02-29 20:53:25 +01:00
|
|
|
$serviceProvider = new LoggerServiceProvider($this->app);
|
|
|
|
$serviceProvider->boot();
|
2017-10-31 13:40:13 +01:00
|
|
|
}
|
|
|
|
}
|