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
It's little bit old but it's worthy to say that maybe the best way is to have helper method that is using Reflection to alter those protected values.
Example :
public function set($entity, $value, $propertyName = 'id')
{
$class = new ReflectionClass($entity);
$property = $class->getProperty($propertyName);
$property->setAccessible(true);
$property->setValue($entity, $value);
}
put that in base test class that you extends or have it in trait and just use it when you need something like that in test. In that way you will be able to write tests without having to create dirty changes.