diff --git a/Tests/DataFixtures/Dumper/YamlDataDumperTest.php b/Tests/DataFixtures/Dumper/YamlDataDumperTest.php index 25876e1..946a039 100644 --- a/Tests/DataFixtures/Dumper/YamlDataDumperTest.php +++ b/Tests/DataFixtures/Dumper/YamlDataDumperTest.php @@ -18,40 +18,76 @@ use Propel\PropelBundle\DataFixtures\Dumper\YamlDataDumper; */ class YamlDataDumperTest extends TestCase { - public function testTransformArrayToData() + public function setUp() { - $expected = <<loadPropelQuickBuilder(); - $array = array( - '\Foo\Bar' => array( - 'fb1' => array('Id' => 10, 'Title' => 'Hello'), - 'fb2' => array('Id' => 20, 'Title' => 'World') - ) - ); + $schema = << + + + + - $loader = new TestableYamlDataDumper(); - $result = $loader->transformArrayToData($array); - $this->assertSame($expected, $result); - } -} - -class TestableYamlDataDumper extends YamlDataDumper -{ - public function __construct() - { - } - - public function transformArrayToData($array) - { - return parent::transformArrayToData($array); + + + +
+ + + + +
+ +XML; + + $builder = new \PropelQuickBuilder(); + $builder->setSchema($schema); + if (!class_exists('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book')) { + $builder->setClassTargets(array('peer', 'object', 'query', 'peerstub', 'objectstub', 'querystub')); + } else { + $builder->setClassTargets(array()); + } + + $this->con = $builder->build(); + } + + 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 = tempnam(sys_get_temp_dir(), 'yaml_datadumper_test'); + @unlink($filename); + + $loader = new YamlDataDumper(__DIR__.'/../../Fixtures/DataFixtures/Loader'); + $loader->dump($filename); + + $expected = <<assertEquals($expected, $result); + + @unlink($filename); } } diff --git a/Tests/Fixtures/DataFixtures/Loader/map/BookAuthorTableMap.php b/Tests/Fixtures/DataFixtures/Loader/map/BookAuthorTableMap.php new file mode 100644 index 0000000..7486dd0 --- /dev/null +++ b/Tests/Fixtures/DataFixtures/Loader/map/BookAuthorTableMap.php @@ -0,0 +1,58 @@ +setName('book_author'); + $this->setPhpName('BookAuthor'); + $this->setClassname('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor'); + $this->setPackage('vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader'); + $this->setUseIdGenerator(false); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null); + // validators + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('Book', 'Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book', RelationMap::ONE_TO_MANY, array('id' => 'author_id', ), 'RESTRICT', 'CASCADE', 'Books'); + } // buildRelations() + +} // AuthorTableMap diff --git a/Tests/Fixtures/DataFixtures/Loader/map/BookTableMap.php b/Tests/Fixtures/DataFixtures/Loader/map/BookTableMap.php new file mode 100644 index 0000000..c5ec02c --- /dev/null +++ b/Tests/Fixtures/DataFixtures/Loader/map/BookTableMap.php @@ -0,0 +1,59 @@ +setName('book'); + $this->setPhpName('Book'); + $this->setClassname('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book'); + $this->setPackage('vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader'); + $this->setUseIdGenerator(false); + // columns + $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); + $this->addColumn('NAME', 'Name', 'VARCHAR', false, 255, null); + $this->addForeignKey('AUTHOR_ID', 'AuthorId', 'INTEGER', 'book_author', 'ID', true, null, null); + // validators + } // initialize() + + /** + * Build the RelationMap objects for this table relationships + */ + public function buildRelations() + { + $this->addRelation('BookAuthor', 'Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor', RelationMap::MANY_TO_ONE, array('author_id' => 'id', ), 'RESTRICT', 'CASCADE'); + } // buildRelations() + +} // BookTableMap