This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |