Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recursively merge fixtures #165

Merged
merged 1 commit into from
Jul 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DataFixtures/Loader/AbstractDataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function load($files = array(), $connectionName)
$content = $this->transformDataToArray($file);

if (count($content) > 0) {
$datas = array_merge($datas, $content);
$datas = array_merge_recursive($datas, $content);
$nbFiles++;
}
}
Expand Down
88 changes: 88 additions & 0 deletions Tests/DataFixtures/Loader/YamlDataLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,94 @@ public function testYamlLoadManyToMany()
$this->assertEquals('Les misérables', $authors[1]->getBooks()->get(0)->getName());
}

public function testYamlLoadManyToManyMultipleFiles()
{
$schema = <<<XML
<database name="default" package="vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader" defaultIdMethod="native">
<table name="table_book_multiple" phpName="YamlManyToManyMultipleFilesBook">
<column name="id" type="integer" primaryKey="true" />
<column name="name" type="varchar" size="255" />
</table>

<table name="table_author_multiple" phpName="YamlManyToManyMultipleFilesAuthor">
<column name="id" type="integer" primaryKey="true" />
<column name="name" type="varchar" size="255" />
</table>

<table name="table_book_author_multiple" phpName="YamlManyToManyMultipleFilesBookAuthor" isCrossRef="true">
<column name="book_id" type="integer" required="true" primaryKey="true" />
<column name="author_id" type="integer" required="true" primaryKey="true" />

<foreign-key foreignTable="table_book_multiple" phpName="Book" onDelete="CASCADE" onUpdate="CASCADE">
<reference local="book_id" foreign="id" />
</foreign-key>
<foreign-key foreignTable="table_author_multiple" phpName="Author" onDelete="CASCADE" onUpdate="CASCADE">
<reference local="author_id" foreign="id" />
</foreign-key>
</table>
</database>
XML;

$fixtures1 = <<<YAML
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook:
Book_2:
id: 2
name: 'Les misérables'

Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor:
Author_1:
id: 1
name: 'A famous one'

Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookAuthor:
BookAuthor_1:
book_id: Book_1
author_id: Author_1
YAML;

$fixtures2 = <<<YAML
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBook:
Book_1:
id: 1
name: 'An important one'

Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesAuthor:
Author_2:
id: 2
name: 'Victor Hugo'
table_book_author_multiples: [ Book_2 ]
YAML;

$filename1 = $this->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 = <<<YAML
Expand Down