[DataFixtures] Added few tests
This commit is contained in:
parent
3b0283b04d
commit
16fc0d190e
64
Tests/DataFixtures/XmlDataLoaderTest.php
Normal file
64
Tests/DataFixtures/XmlDataLoaderTest.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the PropelBundle package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Propel\PropelBundle\Tests\DataFixtures;
|
||||
|
||||
use Propel\PropelBundle\Tests\TestCase;
|
||||
use Propel\PropelBundle\DataFixtures\XmlDataLoader;
|
||||
|
||||
/**
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
*/
|
||||
class XmlDataLoaderTest extends TestCase
|
||||
{
|
||||
protected $tmpfile;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$fixtures = <<<XML
|
||||
<Fixtures>
|
||||
<Bar Namespace="\Foo">
|
||||
<fb1 Id="10" Title="Hello" />
|
||||
<fb2 Id="20" Title="World" />
|
||||
</Bar>
|
||||
</Fixtures>
|
||||
XML;
|
||||
$this->tmpfile = (string) tmpfile();
|
||||
file_put_contents($this->tmpfile, $fixtures);
|
||||
}
|
||||
|
||||
public function testTransformDataToArray()
|
||||
{
|
||||
$loader = new TestableXmlDataLoader();
|
||||
$array = $loader->transformDataToArray($this->tmpfile);
|
||||
|
||||
$this->assertTrue(is_array($array), 'Result is an array');
|
||||
$this->assertEquals(1, count($array), 'There is one class');
|
||||
$this->assertArrayHasKey('\Foo\Bar', $array);
|
||||
|
||||
$subarray = $array['\Foo\Bar'];
|
||||
$this->assertTrue(is_array($subarray), 'Result contains a sub-array');
|
||||
$this->assertEquals(2, count($subarray), 'There is two fixtures objects');
|
||||
$this->assertArrayHasKey('fb1', $subarray);
|
||||
$this->assertArrayHasKey('fb2', $subarray);
|
||||
}
|
||||
}
|
||||
|
||||
class TestableXmlDataLoader extends XmlDataLoader
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function transformDataToArray($data)
|
||||
{
|
||||
return parent::transformDataToArray($data);
|
||||
}
|
||||
}
|
65
Tests/DataFixtures/YamlDataLoaderTest.php
Normal file
65
Tests/DataFixtures/YamlDataLoaderTest.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the PropelBundle package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
namespace Propel\PropelBundle\Tests\DataFixtures;
|
||||
|
||||
use Propel\PropelBundle\Tests\TestCase;
|
||||
use Propel\PropelBundle\DataFixtures\YamlDataLoader;
|
||||
|
||||
/**
|
||||
* @author William Durand <william.durand1@gmail.com>
|
||||
*/
|
||||
class YamlDataLoaderTest extends TestCase
|
||||
{
|
||||
protected $tmpfile;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$fixtures = <<<YML
|
||||
\Foo\Bar:
|
||||
fb1:
|
||||
Id: 10
|
||||
Title: Hello
|
||||
fb2:
|
||||
Id: 20
|
||||
Title: World
|
||||
YML;
|
||||
$this->tmpfile = (string) tmpfile();
|
||||
file_put_contents($this->tmpfile, $fixtures);
|
||||
}
|
||||
|
||||
public function testTransformDataToArray()
|
||||
{
|
||||
$loader = new TestableYamlDataLoader();
|
||||
$array = $loader->transformDataToArray($this->tmpfile);
|
||||
|
||||
$this->assertTrue(is_array($array), 'Result is an array');
|
||||
$this->assertEquals(1, count($array), 'There is one class');
|
||||
$this->assertArrayHasKey('\Foo\Bar', $array);
|
||||
|
||||
$subarray = $array['\Foo\Bar'];
|
||||
$this->assertTrue(is_array($subarray), 'Result contains a sub-array');
|
||||
$this->assertEquals(2, count($subarray), 'There is two fixtures objects');
|
||||
$this->assertArrayHasKey('fb1', $subarray);
|
||||
$this->assertArrayHasKey('fb2', $subarray);
|
||||
}
|
||||
}
|
||||
|
||||
class TestableYamlDataLoader extends YamlDataLoader
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function transformDataToArray($data)
|
||||
{
|
||||
return parent::transformDataToArray($data);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue