diff --git a/Tests/DataFixtures/Dumper/YamlDataDumperTest.php b/Tests/DataFixtures/Dumper/YamlDataDumperTest.php index e4aa627..4803c84 100644 --- a/Tests/DataFixtures/Dumper/YamlDataDumperTest.php +++ b/Tests/DataFixtures/Dumper/YamlDataDumperTest.php @@ -31,8 +31,7 @@ class YamlDataDumperTest extends TestCase ->save($this->con) ; - $filename = tempnam(sys_get_temp_dir(), 'yaml_datadumper_test'); - @unlink($filename); + $filename = $this->getTempFile(); $loader = new YamlDataDumper(__DIR__.'/../../Fixtures/DataFixtures/Loader'); $loader->dump($filename); @@ -52,7 +51,5 @@ YAML; $result = file_get_contents($filename); $this->assertEquals($expected, $result); - - @unlink($filename); } } diff --git a/Tests/DataFixtures/Loader/XmlDataLoaderTest.php b/Tests/DataFixtures/Loader/XmlDataLoaderTest.php index b5f57fd..958fe8a 100644 --- a/Tests/DataFixtures/Loader/XmlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/XmlDataLoaderTest.php @@ -19,12 +19,8 @@ use Propel\PropelBundle\DataFixtures\Loader\XmlDataLoader; */ class XmlDataLoaderTest extends TestCase { - protected $tmpfile; - - protected function setUp() + public function testXmlLoad() { - parent::setUp(); - $fixtures = << @@ -35,19 +31,11 @@ class XmlDataLoaderTest extends TestCase XML; - $this->tmpfile = (string) tmpfile(); - file_put_contents($this->tmpfile, $fixtures); - } - protected function tearDown() - { - unlink($this->tmpfile); - } + $filename = $this->getTempFile($fixtures); - public function testXmlLoad() - { $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); $this->assertCount(1, $books); diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index b09f761..a15fe0a 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -19,12 +19,8 @@ use Propel\PropelBundle\DataFixtures\Loader\YamlDataLoader; */ class YamlDataLoaderTest extends TestCase { - protected $tmpfile; - - protected function setUp() + public function testYamlLoadOneToMany() { - parent::setUp(); - $fixtures = <<tmpfile = (string) tmpfile(); - file_put_contents($this->tmpfile, $fixtures); - } + $filename = $this->getTempFile($fixtures); - protected function tearDown() - { - unlink($this->tmpfile); - } - - public function testYamlLoad() - { $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); $this->assertCount(1, $books); @@ -57,4 +44,68 @@ YAML; $book = $books[0]; $this->assertInstanceOf('Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor', $book->getBookAuthor()); } + + public function testYamlLoadManyToMany() + { + $schema = << + + + +
+ + + + +
+ + + + + + + + + + + +
+ +XML; + + $fixtures = <<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]); + } } diff --git a/Tests/DataFixtures/TestCase.php b/Tests/DataFixtures/TestCase.php index 6111db3..8a5e52a 100644 --- a/Tests/DataFixtures/TestCase.php +++ b/Tests/DataFixtures/TestCase.php @@ -22,6 +22,13 @@ class TestCase extends BaseTestCase */ protected $con; + /** + * The list of created temp files to be removed. + * + * @var array + */ + protected $tmpFiles = array(); + protected function setUp() { parent::setUp(); @@ -57,4 +64,32 @@ XML; $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; + } }