data-fixtures icon indicating copy to clipboard operation
data-fixtures copied to clipboard

Verify if reference is null (and skip all NULLs) while serializing references

Open kniziol opened this issue 10 years ago • 3 comments
trafficstars

Why?

  1. It's required to avoid error spl_object_hash() expects parameter 1 to be object, null given while running functional tests
  2. 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 avatar Feb 13 '15 18:02 kniziol

@kniziol Can you demonstrate with a test?

jwage avatar Mar 21 '15 17:03 jwage

@jwage This problem occurs when you're using liip/functional-test-bundle repo and:

  1. You are loading DataFixtures using Liip\FunctionalTestBundle\Test\WebTestCase::loadFixtures() method
  2. Some of the references to the fixtures are null, because they were deleted
  3. DataFixtures are serialized using $executor->getReferenceRepository()->save($backup) method
  4. And here is the essence of problem: Doctrine\Common\DataFixtures\ProxyReferenceRepository::serialize() method doesn't verify provided $reference

kniziol avatar Mar 24 '15 07:03 kniziol

@kniziol Thanks for the explanation. Can you rebase the PR and add a test case for the fix?

jwage avatar Mar 24 '15 14:03 jwage