add test for YamlDataDumper
This commit is contained in:
parent
3d54ececfd
commit
4d9a49b35c
|
@ -18,40 +18,76 @@ use Propel\PropelBundle\DataFixtures\Dumper\YamlDataDumper;
|
|||
*/
|
||||
class YamlDataDumperTest extends TestCase
|
||||
{
|
||||
public function testTransformArrayToData()
|
||||
public function setUp()
|
||||
{
|
||||
$expected = <<<YML
|
||||
\Foo\Bar:
|
||||
fb1:
|
||||
Id: 10
|
||||
Title: Hello
|
||||
fb2:
|
||||
Id: 20
|
||||
Title: World
|
||||
parent::setUp();
|
||||
|
||||
YML;
|
||||
$this->loadPropelQuickBuilder();
|
||||
|
||||
$array = array(
|
||||
'\Foo\Bar' => array(
|
||||
'fb1' => array('Id' => 10, 'Title' => 'Hello'),
|
||||
'fb2' => array('Id' => 20, 'Title' => 'World')
|
||||
)
|
||||
);
|
||||
$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" />
|
||||
|
||||
$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);
|
||||
<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 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 = <<<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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
59
Tests/Fixtures/DataFixtures/Loader/map/BookTableMap.php
Normal file
59
Tests/Fixtures/DataFixtures/Loader/map/BookTableMap.php
Normal file
|
@ -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
|
Loading…
Reference in a new issue