Skip to content

[Finder] Unified tests #7197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@

class FinderTest extends Iterator\RealIteratorTestCase
{
protected static $tmpDir;

public static function setUpBeforeClass()
{
parent::setUpBeforeClass();

self::$tmpDir = realpath(sys_get_temp_dir().'/symfony2_finder');
}

public function testCreate()
{
Expand Down Expand Up @@ -503,26 +495,6 @@ public function testCountWithoutIn()
count($finder);
}

protected function toAbsolute($files)
{
$f = array();
foreach ($files as $file) {
$f[] = self::$tmpDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file);
}

return $f;
}

protected function toAbsoluteFixtures($files)
{
$f = array();
foreach ($files as $file) {
$f[] = __DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.$file;
}

return $f;
}

/**
* @dataProvider getContainsTestData
* @group grep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,45 @@ public function testAccept($size, $expected)

public function getAcceptData()
{
$since20YearsAgo = array(
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'.bar',
'.foo',
'.foo/.bar',
'foo bar',
'.foo/bar',
);

$since2MonthsAgo = array(
'.git',
'test.py',
'foo',
'toto',
'.bar',
'.foo',
'.foo/.bar',
'foo bar',
'.foo/bar',
);

$untilLastMonth = array(
'.git',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'.foo',
);

return array(
array(array(new DateComparator('since 20 years ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar')),
array(array(new DateComparator('since 2 months ago')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar')),
array(array(new DateComparator('until last month')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.foo')),
array(array(new DateComparator('since 20 years ago')), $this->toAbsolute($since20YearsAgo)),
array(array(new DateComparator('since 2 months ago')), $this->toAbsolute($since2MonthsAgo)),
array(array(new DateComparator('until last month')), $this->toAbsolute($untilLastMonth)),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
*/
public function testAccept($minDepth, $maxDepth, $expected)
{
$inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getAbsolutePath(''), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
$inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);

$iterator = new DepthRangeFilterIterator($inner, $minDepth, $maxDepth);

Expand All @@ -32,17 +32,50 @@ public function testAccept($minDepth, $maxDepth, $expected)

public function getAcceptData()
{
$lessThan1 = array(
'.git',
'test.py',
'foo',
'test.php',
'toto',
'.foo',
'.bar',
'foo bar',
);

$lessThanOrEqualTo1 = array(
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'.foo',
'.foo/.bar',
'.bar',
'foo bar',
'.foo/bar',
);

$graterThanOrEqualTo1 = array(
'foo/bar.tmp',
'.foo/.bar',
'.foo/bar',
);

$equalTo1 = array(
'foo/bar.tmp',
'.foo/.bar',
'.foo/bar',
);

return array(
array(0, 0, array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.bar'), $this->getAbsolutePath('/foo bar'))),
array(0, 1, array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'), $this->getAbsolutePath('/.foo'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.bar'), $this->getAbsolutePath('/foo bar'), $this->getAbsolutePath('/.foo/bar'))),
array(0, 0, $this->toAbsolute($lessThan1)),
array(0, 1, $this->toAbsolute($lessThanOrEqualTo1)),
array(2, INF, array()),
array(1, INF, array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.foo/bar'))),
array(1, 1, array($this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/.foo/.bar'), $this->getAbsolutePath('/.foo/bar'))),
array(1, INF, $this->toAbsolute($graterThanOrEqualTo1)),
array(1, 1, $this->toAbsolute($equalTo1)),
);
}

protected function getAbsolutePath($path)
{
return sys_get_temp_dir().'/symfony2_finder'.str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
*/
public function testAccept($directories, $expected)
{
$inner = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator(sys_get_temp_dir().'/symfony2_finder', \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
$inner = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);

$iterator = new ExcludeDirectoryFilterIterator($inner, $directories);

Expand All @@ -30,33 +30,36 @@ public function testAccept($directories, $expected)

public function getAcceptData()
{
$tmpDir = sys_get_temp_dir().'/symfony2_finder';
$foo = array(
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'test.py',
'test.php',
'toto',
'foo bar'
);

$fo = array(
'.bar',
'.foo',
'.foo/.bar',
'.foo/bar',
'.git',
'test.py',
'foo',
'foo/bar.tmp',
'test.php',
'toto',
'foo bar'
);

return array(
array(array('foo'), array(
$tmpDir.DIRECTORY_SEPARATOR.'.bar',
$tmpDir.DIRECTORY_SEPARATOR.'.foo',
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'.bar',
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'bar',
$tmpDir.DIRECTORY_SEPARATOR.'.git',
$tmpDir.DIRECTORY_SEPARATOR.'test.py',
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
$tmpDir.DIRECTORY_SEPARATOR.'toto',
$tmpDir.DIRECTORY_SEPARATOR.'foo bar',
)),
array(array('fo'), array(
$tmpDir.DIRECTORY_SEPARATOR.'.bar',
$tmpDir.DIRECTORY_SEPARATOR.'.foo',
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'.bar',
$tmpDir.DIRECTORY_SEPARATOR.'.foo'.DIRECTORY_SEPARATOR.'bar',
$tmpDir.DIRECTORY_SEPARATOR.'.git',
$tmpDir.DIRECTORY_SEPARATOR.'test.py',
$tmpDir.DIRECTORY_SEPARATOR.'foo',
$tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp',
$tmpDir.DIRECTORY_SEPARATOR.'test.php',
$tmpDir.DIRECTORY_SEPARATOR.'toto',
$tmpDir.DIRECTORY_SEPARATOR.'foo bar',
)),
array(array('foo'), $this->toAbsolute($foo)),
array(array('fo'), $this->toAbsolute($fo)),
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,26 @@ public function testAccept($mode, $expected)

public function getAcceptData()
{
$onlyFiles = array(
'test.py',
'foo/bar.tmp',
'test.php',
'.bar',
'.foo/.bar',
'.foo/bar',
'foo bar',
);

$onlyDirectories = array(
'.git',
'foo',
'toto',
'.foo',
);

return array(
array(FileTypeFilterIterator::ONLY_FILES, array(sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/.bar', sys_get_temp_dir().'/symfony2_finder/.foo/.bar', sys_get_temp_dir().'/symfony2_finder/foo bar', sys_get_temp_dir().'/symfony2_finder/.foo/bar')),
array(FileTypeFilterIterator::ONLY_DIRECTORIES, array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/toto', sys_get_temp_dir().'/symfony2_finder/.foo')),
array(FileTypeFilterIterator::ONLY_FILES, $this->toAbsolute($onlyFiles)),
array(FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FilterIteratorTest extends RealIteratorTestCase
{
public function testFilterFilesystemIterators()
{
$i = new \FilesystemIterator(sys_get_temp_dir().'/symfony2_finder');
$i = new \FilesystemIterator($this->toAbsolute());

// it is expected that there are test.py test.php in the tmpDir
$i = $this->getMockForAbstractClass('Symfony\Component\Finder\Iterator\FilterIterator', array($i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,96 @@

abstract class RealIteratorTestCase extends IteratorTestCase
{

protected static $tmpDir;
protected static $files;

public static function setUpBeforeClass()
{
$tmpDir = sys_get_temp_dir().'/symfony2_finder';
self::$tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'symfony2_finder';

self::$files = array(
$tmpDir.'/.git/',
$tmpDir.'/.foo/',
$tmpDir.'/.foo/.bar',
$tmpDir.'/.foo/bar',
$tmpDir.'/.bar',
$tmpDir.'/test.py',
$tmpDir.'/foo/',
$tmpDir.'/foo/bar.tmp',
$tmpDir.'/test.php',
$tmpDir.'/toto/',
$tmpDir.'/foo bar',
'.git/',
'.foo/',
'.foo/.bar',
'.foo/bar',
'.bar',
'test.py',
'foo/',
'foo/bar.tmp',
'test.php',
'toto/',
'foo bar'
);

if (is_dir($tmpDir)) {
self::$files = self::toAbsolute(self::$files);

if (is_dir(self::$tmpDir)) {
self::tearDownAfterClass();
} else {
mkdir($tmpDir);
mkdir(self::$tmpDir);
}

foreach (self::$files as $file) {
if ('/' === $file[strlen($file) - 1]) {
if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
mkdir($file);
} else {
touch($file);
}
}

file_put_contents($tmpDir.'/test.php', str_repeat(' ', 800));
file_put_contents($tmpDir.'/test.py', str_repeat(' ', 2000));
file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800));
file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000));

touch($tmpDir.'/foo/bar.tmp', strtotime('2005-10-15'));
touch($tmpDir.'/test.php', strtotime('2005-10-15'));
touch(self::toAbsolute('foo/bar.tmp'), strtotime('2005-10-15'));
touch(self::toAbsolute('test.php'), strtotime('2005-10-15'));
}

public static function tearDownAfterClass()
{
foreach (array_reverse(self::$files) as $file) {
if ('/' === $file[strlen($file) - 1]) {
if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
@rmdir($file);
} else {
@unlink($file);
}
}
}

protected static function toAbsolute($files = null)
{
/*
* Without the call to setUpBeforeClass() property can be null.
*/
if (!self::$tmpDir) {
self::$tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'symfony2_finder';
}

if (is_array($files)) {
$f = array();
foreach ($files as $file) {
$f[] = self::$tmpDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file);
}

return $f;
}

if (is_string($files)) {

return self::$tmpDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $files);
}

return self::$tmpDir;
}

protected static function toAbsoluteFixtures($files)
{
$f = array();
foreach ($files as $file) {
$f[] = realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.$file);
}

return $f;
}

}
Loading