From fff058f44b9d2c5074bea3ec34033add7a5ddf84 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 8 Aug 2016 12:07:04 +0200 Subject: [PATCH] Created LoggerFactoryTest --- module/Common/config/dependencies.config.php | 2 + .../Common/test/Factory/LoggerFactoryTest.php | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 module/Common/test/Factory/LoggerFactoryTest.php diff --git a/module/Common/config/dependencies.config.php b/module/Common/config/dependencies.config.php index ea670d57..b0cd571a 100644 --- a/module/Common/config/dependencies.config.php +++ b/module/Common/config/dependencies.config.php @@ -2,6 +2,7 @@ use Acelaya\ZsmAnnotatedServices\Factory\V3\AnnotatedFactory; use Doctrine\Common\Cache\Cache; use Doctrine\ORM\EntityManager; +use Monolog\Logger; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Common\ErrorHandler; use Shlinkio\Shlink\Common\Factory\CacheFactory; @@ -38,6 +39,7 @@ return [ 'httpClient' => GuzzleHttp\Client::class, 'translator' => Translator::class, 'logger' => LoggerInterface::class, + Logger::class => LoggerInterface::class, AnnotatedFactory::CACHE_SERVICE => Cache::class, ], ], diff --git a/module/Common/test/Factory/LoggerFactoryTest.php b/module/Common/test/Factory/LoggerFactoryTest.php new file mode 100644 index 00000000..bf292a1f --- /dev/null +++ b/module/Common/test/Factory/LoggerFactoryTest.php @@ -0,0 +1,54 @@ +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()); + } +}