Created
August 25, 2015 14:14
-
-
Save fabiocarneiro/471618d78f91dc75555b to your computer and use it in GitHub Desktop.
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
<?php | |
class ExampleFactory | |
{ | |
/** | |
* @param DI $di | |
*/ | |
public function __invoke(DI $di) | |
{ | |
$dependency = $di->get(Dependency::class); | |
return new Example($dependency); | |
} | |
} |
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
<?php | |
public function ExampleFactoryTest extends TestCase | |
{ | |
public function testReturnsExampleConcreteInstance() | |
{ | |
$di = $this->getMock(DI::class); | |
$factory = new ExampleFactory($di); | |
$di->expects($this->once()) | |
->method('get') | |
->with(Dependency::class) | |
->willReturn( | |
$this->getMock(Dependency::class) | |
); | |
$this->assertInstanceOf(Example::class, $factory()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment