Reputation: 3498
I want to test this part:
if ($unitOfWork->getEntityState($entity) === $unitOfWork::STATE_NEW) { ....
I already have a MOCK of $unitOfWork. But UnitofWork hast a CONST "STATE_NEW" and I don't know how I can mock this? Because when I say, that method "getEntityState
" retuns the value "STATE_NEW
", I want to say, that $unitOfWork::STATE_NEW
is equal to the return Value and so it is going the if-condition!
Has anyone an idea?
I already tried:
$unitOfWorkMock->expects($this->once())
->method('STATE_NEW')
->will($this->returnValue('STATE_NEW'));
...but doesn't work! ALso this ist not possible:
$unitOfWorkMock::STATE_NEW = 2;
To get my Mock of the unitOfWork i Call:
private function getUnitOfWorkMock()
{
return $this->getMockBuilder('\Doctrine\ORM\UnitOfWork')
->disableOriginalConstructor()
->getMock();
}
Upvotes: 0
Views: 1662
Reputation: 26719
You don't need to mock constants, as basically mock objects extends the real objects and they have all of their constants.
$unitOfWorkMock->expects($this->once())
->method('getEntityState')
->will($this->returnValue($unitOfWorkMock::STATE_NEW));
Upvotes: 1