From 3b4ce8e784ae81f990439177e59a5f910dc95404 Mon Sep 17 00:00:00 2001 From: clombardot Date: Wed, 25 Apr 2012 16:11:30 +0200 Subject: [PATCH] Enable php in yaml fixtures Make easiest loading of serialized datas in object columns --- DataFixtures/Loader/YamlDataLoader.php | 10 ++++++++ .../Loader/YamlDataLoaderTest.php | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/DataFixtures/Loader/YamlDataLoader.php b/DataFixtures/Loader/YamlDataLoader.php index 7c16a52..b21138f 100644 --- a/DataFixtures/Loader/YamlDataLoader.php +++ b/DataFixtures/Loader/YamlDataLoader.php @@ -19,6 +19,16 @@ use Symfony\Component\Yaml\Yaml; */ class YamlDataLoader extends AbstractDataLoader { + /** + * {@inheritdoc} + */ + public function __construct($rootDir) + { + parent::__construct($rootDir); + + Yaml::enablePhpParsing(true); + } + /** * {@inheritdoc} */ diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index f80d80f..eba3835 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -135,4 +135,28 @@ YAML; $author = $authors[0]; $this->assertEquals('A famous one', $author->getName()); } + + public function testLoaderWithPhp() + { + $fixtures = << + +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()); + } }