diff --git a/test/EnliteMonologTest/Service/MonologServiceAbstractFactoryTest.php b/test/EnliteMonologTest/Service/MonologServiceAbstractFactoryTest.php index c46406a..87db200 100644 --- a/test/EnliteMonologTest/Service/MonologServiceAbstractFactoryTest.php +++ b/test/EnliteMonologTest/Service/MonologServiceAbstractFactoryTest.php @@ -6,6 +6,8 @@ namespace EnliteMonologTest\Service; use EnliteMonolog\Service\MonologServiceAbstractFactory; +use Interop\Container\ContainerInterface; +use Monolog\Logger; use Zend\ServiceManager\ServiceManager; class MonologServiceAbstractFactoryTest extends \PHPUnit_Framework_TestCase @@ -79,4 +81,50 @@ public function testCreateServiceWithName() self::assertInstanceOf('\Monolog\Logger', $logger); } + + public function testCanCreate() + { + $services = new ServiceManager(); + + if (!$services instanceof ContainerInterface) { + self::markTestSkipped('container-interop/container-interop is required.'); + } + + $sut = new MonologServiceAbstractFactory(); + + $services->setService( + 'config', + array( + 'EnliteMonolog' => array( + 'default' => array() + ) + ) + ); + + self::assertTrue($sut->canCreate($services, 'default')); + } + + public function testInvoke() + { + $services = new ServiceManager(); + + if (!$services instanceof ContainerInterface) { + self::markTestSkipped('container-interop/container-interop is required.'); + } + + $sut = new MonologServiceAbstractFactory(); + + $services->setService( + 'config', + array( + 'EnliteMonolog' => array( + 'default' => array() + ) + ) + ); + + $logger = $sut($services, 'default'); + + self::assertInstanceOf('\Monolog\Logger', $logger); + } } diff --git a/test/EnliteMonologTest/Service/MonologServiceAwareTraitTest.php b/test/EnliteMonologTest/Service/MonologServiceAwareTraitTest.php new file mode 100644 index 0000000..7f69c71 --- /dev/null +++ b/test/EnliteMonologTest/Service/MonologServiceAwareTraitTest.php @@ -0,0 +1,24 @@ +getMockForTrait('\EnliteMonolog\Service\MonologServiceAwareTrait'); + + $logger = new Logger(__METHOD__); + + $trait->setMonologService($logger); + + self::assertSame($logger, $trait->getMonologService()); + } +} diff --git a/test/EnliteMonologTest/Service/MonologServiceFactoryTest.php b/test/EnliteMonologTest/Service/MonologServiceFactoryTest.php index f18f1ec..45cb0db 100644 --- a/test/EnliteMonologTest/Service/MonologServiceFactoryTest.php +++ b/test/EnliteMonologTest/Service/MonologServiceFactoryTest.php @@ -7,6 +7,7 @@ use EnliteMonolog\Service\MonologOptions; use EnliteMonolog\Service\MonologServiceFactory; +use Interop\Container\ContainerInterface; use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\LineFormatter; use Zend\ServiceManager\ServiceManager; @@ -385,4 +386,25 @@ public function testHandlerGetsDefaultFormatterWithDefaultDateFormat() self::assertContains('[2016-01-01 00:00:00]', $line); } + + public function testInvoke() + { + $services = new ServiceManager(); + + if (!$services instanceof ContainerInterface) { + self::markTestSkipped('container-interop/container-interop is required.'); + } + + $config = array('name' => 'test', 'handlers' => array(array('name' => 'Monolog\Handler\TestHandler'))); + + $services->setService('EnliteMonologOptions', new MonologOptions($config)); + + $sut = new MonologServiceFactory(); + + $service = $sut($services, 'EnliteMonolog'); + $this->assertInstanceOf('Monolog\Logger', $service); + $this->assertEquals('test', $service->getName()); + + $this->assertInstanceOf('Monolog\Handler\TestHandler', $service->popHandler()); + } }