I am testing a service with PHPUnit.
I am using setUp() to create mock objects of the dependencies that my service accepts, like this:
public function setUp()
{
$this->fooManagerMock = $this->getFooManagerMock();
$this->barManagerMock = $this->getBarManagerMock();
$this->treeManagerMock = $this->getTreeManagerMock();
$this->loggerMock = $this->getLoggerMock();
$this->myService = new MyService($this->fooManagerMock, $this->barManagerMock, $this->treeManagerMock, $this->loggerMock);
}
Bundle\Tests\Service\MyTest::testServiceWithValidData
/**
* @dataProvider getServiceValidCaseData
*/
public function testServiceWithValidData($case)
{
$this->assertTrue($this->myService->serve($fooArray));
}
It turns out that a entity manager that in my serve() function, I am having something like this:
return $this->fooManager->find($fooId) !== null;
in this case $this->fooManager is instance of Mock_FooManager_4038382a and the whole test fails.
Any suggestions are more than welcome.
Aucun commentaire:
Enregistrer un commentaire