Permalink
Browse files

Enable php in yaml fixtures

Make easiest loading of serialized datas in object columns
  • Loading branch information...
cedriclombardot committed Apr 25, 2012
1 parent c99afb0 commit 3b4ce8e784ae81f990439177e59a5f910dc95404
Showing with 34 additions and 0 deletions.
  1. +10 −0 DataFixtures/Loader/YamlDataLoader.php
  2. +24 −0 Tests/DataFixtures/Loader/YamlDataLoaderTest.php
@@ -19,6 +19,16 @@
*/
class YamlDataLoader extends AbstractDataLoader
{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct($rootDir)
+ {
+ parent::__construct($rootDir);
+
+ Yaml::enablePhpParsing(true);
+ }
+
/**
* {@inheritdoc}
*/
@@ -135,4 +135,28 @@ public function testLoadSelfReferencing()
$author = $authors[0];
$this->assertEquals('A famous one', $author->getName());
}
+
+ public function testLoaderWithPhp()
+ {
+ $fixtures = <<<YAML
+Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor:
+ BookAuthor_1:
+ id: '1'
+ name: <?php echo "to be announced"; ?>
+
+YAML;
+ $filename = $this->getTempFile($fixtures);
+
+ $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
+ $loader->load(array($filename), 'default');
+
+ $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
+ $this->assertCount(0, $books);
+
+ $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthorPeer::doSelect(new \Criteria(), $this->con);
+ $this->assertCount(1, $authors);
+
+ $author = $authors[0];
+ $this->assertEquals('to be announced', $author->getName());
+ }
}

0 comments on commit 3b4ce8e

Please sign in to comment.