Skip to content

Instantly share code, notes, and snippets.

@fabiocarneiro
Created August 25, 2015 14:14
Show Gist options
  • Save fabiocarneiro/471618d78f91dc75555b to your computer and use it in GitHub Desktop.
Save fabiocarneiro/471618d78f91dc75555b to your computer and use it in GitHub Desktop.
<?php
class ExampleFactory
{
/**
* @param DI $di
*/
public function __invoke(DI $di)
{
$dependency = $di->get(Dependency::class);
return new Example($dependency);
}
}
<?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