Permalink
Browse files

Add some tests for adding a child object to fill a parent based relat…

…ionship in fixtures (refs #195)
  • Loading branch information...
1 parent 7733e98 commit dfeb22b2685f7b5e6b2216bc0494a9b281a6489c @jpetitcolas jpetitcolas committed Nov 29, 2012
Showing with 57 additions and 0 deletions.
  1. +57 −0 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
@@ -321,4 +321,61 @@ public function testLoadWithFaker()
$this->assertNotEquals('null', strtolower($book->getDescription()));
$this->assertRegexp('#[\w ]+#', $book->getDescription());
}
+
+ public function testLoadWithInheritedRelationship()
+ {
+ $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_inherited_relationship" phpName="YamlInheritedRelationshipBook">
+ <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
+ <column name="name" type="varchar" size="255" />
+ <column name="author_id" type="integer" required="true" />
+ <foreign-key foreignTable="table_author_inherited_relationship" phpName="Author">
+ <reference local="author_id" foreign="id" />
+ </foreign-key>
+ </table>
+
+ <table name="table_author_inherited_relationship" phpName="YamlInheritedRelationshipAuthor">
+ <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
+ <column name="name" type="varchar" size="255" />
+ </table>
+
+ <table name="table_nobelized_author_inherited_relationship" phpName="YamlInheritedRelationshipNobelizedAuthor">
+ <column name="nobel_year" type="integer" />
+ <behavior name="concrete_inheritance">
+ <parameter name="extends" value="table_author_inherited_relationship" />
+ </behavior>
+ </table>
+
+</database>
+XML;
+
+ $fixtures = <<<YAML
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipNobelizedAuthor:
+ NobelizedAuthor_1:
+ nobel_year: 2012
+
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipBook:
+ Book_1:
+ name: 'Supplice du santal'
+ author_id: NobelizedAuthor_1
+YAML;
+
+ $filename = $this->getTempFile($fixtures);
+
+ $builder = new \PropelQuickBuilder();
+ $builder->setSchema($schema);
+ $con = $builder->build();
+
+ $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
+ $loader->load(array($filename), 'default');
+
+ $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipBookPeer::doSelect(new \Criteria(), $con);
+ $this->assertCount(1, $books);
+
+ $book = $books[0];
+ $author = $book->getAuthor();
+ $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipAuthor', $author);
+ }
}

0 comments on commit dfeb22b

Please sign in to comment.