This commit is contained in:
William DURAND 2012-11-05 14:18:43 +01:00
parent 53cba04c23
commit a8ea9726a0

View file

@ -27,43 +27,44 @@ class FixturesLoadCommandTest extends TestCase
$this->command = new TestableFixturesLoadCommand('testable-command'); $this->command = new TestableFixturesLoadCommand('testable-command');
// let's create some dummy fixture files // let's create some dummy fixture files
$this->fixtures_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel'; $this->fixturesDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel';
$this->fixtures_files = array( $this->fixturesFiles = array(
'10_foo.yml', '20_bar.yml', '15_biz.yml', '18_boo.sql', '42_baz.sql' '10_foo.yml', '20_bar.yml', '15_biz.yml', '18_boo.sql', '42_baz.sql'
); );
$this->filesystem = new Filesystem(); $this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->fixtures_dir); $this->filesystem->mkdir($this->fixturesDir);
foreach ($this->fixtures_files as $file) {
$this->filesystem->touch($this->fixtures_dir . DIRECTORY_SEPARATOR . $file); foreach ($this->fixturesFiles as $file) {
$this->filesystem->touch($this->fixturesDir . DIRECTORY_SEPARATOR . $file);
} }
} }
public function tearDown() public function tearDown()
{ {
$this->filesystem->remove($this->fixtures_dir); $this->filesystem->remove($this->fixturesDir);
} }
public function testOrderedFixturesFiles() public function testOrderedFixturesFiles()
{ {
$this->assertEquals( $this->assertEquals(
array('10_foo.yml', '15_biz.yml', '20_bar.yml',), array('10_foo.yml', '15_biz.yml', '20_bar.yml',),
$this->cleanFixtureIterator($this->command->getFixtureFiles('yml', $this->fixtures_dir)) $this->cleanFixtureIterator($this->command->getFixtureFiles('yml', $this->fixturesDir))
); );
$this->assertEquals( $this->assertEquals(
array('18_boo.sql', '42_baz.sql',), array('18_boo.sql', '42_baz.sql',),
$this->cleanFixtureIterator($this->command->getFixtureFiles('sql', $this->fixtures_dir)) $this->cleanFixtureIterator($this->command->getFixtureFiles('sql', $this->fixturesDir))
); );
} }
protected function cleanFixtureIterator($file_iterator) protected function cleanFixtureIterator($file_iterator)
{ {
$tmp_dir = $this->fixtures_dir; $tmpDir = realpath($this->fixturesDir);
return array_map(function($file) use ($tmp_dir) { return array_map(function($file) use ($tmpDir) {
return str_replace($tmp_dir . DIRECTORY_SEPARATOR, '', $file); return str_replace($tmpDir . DIRECTORY_SEPARATOR, '', $file);
}, array_keys(iterator_to_array($file_iterator))); }, array_values(iterator_to_array($file_iterator)));
} }
} }