Skip to content

Instantly share code, notes, and snippets.

@kanian
Last active March 21, 2019 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanian/e95356dcd09b043201b036eca21f16a7 to your computer and use it in GitHub Desktop.
Save kanian/e95356dcd09b043201b036eca21f16a7 to your computer and use it in GitHub Desktop.
Sample Customer Service Unit Test with DI Container
<?php
//..
class CustomerServiceTest extends TestCase
{
//..
protected function makeProphecy($classOrInstance) : void {
if($classOrInstance === null){
return ;
}
$a = function () use($classOrInstance){
return $this->prophesize($classOrInstance);
};
$this->c->singletonize($classOrInstance, \Closure::bind($a, $this));
}
protected function setUp()
{
//some setup here
$this->makeProphecy(CustomerRepositoryInterface::class);
$this->c['CustomerService'] = function ($c) {
return new CustomerService($c[CustomerRepositoryInterface::class]->reveal());
};
$this->customer = $this->objectMother->getUnSavedCustomer();
$this->savedCustomer = $this->objectMother->getCustomer();
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment