data-fixtures
data-fixtures copied to clipboard
Verify if reference is null (and skip all NULLs) while serializing references
trafficstars
Why?
- It's required to avoid error
spl_object_hash() expects parameter 1 to be object, null givenwhile running functional tests - This problem occurs when some of loaded entities are deleted. After that there are references that points to
null.
Example of stack trace:
/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1540
/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php:78
/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php:79
/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php:144
/vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php:337
@kniziol Can you demonstrate with a test?
@jwage This problem occurs when you're using liip/functional-test-bundle repo and:
- You are loading DataFixtures using
Liip\FunctionalTestBundle\Test\WebTestCase::loadFixtures()method - Some of the references to the fixtures are
null, because they were deleted - DataFixtures are serialized using
$executor->getReferenceRepository()->save($backup)method - And here is the essence of problem:
Doctrine\Common\DataFixtures\ProxyReferenceRepository::serialize()method doesn't verify provided$reference
@kniziol Thanks for the explanation. Can you rebase the PR and add a test case for the fix?