File tree Expand file tree Collapse file tree
Tests/DataFixtures/Loader Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,7 +51,12 @@ protected function transformDataToArray($file)
5151 $ args = func_get_args ();
5252 array_shift ($ args );
5353
54- echo Yaml::dump (call_user_func_array (array ($ generator , $ type ), $ args )) . "\n" ;
54+ $ value = call_user_func_array (array ($ generator , $ type ), $ args );
55+ if ($ value instanceof \DateTime) {
56+ $ value = $ value ->format ('Y-m-d H:i:s ' );
57+ }
58+
59+ echo Yaml::dump ($ value ) . "\n" ;
5560 };
5661 } else {
5762 $ faker = function ($ text ) {
Original file line number Diff line number Diff line change @@ -321,6 +321,37 @@ public function testLoadWithFaker()
321321 $ this ->assertRegexp ('#[\w ]+# ' , $ book ->getDescription ());
322322 }
323323
324+ public function testLoadWithFakerDateTime ()
325+ {
326+ if (!class_exists ('Faker\Factory ' )) {
327+ $ this ->markTestSkipped ('Faker is mandatory ' );
328+ }
329+
330+ $ fixtures = <<<YAML
331+ Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book:
332+ Book_1:
333+ id: '1'
334+ name: <?php \$faker('dateTimeThisMonth'); ?>
335+ description: <?php \$faker('sentence'); ?>
336+
337+ YAML ;
338+ $ filename = $ this ->getTempFile ($ fixtures );
339+ $ container = $ this ->getContainer ();
340+ $ container ->set ('faker.generator ' , \Faker \Factory::create ());
341+
342+ $ loader = new YamlDataLoader (__DIR__ .'/../../Fixtures/DataFixtures/Loader ' , $ container );
343+ $ loader ->load (array ($ filename ), 'default ' );
344+
345+ $ books = \Propel \Bundle \PropelBundle \Tests \Fixtures \DataFixtures \Loader \BookPeer::doSelect (new \Criteria (), $ this ->con );
346+ $ this ->assertCount (1 , $ books );
347+
348+ $ book = $ books [0 ];
349+ $ this ->assertRegExp ('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/ ' , $ book ->getName ());
350+
351+ $ datetime = new \DateTime ($ book ->getName ());
352+ $ this ->assertInstanceOf ('DateTime ' , $ datetime );
353+ }
354+
324355 public function testLoadWithInheritedRelationship ()
325356 {
326357 $ schema = <<<XML
You can’t perform that action at this time.
0 commit comments