Last active
March 21, 2019 12:08
-
-
Save kanian/e95356dcd09b043201b036eca21f16a7 to your computer and use it in GitHub Desktop.
Sample Customer Service Unit Test with DI 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
<?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