Method for loading fixtures from file added. #79

Merged
merged 1 commit into from Mar 21, 2015

Projects

None yet

8 participants

@malef
Contributor
malef commented Oct 13, 2012

This PR allows to load fixtures from a single file by adding loadFromFile method to Loader class.

In some projects which require various fixture sets (e.g. for different setups for various environments) being able to point fixtures only by directory is quite a pain as some fixtures may be reused in few sets. Moving them to subdirectories doesn't solve the problem in some cases as namespaces would have to be adjusted accordingly. There were some issues reported concerning the lack of this feature both in this repo and in DoctrineFixturesBundle. They didn't however contain any code needed to accomplish the goal.

I am planning also to provide a related PR to DoctrineFixturesBundle when this one meets your acceptance.

PHPUnit tests fail in one case, but it does not seem related and it fails also on master. Namely:

There was 1 failure:

1) Doctrine\Tests\Common\DataFixtures\ProxyReferenceRepositoryTest::testReferenceReconstruction
Failed asserting that Doctrine\Tests\Common\DataFixtures\TestEntity\Role Object (...) is an instance of class "Doctrine\ORM\Proxy\Proxy".

/home/mariusz/Development/data-fixtures/tests/Doctrine/Tests/Common/DataFixtures/ProxyReferenceRepositoryTest.php:116
@erichard

This feature is interesting ! I would like to see this PR merged.

@mcz-agnitio

Bump 2?

@Nyholm
Nyholm commented Oct 30, 2014

👍

@KingCrunch KingCrunch commented on the diff Oct 30, 2014
lib/Doctrine/Common/DataFixtures/Loader.php
+ */
+ private function loadFromIterator(\Iterator $iterator)
+ {
+ $includedFiles = array();
+ foreach ($iterator as $file) {
+ if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
+ continue;
+ }
+ $sourceFile = realpath($file->getPathName());
+ require_once $sourceFile;
+ $includedFiles[] = $sourceFile;
+ }
+
+ $fixtures = array();
+ $declared = get_declared_classes();
+ foreach ($declared as $className) {
@KingCrunch
KingCrunch Oct 30, 2014

This looks like it can be pretty expensive

@mab-agnitio
mab-agnitio Oct 30, 2014

Well, if you look at the original code, you will see that this is the same way it was done for directories. And loading fixtures is not something you do every 5 minutes, so even if it takes few seconds I don't consider this to be any problem.

@lavoiesl
Member

Can we please get this merged? This is really annoying.

Even more infuriating, the documentation of the command wrongly says it supports specifying files: The directory or file to load data fixtures from.

@jwage jwage merged commit 601f006 into doctrine:master Mar 21, 2015
@jwage jwage referenced this pull request Mar 21, 2015
Closed

Load fixture from file #175

@lavoiesl
Member

testReferenceReconstruction error will be fixed by #177

@lavoiesl lavoiesl added this to the 1.1 milestone Mar 23, 2015
@lavoiesl lavoiesl referenced this pull request in doctrine/DoctrineFixturesBundle Mar 23, 2015
Merged

Allow fixtures loading from a single file #97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment