I\'m working on tests for a Symfony2 project, and right now I\'m looking for a way to create tests involving entity objects without persisting them. The problem is: id
Another way is to create a child of your entity (this could live in the tests folder if you want to keep things clean), then add the "setId()" method to the child
class TestableEntity extends \My\Namespace\Entity
{
public function setId($id)
{
$this->id = $id;
return $this;
}
}
Your tests should then test the TestableEntity, rather than the real entity. As long as the "id" property in \My\Namespace\Entity is protected, rather than private, it can be set via the TestableEntity.