2016-08-08 13:07:04 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-08-08 13:07:04 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Common\Factory;
|
|
|
|
|
|
|
|
use Monolog\Logger;
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-08 13:07:04 +03:00
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use Shlinkio\Shlink\Common\Factory\LoggerFactory;
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
|
|
|
|
|
|
class LoggerFactoryTest extends TestCase
|
|
|
|
{
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var LoggerFactory */
|
2018-11-20 21:37:22 +03:00
|
|
|
private $factory;
|
2016-08-08 13:07:04 +03:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->factory = new LoggerFactory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function serviceIsCreated()
|
|
|
|
{
|
|
|
|
/** @var Logger $instance */
|
|
|
|
$instance = $this->factory->__invoke(new ServiceManager(), '');
|
|
|
|
$this->assertInstanceOf(LoggerInterface::class, $instance);
|
|
|
|
$this->assertEquals('Logger', $instance->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function nameIsSetFromOptions()
|
|
|
|
{
|
|
|
|
/** @var Logger $instance */
|
|
|
|
$instance = $this->factory->__invoke(new ServiceManager(), '', ['logger_name' => 'Foo']);
|
|
|
|
$this->assertInstanceOf(LoggerInterface::class, $instance);
|
|
|
|
$this->assertEquals('Foo', $instance->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function serviceNameOverwritesOptionsLoggerName()
|
|
|
|
{
|
|
|
|
/** @var Logger $instance */
|
|
|
|
$instance = $this->factory->__invoke(new ServiceManager(), 'Logger_Shlink', ['logger_name' => 'Foo']);
|
|
|
|
$this->assertInstanceOf(LoggerInterface::class, $instance);
|
|
|
|
$this->assertEquals('Shlink', $instance->getName());
|
|
|
|
}
|
|
|
|
}
|