Skip to content

Commit

Permalink
Merge pull request #45 from abacaphiliac/container-interop
Browse files Browse the repository at this point in the history
add container-interop as a dev dependency
  • Loading branch information
abacaphiliac authored Sep 9, 2017
2 parents 2202738 + b6011f6 commit 8e12299
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"zendframework/zend-servicemanager": "^2 || ^3"
},
"require-dev": {
"container-interop/container-interop": "^1.0",
"jakub-onderka/php-parallel-lint": "^0.9",
"johnkary/phpunit-speedtrap": "^1.0",
"squizlabs/php_codesniffer": "^2.9",
Expand Down
54 changes: 54 additions & 0 deletions test/EnliteMonologTest/Service/ContainerMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace EnliteMonologTest\Service;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Zend\ServiceManager\ServiceManager;

class ContainerMock implements ContainerInterface
{
/** @var ServiceManager */
private $services;

/**
* ContainerMock constructor.
* @param ServiceManager $services
*/
public function __construct(ServiceManager $services)
{
$this->services = $services;
}

/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return mixed Entry.
*/
public function get($id)
{
return $this->services->get($id);
}

/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
*
* @param string $id Identifier of the entry to look for.
*
* @return bool
*/
public function has($id)
{
return $this->services->has($id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ public function testCanCreate()
{
$services = new ServiceManager();

if (!$services instanceof ContainerInterface) {
self::markTestSkipped('container-interop/container-interop is required.');
}

$sut = new MonologServiceAbstractFactory();

$services->setService(
Expand All @@ -105,17 +101,13 @@ public function testCanCreate()
)
);

self::assertTrue($sut->canCreate($services, 'default'));
self::assertTrue($sut->canCreate(new ContainerMock($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(
Expand All @@ -127,7 +119,7 @@ public function testInvoke()
)
);

$logger = $sut($services, 'default');
$logger = $sut(new ContainerMock($services), 'default');

self::assertInstanceOf('\Monolog\Logger', $logger);
}
Expand Down
6 changes: 1 addition & 5 deletions test/EnliteMonologTest/Service/MonologServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,13 @@ 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');
$service = $sut(new ContainerMock($services), 'EnliteMonolog');
$this->assertInstanceOf('Monolog\Logger', $service);
$this->assertEquals('test', $service->getName());

Expand Down
12 changes: 2 additions & 10 deletions test/EnliteMonologTest/Service/MonologServiceInitializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ public function testInvoke()

$services = new ServiceManager();

if (!$services instanceof ContainerInterface) {
self::markTestSkipped('container-interop/container-interop is required.');
}

$services->setService('EnliteMonologService', $logger);

$sut = new MonologServiceInitializer();

self::assertNull($sut($services, $service));
self::assertNull($sut(new ContainerMock($services), $service));

self::assertSame($logger, $service->getMonologService());
}
Expand All @@ -108,12 +104,8 @@ public function testInvokeInvalidInstance()

$services = new ServiceManager();

if (!$services instanceof ContainerInterface) {
self::markTestSkipped('container-interop/container-interop is required.');
}

$sut = new MonologServiceInitializer();

self::assertNull($sut($services, $service));
self::assertNull($sut(new ContainerMock($services), $service));
}
}

0 comments on commit 8e12299

Please sign in to comment.