diff --git a/DataFixtures/Loader/YamlDataLoader.php b/DataFixtures/Loader/YamlDataLoader.php index 35da263..e8df432 100644 --- a/DataFixtures/Loader/YamlDataLoader.php +++ b/DataFixtures/Loader/YamlDataLoader.php @@ -51,7 +51,12 @@ class YamlDataLoader extends AbstractDataLoader $args = func_get_args(); array_shift($args); - echo Yaml::dump(call_user_func_array(array($generator, $type), $args)) . "\n"; + $value = call_user_func_array(array($generator, $type), $args); + if ($value instanceof \DateTime) { + $value = $value->format('Y-m-d H:i:s'); + } + + echo Yaml::dump($value) . "\n"; }; } else { $faker = function($text) { diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index 75165b5..017e20b 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -321,6 +321,37 @@ YAML; $this->assertRegexp('#[\w ]+#', $book->getDescription()); } + public function testLoadWithFakerDateTime() + { + if (!class_exists('Faker\Factory')) { + $this->markTestSkipped('Faker is mandatory'); + } + + $fixtures = << + description: + +YAML; + $filename = $this->getTempFile($fixtures); + $container = $this->getContainer(); + $container->set('faker.generator', \Faker\Factory::create()); + + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $container); + $loader->load(array($filename), 'default'); + + $books = \Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con); + $this->assertCount(1, $books); + + $book = $books[0]; + $this->assertRegExp('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $book->getName()); + + $datetime = new \DateTime($book->getName()); + $this->assertInstanceOf('DateTime', $datetime); + } + public function testLoadWithInheritedRelationship() { $schema = <<