public function testYamlDump() { $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor(); $author->setName('A famous one')->save($this->con); $complementary = new \stdClass(); $complementary->first_word_date = '2012-01-01'; $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book(); $book->setName('An important one')->setAuthorId(1)->setComplementaryInfos($complementary)->save($this->con); $filename = $this->getTempFile(); $loader = new YamlDataDumper(__DIR__ . '/../../Fixtures/DataFixtures/Loader'); $loader->dump($filename); $expected = <<<YAML Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor: BookAuthor_1: id: '1' name: 'A famous one' Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book: Book_1: id: '1' name: 'An important one' author_id: BookAuthor_1 complementary_infos: !!php/object:O:8:"stdClass":1:{s:15:"first_word_date";s:10:"2012-01-01";} YAML; $result = file_get_contents($filename); $this->assertEquals($expected, $result); }
public function testWipesExistingData() { $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor(); $author->setName('Some famous author'); $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book(); $book->setName('Armageddon is near')->setBookAuthor($author)->save($this->con); $savedBook = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelectOne(new \Criteria(), $this->con); $this->assertInstanceOf('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book', $savedBook, 'The fixture has been saved correctly.'); $builder = $this->getMockBuilder('Propel\\PropelBundle\\DataFixtures\\Loader\\DataWiper'); $wipeout = $builder->setMethods(array('loadMapBuilders'))->disableOriginalConstructor()->getMock(); $dbMap = new \DatabaseMap('default'); $dbMap->addTableFromMapClass('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\map\\BookTableMap'); $reflection = new \ReflectionObject($wipeout); $property = $reflection->getProperty('dbMap'); $property->setAccessible(true); $property->setValue($wipeout, $dbMap); $wipeout->expects($this->once())->method('loadMapBuilders'); $wipeout->load(array(), 'default'); $this->assertCount(0, \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con)); }
public function testYamlDump() { $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor(); $author->setName('A famous one')->save($this->con); $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book(); $book->setName('An important one')->setAuthorId(1)->save($this->con); $filename = $this->getTempFile(); $loader = new YamlDataDumper(__DIR__ . '/../../Fixtures/DataFixtures/Loader'); $loader->dump($filename); $expected = <<<YAML Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor: BookAuthor_1: id: '1' name: 'A famous one' Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book: Book_1: id: '1' name: 'An important one' author_id: BookAuthor_1 YAML; $result = file_get_contents($filename); $this->assertEquals($expected, $result); }