Skip to content
Browse files

Merge pull request #199 from pixel-cookers/fix-load-fixture-object

[fixtures] allow loading array to object column
  • Loading branch information...
2 parents fd80526 + 70b32dc commit cc1a2dc8bce9e35212a58e16f0c26f94e1211038 @willdurand willdurand committed Dec 22, 2012
Showing with 34 additions and 1 deletion.
  1. +1 −1 DataFixtures/Loader/AbstractDataLoader.php
  2. +33 −0 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
View
2 DataFixtures/Loader/AbstractDataLoader.php
@@ -178,7 +178,7 @@ protected function loadDataFromArray($data = null)
} catch (PropelException $e) {
// Check whether this is actually an array stored in the object.
if ('Cannot fetch TableMap for undefined table: '.substr($name, 0, -1) === $e->getMessage()) {
- if ('ARRAY' !== $tableMap->getColumn($name)->getType()) {
+ if ('ARRAY' !== $tableMap->getColumn($name)->getType() && 'OBJECT' !== $tableMap->getColumn($name)->getType()) {
throw $e;
}
}
View
33 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
@@ -378,4 +378,37 @@ public function testLoadWithInheritedRelationship()
$author = $book->getAuthor();
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipAuthor', $author);
}
+
+ public function testLoadArrayToObjectType()
+ {
+ $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_with_object" phpName="YamlBookWithObject">
+ <column name="id" type="integer" primaryKey="true" />
+ <column name="name" type="varchar" size="255" />
+ <column name="options" type="object" />
+ </table>
+</database>
+XML;
+ $fixtures = <<<YAML
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObject:
+ book1:
+ name: my book
+ options: {opt1: 2012, opt2: 140, inner: {subOpt: 123}}
+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');
+
+ $book = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObjectQuery::create(null, $con)->findOne();
+
+ $this->assertInstanceOf('\Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObject', $book);
+ $this->assertEquals(array('opt1' => 2012, 'opt2' => 140, 'inner' => array('subOpt' => 123)), $book->getOptions());
+ }
}

0 comments on commit cc1a2dc

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