add m:n test for data loader
* refactor tests of DataFixtures
This commit is contained in:
parent
e87c020313
commit
eece448443
|
@ -31,8 +31,7 @@ class YamlDataDumperTest extends TestCase
|
||||||
->save($this->con)
|
->save($this->con)
|
||||||
;
|
;
|
||||||
|
|
||||||
$filename = tempnam(sys_get_temp_dir(), 'yaml_datadumper_test');
|
$filename = $this->getTempFile();
|
||||||
@unlink($filename);
|
|
||||||
|
|
||||||
$loader = new YamlDataDumper(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
$loader = new YamlDataDumper(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
||||||
$loader->dump($filename);
|
$loader->dump($filename);
|
||||||
|
@ -52,7 +51,5 @@ YAML;
|
||||||
|
|
||||||
$result = file_get_contents($filename);
|
$result = file_get_contents($filename);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
@unlink($filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,8 @@ use Propel\PropelBundle\DataFixtures\Loader\XmlDataLoader;
|
||||||
*/
|
*/
|
||||||
class XmlDataLoaderTest extends TestCase
|
class XmlDataLoaderTest extends TestCase
|
||||||
{
|
{
|
||||||
protected $tmpfile;
|
public function testXmlLoad()
|
||||||
|
|
||||||
protected function setUp()
|
|
||||||
{
|
{
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$fixtures = <<<XML
|
$fixtures = <<<XML
|
||||||
<Fixtures>
|
<Fixtures>
|
||||||
<BookAuthor Namespace="Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader">
|
<BookAuthor Namespace="Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader">
|
||||||
|
@ -35,19 +31,11 @@ class XmlDataLoaderTest extends TestCase
|
||||||
</Book>
|
</Book>
|
||||||
</Fixtures>
|
</Fixtures>
|
||||||
XML;
|
XML;
|
||||||
$this->tmpfile = (string) tmpfile();
|
|
||||||
file_put_contents($this->tmpfile, $fixtures);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown()
|
$filename = $this->getTempFile($fixtures);
|
||||||
{
|
|
||||||
unlink($this->tmpfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testXmlLoad()
|
|
||||||
{
|
|
||||||
$loader = new XmlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
$loader = new XmlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
||||||
$loader->load(array($this->tmpfile), 'default');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
|
||||||
$this->assertCount(1, $books);
|
$this->assertCount(1, $books);
|
||||||
|
|
|
@ -19,12 +19,8 @@ use Propel\PropelBundle\DataFixtures\Loader\YamlDataLoader;
|
||||||
*/
|
*/
|
||||||
class YamlDataLoaderTest extends TestCase
|
class YamlDataLoaderTest extends TestCase
|
||||||
{
|
{
|
||||||
protected $tmpfile;
|
public function testYamlLoadOneToMany()
|
||||||
|
|
||||||
protected function setUp()
|
|
||||||
{
|
{
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$fixtures = <<<YAML
|
$fixtures = <<<YAML
|
||||||
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor:
|
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor:
|
||||||
BookAuthor_1:
|
BookAuthor_1:
|
||||||
|
@ -37,19 +33,10 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book:
|
||||||
author_id: BookAuthor_1
|
author_id: BookAuthor_1
|
||||||
|
|
||||||
YAML;
|
YAML;
|
||||||
$this->tmpfile = (string) tmpfile();
|
$filename = $this->getTempFile($fixtures);
|
||||||
file_put_contents($this->tmpfile, $fixtures);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown()
|
|
||||||
{
|
|
||||||
unlink($this->tmpfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testYamlLoad()
|
|
||||||
{
|
|
||||||
$loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
$loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
||||||
$loader->load(array($this->tmpfile), 'default');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
|
||||||
$this->assertCount(1, $books);
|
$this->assertCount(1, $books);
|
||||||
|
@ -57,4 +44,68 @@ YAML;
|
||||||
$book = $books[0];
|
$book = $books[0];
|
||||||
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor', $book->getBookAuthor());
|
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor', $book->getBookAuthor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testYamlLoadManyToMany()
|
||||||
|
{
|
||||||
|
$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" phpName="YamlManyToManyBook">
|
||||||
|
<column name="id" type="integer" primaryKey="true" />
|
||||||
|
<column name="name" type="varchar" size="255" />
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table name="author" phpName="YamlManyToManyAuthor">
|
||||||
|
<column name="id" type="integer" primaryKey="true" />
|
||||||
|
<column name="name" type="varchar" size="255" />
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table name="book_author" phpName="YamlManyToManyBookAuthor">
|
||||||
|
<column name="book_id" type="integer" required="true" primaryKey="true" />
|
||||||
|
<column name="author_id" type="integer" required="true" primaryKey="true" />
|
||||||
|
|
||||||
|
<foreign-key foreignTable="book" phpName="Book" onDelete="CASCADE" onUpdate="CASCADE">
|
||||||
|
<reference local="book_id" foreign="id" />
|
||||||
|
</foreign-key>
|
||||||
|
<foreign-key foreignTable="author" phpName="Author" onDelete="CASCADE" onUpdate="CASCADE">
|
||||||
|
<reference local="author_id" foreign="id" />
|
||||||
|
</foreign-key>
|
||||||
|
</table>
|
||||||
|
</database>
|
||||||
|
XML;
|
||||||
|
|
||||||
|
$fixtures = <<<YAML
|
||||||
|
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyAuthor:
|
||||||
|
Author_1:
|
||||||
|
name: 'A famous one'
|
||||||
|
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBook:
|
||||||
|
Book_1:
|
||||||
|
name: 'An important one'
|
||||||
|
Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookAuthor:
|
||||||
|
BookAuthor_1:
|
||||||
|
book_id: Book_1
|
||||||
|
author_id: Author_1
|
||||||
|
|
||||||
|
YAML;
|
||||||
|
|
||||||
|
$filename = $this->getTempFile($fixtures);
|
||||||
|
|
||||||
|
$builder = new \PropelQuickBuilder();
|
||||||
|
$builder->setSchema($schema);
|
||||||
|
$con = $builder->build();
|
||||||
|
|
||||||
|
$loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader');
|
||||||
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookPeer::doSelect(new \Criteria(), $con);
|
||||||
|
$this->assertCount(1, $books);
|
||||||
|
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBook', $books[0]);
|
||||||
|
|
||||||
|
$authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyAuthorPeer::doSelect(new \Criteria(), $con);
|
||||||
|
$this->assertCount(1, $authors);
|
||||||
|
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyAuthor', $authors[0]);
|
||||||
|
|
||||||
|
$bookAuthors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookAuthorPeer::doSelect(new \Criteria(), $con);
|
||||||
|
$this->assertCount(1, $bookAuthors);
|
||||||
|
$this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookAuthor', $bookAuthors[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,13 @@ class TestCase extends BaseTestCase
|
||||||
*/
|
*/
|
||||||
protected $con;
|
protected $con;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of created temp files to be removed.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $tmpFiles = array();
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -57,4 +64,32 @@ XML;
|
||||||
|
|
||||||
$this->con = $builder->build();
|
$this->con = $builder->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
foreach ($this->tmpFiles as $eachFile) {
|
||||||
|
@unlink($eachFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tmpFiles = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the name of a created temporary file containing the given content.
|
||||||
|
*
|
||||||
|
* @param string $content
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getTempFile($content = '')
|
||||||
|
{
|
||||||
|
$filename = tempnam(sys_get_temp_dir(), 'propelbundle-datafixtures-test');
|
||||||
|
@unlink($filename);
|
||||||
|
|
||||||
|
file_put_contents($filename, $content);
|
||||||
|
|
||||||
|
$this->tmpFiles[] = $filename;
|
||||||
|
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue