Skip to content

Loading…

hotfix/datadumper class ordering #111

Merged
merged 2 commits into from

3 participants

@havvg
Propel member

Replacing #95.

@havvg havvg referenced this pull request
Closed

Fixes Class ordering bug #95

@havvg
Propel member
@willdurand willdurand merged commit 1fcb057 into propelorm:master
@willdurand
Propel member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2012
  1. @tacman @havvg

    get class (not table) for ordering

    tacman committed with havvg
  2. @havvg

    add test for YamlDataDumper

    havvg committed
View
2 DataFixtures/Dumper/AbstractDataDumper.php
@@ -185,7 +185,7 @@ protected function fixOrderingOfForeignKeyData($classes)
foreach ($tableMap->getColumns() as $column) {
if ($column->isForeignKey()) {
$relatedTable = $this->dbMap->getTable($column->getRelatedTableName());
- $relatedTablePos = array_search($relatedTable->getPhpName(), $classes);
+ $relatedTablePos = array_search($relatedTable->getClassname(), $classes);
// check if relatedTable is after the current table
if ($relatedTablePos > $i) {
View
96 Tests/DataFixtures/Dumper/YamlDataDumperTest.php
@@ -18,40 +18,76 @@
*/
class YamlDataDumperTest extends TestCase
{
- public function testTransformArrayToData()
+ public function setUp()
{
- $expected = <<<YML
-\Foo\Bar:
- fb1:
- Id: 10
- Title: Hello
- fb2:
- Id: 20
- Title: World
-
-YML;
-
- $array = array(
- '\Foo\Bar' => array(
- 'fb1' => array('Id' => 10, 'Title' => 'Hello'),
- 'fb2' => array('Id' => 20, 'Title' => 'World')
- )
- );
-
- $loader = new TestableYamlDataDumper();
- $result = $loader->transformArrayToData($array);
- $this->assertSame($expected, $result);
- }
-}
+ parent::setUp();
-class TestableYamlDataDumper extends YamlDataDumper
-{
- public function __construct()
- {
+ $this->loadPropelQuickBuilder();
+
+ $schema = <<<XML
+<database name="default" package="vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader" namespace="Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader" defaultIdMethod="native">
+ <table name="book">
+ <column name="id" type="integer" primaryKey="true" />
+ <column name="name" type="varchar" size="255" />
+ <column name="author_id" type="integer" required="false" defaultValue="null" />
+
+ <foreign-key foreignTable="book_author" onDelete="RESTRICT" onUpdate="CASCADE">
+ <reference local="author_id" foreign="id" />
+ </foreign-key>
+ </table>
+
+ <table name="book_author">
+ <column name="id" type="integer" primaryKey="true" />
+ <column name="name" type="varchar" size="255" />
+ </table>
+</database>
+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 transformArrayToData($array)
+ public function testYamlDump()
{
- return parent::transformArrayToData($array);
+ $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 = <<<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);
+
+ @unlink($filename);
}
}
View
58 Tests/Fixtures/DataFixtures/Loader/map/BookAuthorTableMap.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\map;
+
+use \RelationMap;
+use \TableMap;
+
+
+/**
+ * This class defines the structure of the 'author' table.
+ *
+ *
+ *
+ * This map class is used by Propel to do runtime db structure discovery.
+ * For example, the createSelectSql() method checks the type of a given column used in an
+ * ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
+ * (i.e. if it's a text column type).
+ *
+ * @package propel.generator.vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader.map
+ */
+class BookAuthorTableMap extends TableMap
+{
+
+ /**
+ * The (dot-path) name of this class
+ */
+ const CLASS_NAME = 'vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader.map.BookAuthorTableMap';
+
+ /**
+ * Initialize the table attributes, columns and validators
+ * Relations are not initialized by this method since they are lazy loaded
+ *
+ * @return void
+ * @throws PropelException
+ */
+ public function initialize()
+ {
+ // attributes
+ $this->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
View
59 Tests/Fixtures/DataFixtures/Loader/map/BookTableMap.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\map;
+
+use \RelationMap;
+use \TableMap;
+
+
+/**
+ * This class defines the structure of the 'book' table.
+ *
+ *
+ *
+ * This map class is used by Propel to do runtime db structure discovery.
+ * For example, the createSelectSql() method checks the type of a given column used in an
+ * ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
+ * (i.e. if it's a text column type).
+ *
+ * @package propel.generator.vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader.map
+ */
+class BookTableMap extends TableMap
+{
+
+ /**
+ * The (dot-path) name of this class
+ */
+ const CLASS_NAME = 'vendor.bundles.Propel.PropelBundle.Tests.Fixtures.DataFixtures.Loader.map.BookTableMap';
+
+ /**
+ * Initialize the table attributes, columns and validators
+ * Relations are not initialized by this method since they are lazy loaded
+ *
+ * @return void
+ * @throws PropelException
+ */
+ public function initialize()
+ {
+ // attributes
+ $this->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
Something went wrong with that request. Please try again.