Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge 8a7fc18 into cb23064
Browse files Browse the repository at this point in the history
  • Loading branch information
tux-rampage authored Dec 7, 2017
2 parents cb23064 + 8a7fc18 commit 0915a13
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Container/GeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @see https://github.com/zendframework/zend-di for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-di/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Di\Container;

use Psr\Container\ContainerInterface;

class GeneratorFactory
{
public function create(ContainerInterface $container)
{
// TODO: Implement the factory
}

public function __invoke(ContainerInterface $container)
{
return $this->create($container);
}
}
67 changes: 67 additions & 0 deletions test/Container/GeneratorFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* @see https://github.com/zendframework/zend-di for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-di/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Di\Container;

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Zend\Di\CodeGenerator\InjectorGenerator;
use Zend\Di\Config;
use Zend\Di\ConfigInterface;
use Zend\Di\Container\GeneratorFactory;
use Zend\Di\Injector;
use Zend\Di\InjectorInterface;

/**
* @covers Zend\Di\Container\GeneratorFactory
*
*/
class GeneratorFactoryTest extends TestCase
{
public function testInvokeCreatesGenerator()
{
$injector = new Injector();
$factory = new GeneratorFactory();

$result = $factory($injector->getContainer());
$this->assertInstanceOf(InjectorGenerator::class, $result);
}

/**
* Data provider for testFactoryUsesServiceFromContainer
*/
public function provideContainerServices()
{
return [
// serviceName, provided instance
'config' => [ConfigInterface::class, new Config()],
'injector' => [InjectorInterface::class, new Injector()]
];
}

/**
* @dataProvider provideContainerServices
*/
public function testFactoryUsesServiceFromContainer(string $serviceName, $instance): void
{
$container = $this->getMockBuilder(ContainerInterface::class)->getMockForAbstractClass();
$container->expects($this->atLeastOnce())
->method('has')
->with($serviceName)
->willReturn(true);

$container->method('has')->willReturn(false);

$container->expects($this->atLeastOnce())
->method('get')
->with($serviceName)
->willReturn($instance);

$factory = new GeneratorFactory();
$factory($container);
}
}

0 comments on commit 0915a13

Please sign in to comment.