interface EntityInterface { public function setAncestor(EntityInterface $parent); public function getAncestor(); public function addDescendant(EntityInterface $descendant); public function getName(); } abstract class Entity implements EntityInterface { protected $name; /** @var EntityInterface Ancestor */ protected $ancestor = null; /** @var EntityInterface Descendants */ public function __construct($name) { $this->name = $name; } public function getAncestor() { return $this->ancestor; } public function setAncestor(EntityInterface $ancestor) { $this->ancestor = $ancestor; } public function addDescendant(EntityInterface $descendant) { $descendant->setAncestor($this); $this->descendants[$descendant->getName()] = $descendant; } public function getName() { return $this->name; } }
Test wygląda tak:
class EntityTest extends PHPUnit_Framework_TestCase { public function testEntityDescendantCanBeSet() { $entity = $this->getMockBuilder(Entity::class) ->disableOriginalConstructor() ->getMock(); $descendant_entity = $this->getMockBuilder(Entity::class) ->disableOriginalConstructor() ->getMock(); $entity->expects($this->once()) ->method('addDescendant'); $descendant_entity->expects($this->once()) ->method('setAncestor'); $descendant_entity->expects($this->once()) ->method('getName') ->will($this->returnValue('entity_name')); $entity->addDescendant($descendant_entity); } }
Dostaję taki komunikat:
Cytat
1) EntityTest::testEntityDescendantCanBeSet
Expectation failed for method name is equal to <string:setAncestor> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.
Expectation failed for method name is equal to <string:setAncestor> when invoked 1 time(s).
Method was expected to be called 1 times, actually called 0 times.
Podobny komunikat jest dla getName jeśli test setAncestor jest zakomentowany. Co jest nie tak i jak to można przetestować?