Skip to content
This repository
Browse code

Merge pull request #165 from havvg/1.1

recursively merge YAML fixtures
  • Loading branch information...
commit 62eb1ec793065a858e311152e7737a453fb6f3c8 2 parents 554132c + 90a5977
William Durand willdurand authored
2  DataFixtures/Loader/AbstractDataLoader.php
@@ -62,7 +62,7 @@ public function load($files = array(), $connectionName)
62 62 $content = $this->transformDataToArray($file);
63 63
64 64 if (count($content) > 0) {
65   - $datas = array_merge($datas, $content);
  65 + $datas = array_merge_recursive($datas, $content);
66 66 $nbFiles++;
67 67 }
68 68 }
88 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
@@ -126,6 +126,94 @@ public function testYamlLoadManyToMany()
126 126 $this->assertEquals('Les misérables', $authors[1]->getBooks()->get(0)->getName());
127 127 }
128 128
  129 + public function testYamlLoadManyToManyMultipleFiles()
  130 + {
  131 + $schema = <<<XML
  132 +<database name="default" package="vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader" defaultIdMethod="native">
  133 + <table name="table_book_multiple" phpName="YamlManyToManyMultipleFilesBook">
  134 + <column name="id" type="integer" primaryKey="true" />
  135 + <column name="name" type="varchar" size="255" />
  136 + </table>
  137 +
  138 + <table name="table_author_multiple" phpName="YamlManyToManyMultipleFilesAuthor">
  139 + <column name="id" type="integer" primaryKey="true" />
  140 + <column name="name" type="varchar" size="255" />
  141 + </table>
  142 +
  143 + <table name="table_book_author_multiple" phpName="YamlManyToManyMultipleFilesBookAuthor" isCrossRef="true">
  144 + <column name="book_id" type="integer" required="true" primaryKey="true" />
  145 + <column name="author_id" type="integer" required="true" primaryKey="true" />
  146 +
  147 + <foreign-key foreignTable="table_book_multiple" phpName="Book" onDelete="CASCADE" onUpdate="CASCADE">
  148 + <reference local="book_id" foreign="id" />
  149 + </foreign-key>
  150 + <foreign-key foreignTable="table_author_multiple" phpName="Author" onDelete="CASCADE" onUpdate="CASCADE">
  151 + <reference local="author_id" foreign="id" />
  152 + </foreign-key>
  153 + </table>
  154 +</database>
  155 +XML;
  156 +
  157 + $fixtures1 = <<<YAML
  158 +Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook:
  159 + Book_2:
  160 + id: 2
  161 + name: 'Les misérables'
  162 +
  163 +Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor:
  164 + Author_1:
  165 + id: 1
  166 + name: 'A famous one'
  167 +
  168 +Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthor:
  169 + BookAuthor_1:
  170 + book_id: Book_1
  171 + author_id: Author_1
  172 +YAML;
  173 +
  174 + $fixtures2 = <<<YAML
  175 +Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook:
  176 + Book_1:
  177 + id: 1
  178 + name: 'An important one'
  179 +
  180 +Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor:
  181 + Author_2:
  182 + id: 2
  183 + name: 'Victor Hugo'
  184 + table_book_author_multiples: [ Book_2 ]
  185 +YAML;
  186 +
  187 + $filename1 = $this->getTempFile($fixtures1);
  188 + $filename2 = $this->getTempFile($fixtures2);
  189 +
  190 + $builder = new \PropelQuickBuilder();
  191 + $builder->setSchema($schema);
  192 + $con = $builder->build();
  193 +
  194 + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
  195 + $loader->load(array($filename1, $filename2), 'default');
  196 +
  197 + $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookPeer::doSelect(new \Criteria(), $con);
  198 + $this->assertCount(2, $books);
  199 + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook', $books[0]);
  200 + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook', $books[1]);
  201 +
  202 + $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthorPeer::doSelect(new \Criteria(), $con);
  203 + $this->assertCount(2, $authors);
  204 + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor', $authors[0]);
  205 + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor', $authors[1]);
  206 +
  207 + $bookAuthors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthorPeer::doSelect(new \Criteria(), $con);
  208 + $this->assertCount(2, $bookAuthors);
  209 + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthor', $bookAuthors[0]);
  210 + $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthor', $bookAuthors[1]);
  211 +
  212 + $this->assertEquals('Victor Hugo', $authors[1]->getName());
  213 + $this->assertTrue($authors[1]->getBooks()->contains($books[1]));
  214 + $this->assertEquals('Les misérables', $authors[1]->getBooks()->get(0)->getName());
  215 + }
  216 +
129 217 public function testLoadSelfReferencing()
130 218 {
131 219 $fixtures = <<<YAML

0 comments on commit 62eb1ec

Please sign in to comment.
Something went wrong with that request. Please try again.