Skip to content

Commit

Permalink
Merge pull request #33 from abacaphiliac/improve-coverage
Browse files Browse the repository at this point in the history
add tests to improve coverage
  • Loading branch information
abacaphiliac authored Sep 9, 2017
2 parents c2fdccd + 0d42d65 commit 4cf6074
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
24 changes: 24 additions & 0 deletions test/EnliteMonologTest/Service/MonologServiceAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace EnliteMonologTest\Service;

use EnliteMonolog\Service\MonologServiceAwareTrait;
use Monolog\Logger;

/**
* @requires PHP 5.4
*/
class MonologServiceAwareTraitTest extends \PHPUnit_Framework_TestCase
{
public function testSetMonologService()
{
/** @var MonologServiceAwareTrait $trait */
$trait = $this->getMockForTrait('\EnliteMonolog\Service\MonologServiceAwareTrait');

$logger = new Logger(__METHOD__);

$trait->setMonologService($logger);

self::assertSame($logger, $trait->getMonologService());
}
}
22 changes: 22 additions & 0 deletions test/EnliteMonologTest/Service/MonologServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 4cf6074

Please sign in to comment.