diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index 36f4359..24e83f1 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -62,7 +62,7 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa $content = $this->transformDataToArray($file); if (count($content) > 0) { - $datas = array_merge($datas, $content); + $datas = array_merge_recursive($datas, $content); $nbFiles++; } } diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index 4c8a2ea..cc0ce87 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -126,6 +126,94 @@ YAML; $this->assertEquals('Les misérables', $authors[1]->getBooks()->get(0)->getName()); } + public function testYamlLoadManyToManyMultipleFiles() + { + $schema = << + + + +
+ + + + +
+ + + + + + + + + + + +
+ +XML; + + $fixtures1 = <<getTempFile($fixtures1); + $filename2 = $this->getTempFile($fixtures2); + + $builder = new \PropelQuickBuilder(); + $builder->setSchema($schema); + $con = $builder->build(); + + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader'); + $loader->load(array($filename1, $filename2), 'default'); + + $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookPeer::doSelect(new \Criteria(), $con); + $this->assertCount(2, $books); + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook', $books[0]); + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook', $books[1]); + + $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthorPeer::doSelect(new \Criteria(), $con); + $this->assertCount(2, $authors); + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor', $authors[0]); + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor', $authors[1]); + + $bookAuthors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthorPeer::doSelect(new \Criteria(), $con); + $this->assertCount(2, $bookAuthors); + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthor', $bookAuthors[0]); + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthor', $bookAuthors[1]); + + $this->assertEquals('Victor Hugo', $authors[1]->getName()); + $this->assertTrue($authors[1]->getBooks()->contains($books[1])); + $this->assertEquals('Les misérables', $authors[1]->getBooks()->get(0)->getName()); + } + public function testLoadSelfReferencing() { $fixtures = <<