ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- Symfony/Component/Finder/Tests/FakeAdapter/DummyAdapter.php000064400000001754152376005700017753 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\FakeAdapter; use Symfony\Component\Finder\Adapter\AbstractAdapter; /** * @author Jean-François Simon */ class DummyAdapter extends AbstractAdapter { /** * @var \Iterator */ private $iterator; /** * @param \Iterator $iterator */ public function __construct(\Iterator $iterator) { $this->iterator = $iterator; } /** * {@inheritdoc} */ public function searchInDirectory($dir) { return $this->iterator; } /** * {@inheritdoc} */ public function getName() { return 'yes'; } /** * {@inheritdoc} */ protected function canBeUsed() { return true; } } Symfony/Component/Finder/Tests/FakeAdapter/NamedAdapter.php000064400000001732152376005700017700 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\FakeAdapter; use Symfony\Component\Finder\Adapter\AbstractAdapter; /** * @author Jean-François Simon */ class NamedAdapter extends AbstractAdapter { /** * @var string */ private $name; /** * @param string $name */ public function __construct($name) { $this->name = $name; } /** * {@inheritdoc} */ public function searchInDirectory($dir) { return new \ArrayIterator(array()); } /** * {@inheritdoc} */ public function getName() { return $this->name; } /** * {@inheritdoc} */ protected function canBeUsed() { return true; } } Symfony/Component/Finder/Tests/FakeAdapter/FailingAdapter.php000064400000001555152376005700020230 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\FakeAdapter; use Symfony\Component\Finder\Adapter\AbstractAdapter; use Symfony\Component\Finder\Exception\AdapterFailureException; /** * @author Jean-François Simon */ class FailingAdapter extends AbstractAdapter { /** * {@inheritdoc} */ public function searchInDirectory($dir) { throw new AdapterFailureException($this); } /** * {@inheritdoc} */ public function getName() { return 'failing'; } /** * {@inheritdoc} */ protected function canBeUsed() { return true; } } Symfony/Component/Finder/Tests/FakeAdapter/UnsupportedAdapter.php000064400000001460152376005700021202 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\FakeAdapter; use Symfony\Component\Finder\Adapter\AbstractAdapter; /** * @author Jean-François Simon */ class UnsupportedAdapter extends AbstractAdapter { /** * {@inheritdoc} */ public function searchInDirectory($dir) { return new \ArrayIterator(array()); } /** * {@inheritdoc} */ public function getName() { return 'unsupported'; } /** * {@inheritdoc} */ protected function canBeUsed() { return false; } } Symfony/Component/Finder/Tests/Fixtures/copy/A/B/C/abc.dat.copy000064400000000000152376005700020154 0ustar00Symfony/Component/Finder/Tests/Fixtures/copy/A/B/ab.dat.copy000064400000000000152376005700017627 0ustar00Symfony/Component/Finder/Tests/Fixtures/copy/A/a.dat.copy000064400000000000152376005700017304 0ustar00Symfony/Component/Finder/Tests/Fixtures/one/b/c.neon000064400000000000152376005700016374 0ustar00Symfony/Component/Finder/Tests/Fixtures/one/b/d.neon000064400000000000152376005700016375 0ustar00Symfony/Component/Finder/Tests/Fixtures/one/a000064400000000000152376005700015213 0ustar00Symfony/Component/Finder/Tests/Fixtures/lorem.txt000064400000000065152376005700016161 0ustar00lorem ipsum dolor sit amet LOREM IPSUM DOLOR SIT AMETSymfony/Component/Finder/Tests/Fixtures/ipsum.txt000064400000000051152376005700016173 0ustar00ipsum dolor sit amet IPSUM DOLOR SIT AMETSymfony/Component/Finder/Tests/Fixtures/dolor.txt000064400000000035152376005700016157 0ustar00dolor sit amet DOLOR SIT AMETSymfony/Component/Finder/Tests/Fixtures/A/a.dat000064400000000000152376005700015361 0ustar00Symfony/Component/Finder/Tests/Fixtures/A/B/ab.dat000064400000000000152376005700015704 0ustar00Symfony/Component/Finder/Tests/Fixtures/A/B/C/abc.dat000064400000000000152376005700016231 0ustar00Symfony/Component/Finder/Tests/Fixtures/with space/foo.txt000064400000000000152376005700017642 0ustar00Symfony/Component/Finder/Tests/Comparator/NumberComparatorTest.php000064400000007057152376005700021441 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Comparator; use Symfony\Component\Finder\Comparator\NumberComparator; class NumberComparatorTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider getConstructorTestData */ public function testConstructor($successes, $failures) { foreach ($successes as $s) { new NumberComparator($s); } foreach ($failures as $f) { try { new NumberComparator($f); $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); } } } /** * @dataProvider getTestData */ public function testTest($test, $match, $noMatch) { $c = new NumberComparator($test); foreach ($match as $m) { $this->assertTrue($c->test($m), '->test() tests a string against the expression'); } foreach ($noMatch as $m) { $this->assertFalse($c->test($m), '->test() tests a string against the expression'); } } public function getTestData() { return array( array('< 1000', array('500', '999'), array('1000', '1500')), array('< 1K', array('500', '999'), array('1000', '1500')), array('<1k', array('500', '999'), array('1000', '1500')), array(' < 1 K ', array('500', '999'), array('1000', '1500')), array('<= 1K', array('1000'), array('1001')), array('> 1K', array('1001'), array('1000')), array('>= 1K', array('1000'), array('999')), array('< 1KI', array('500', '1023'), array('1024', '1500')), array('<= 1KI', array('1024'), array('1025')), array('> 1KI', array('1025'), array('1024')), array('>= 1KI', array('1024'), array('1023')), array('1KI', array('1024'), array('1023', '1025')), array('==1KI', array('1024'), array('1023', '1025')), array('==1m', array('1000000'), array('999999', '1000001')), array('==1mi', array(1024*1024), array(1024*1024-1, 1024*1024+1)), array('==1g', array('1000000000'), array('999999999', '1000000001')), array('==1gi', array(1024*1024*1024), array(1024*1024*1024-1, 1024*1024*1024+1)), array('!= 1000', array('500', '999'), array('1000')), ); } public function getConstructorTestData() { return array( array( array( '1', '0', '3.5', '33.55', '123.456', '123456.78', '.1', '.123', '.0', '0.0', '1.', '0.', '123.', '==1', '!=1', '<1', '>1', '<=1', '>=1', '==1k', '==1ki', '==1m', '==1mi', '==1g', '==1gi', '1k', '1ki', '1m', '1mi', '1g', '1gi', ), array( false, null, '', ' ', 'foobar', '=1', '===1', '0 . 1', '123 .45', '234. 567', '..', '.0.', '0.1.2', ) ), ); } } Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php000064400000003626152376005700020266 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Comparator; use Symfony\Component\Finder\Comparator\Comparator; class ComparatorTest extends \PHPUnit_Framework_TestCase { public function testGetSetOperator() { $comparator = new Comparator(); try { $comparator->setOperator('foo'); $this->fail('->setOperator() throws an \InvalidArgumentException if the operator is not valid.'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '->setOperator() throws an \InvalidArgumentException if the operator is not valid.'); } $comparator = new Comparator(); $comparator->setOperator('>'); $this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator'); } public function testGetSetTarget() { $comparator = new Comparator(); $comparator->setTarget(8); $this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target'); } /** * @dataProvider getTestData */ public function testTest($operator, $target, $match, $noMatch) { $c = new Comparator(); $c->setOperator($operator); $c->setTarget($target); foreach ($match as $m) { $this->assertTrue($c->test($m), '->test() tests a string against the expression'); } foreach ($noMatch as $m) { $this->assertFalse($c->test($m), '->test() tests a string against the expression'); } } public function getTestData() { return array( array('<', '1000', array('500', '999'), array('1000', '1500')), ); } } Symfony/Component/Finder/Tests/Comparator/DateComparatorTest.php000064400000004604152376005700021061 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Comparator; use Symfony\Component\Finder\Comparator\DateComparator; class DateComparatorTest extends \PHPUnit_Framework_TestCase { public function testConstructor() { try { new DateComparator('foobar'); $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); } try { new DateComparator(''); $this->fail('__construct() throws an \InvalidArgumentException if the test expression is not valid.'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the test expression is not valid.'); } } /** * @dataProvider getTestData */ public function testTest($test, $match, $noMatch) { $c = new DateComparator($test); foreach ($match as $m) { $this->assertTrue($c->test($m), '->test() tests a string against the expression'); } foreach ($noMatch as $m) { $this->assertFalse($c->test($m), '->test() tests a string against the expression'); } } public function getTestData() { return array( array('< 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), array('until 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), array('before 2005-10-10', array(strtotime('2005-10-09')), array(strtotime('2005-10-15'))), array('> 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), array('after 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), array('since 2005-10-10', array(strtotime('2005-10-15')), array(strtotime('2005-10-09'))), array('!= 2005-10-10', array(strtotime('2005-10-11')), array(strtotime('2005-10-10'))), ); } } Symfony/Component/Finder/Tests/Expression/GlobTest.php000064400000003164152376005700017067 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Expression; use Symfony\Component\Finder\Expression\Expression; class GlobTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider getToRegexData */ public function testGlobToRegex($glob, $match, $noMatch) { foreach ($match as $m) { $this->assertRegExp(Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp'); } foreach ($noMatch as $m) { $this->assertNotRegExp(Expression::create($glob)->getRegex()->render(), $m, '::toRegex() converts a glob to a regexp'); } } public function getToRegexData() { return array( array('', array(''), array('f', '/')), array('*', array('foo'), array('foo/', '/foo')), array('foo.*', array('foo.php', 'foo.a', 'foo.'), array('fooo.php', 'foo.php/foo')), array('fo?', array('foo', 'fot'), array('fooo', 'ffoo', 'fo/')), array('fo{o,t}', array('foo', 'fot'), array('fob', 'fo/')), array('foo(bar|foo)', array('foo(bar|foo)'), array('foobar', 'foofoo')), array('foo,bar', array('foo,bar'), array('foo', 'bar')), array('fo{o,\\,}', array('foo', 'fo,'), array()), array('fo{o,\\\\}', array('foo', 'fo\\'), array()), array('/foo', array('/foo'), array('foo')), ); } } Symfony/Component/Finder/Tests/Expression/RegexTest.php000064400000007641152376005700017262 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Expression; use Symfony\Component\Finder\Expression\Expression; class RegexTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider getHasFlagsData */ public function testHasFlags($regex, $start, $end) { $expr = new Expression($regex); $this->assertEquals($start, $expr->getRegex()->hasStartFlag()); $this->assertEquals($end, $expr->getRegex()->hasEndFlag()); } /** * @dataProvider getHasJokersData */ public function testHasJokers($regex, $start, $end) { $expr = new Expression($regex); $this->assertEquals($start, $expr->getRegex()->hasStartJoker()); $this->assertEquals($end, $expr->getRegex()->hasEndJoker()); } /** * @dataProvider getSetFlagsData */ public function testSetFlags($regex, $start, $end, $expected) { $expr = new Expression($regex); $expr->getRegex()->setStartFlag($start)->setEndFlag($end); $this->assertEquals($expected, $expr->render()); } /** * @dataProvider getSetJokersData */ public function testSetJokers($regex, $start, $end, $expected) { $expr = new Expression($regex); $expr->getRegex()->setStartJoker($start)->setEndJoker($end); $this->assertEquals($expected, $expr->render()); } public function testOptions() { $expr = new Expression('~abc~is'); $expr->getRegex()->removeOption('i')->addOption('m'); $this->assertEquals('~abc~sm', $expr->render()); } public function testMixFlagsAndJokers() { $expr = new Expression('~^.*abc.*$~is'); $expr->getRegex()->setStartFlag(false)->setEndFlag(false)->setStartJoker(false)->setEndJoker(false); $this->assertEquals('~abc~is', $expr->render()); $expr->getRegex()->setStartFlag(true)->setEndFlag(true)->setStartJoker(true)->setEndJoker(true); $this->assertEquals('~^.*abc.*$~is', $expr->render()); } /** * @dataProvider getReplaceJokersTestData */ public function testReplaceJokers($regex, $expected) { $expr = new Expression($regex); $expr = $expr->getRegex()->replaceJokers('@'); $this->assertEquals($expected, $expr->renderPattern()); } public function getHasFlagsData() { return array( array('~^abc~', true, false), array('~abc$~', false, true), array('~abc~', false, false), array('~^abc$~', true, true), array('~^abc\\$~', true, false), ); } public function getHasJokersData() { return array( array('~.*abc~', true, false), array('~abc.*~', false, true), array('~abc~', false, false), array('~.*abc.*~', true, true), array('~.*abc\\.*~', true, false), ); } public function getSetFlagsData() { return array( array('~abc~', true, false, '~^abc~'), array('~abc~', false, true, '~abc$~'), array('~abc~', false, false, '~abc~'), array('~abc~', true, true, '~^abc$~'), ); } public function getSetJokersData() { return array( array('~abc~', true, false, '~.*abc~'), array('~abc~', false, true, '~abc.*~'), array('~abc~', false, false, '~abc~'), array('~abc~', true, true, '~.*abc.*~'), ); } public function getReplaceJokersTestData() { return array( array('~.abc~', '@abc'), array('~\\.abc~', '\\.abc'), array('~\\\\.abc~', '\\\\@abc'), array('~\\\\\\.abc~', '\\\\\\.abc'), ); } } Symfony/Component/Finder/Tests/Expression/ExpressionTest.php000064400000003220152376005700020334 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Expression; use Symfony\Component\Finder\Expression\Expression; class ExpressionTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider getTypeGuesserData */ public function testTypeGuesser($expr, $type) { $this->assertEquals($type, Expression::create($expr)->getType()); } /** * @dataProvider getCaseSensitiveData */ public function testCaseSensitive($expr, $isCaseSensitive) { $this->assertEquals($isCaseSensitive, Expression::create($expr)->isCaseSensitive()); } /** * @dataProvider getRegexRenderingData */ public function testRegexRendering($expr, $body) { $this->assertEquals($body, Expression::create($expr)->renderPattern()); } public function getTypeGuesserData() { return array( array('{foo}', Expression::TYPE_REGEX), array('/foo/', Expression::TYPE_REGEX), array('foo', Expression::TYPE_GLOB), array('foo*', Expression::TYPE_GLOB), ); } public function getCaseSensitiveData() { return array( array('{foo}m', true), array('/foo/i', false), array('foo*', true), ); } public function getRegexRenderingData() { return array( array('{foo}m', 'foo'), array('/foo/i', 'foo'), ); } } Symfony/Component/Finder/Tests/FinderTest.php000064400000073555152376005700015267 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Adapter; class FinderTest extends Iterator\RealIteratorTestCase { public function testCreate() { $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create()); } /** * @dataProvider getAdaptersTestData */ public function testDirectories($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->directories()); $this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->directories(); $finder->files(); $finder->directories(); $this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testFiles($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->files()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->files(); $finder->directories(); $finder->files(); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testDepth($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->depth('< 1')); $this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->depth('<= 0')); $this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->depth('>= 1')); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->depth('< 1')->depth('>= 1'); $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testName($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->name('*.php')); $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->name('test.ph*'); $finder->name('test.py'); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->name('~^test~i'); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->name('~\\.php$~i'); $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->name('test.p{hp,y}'); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testNotName($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->notName('*.php')); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->notName('*.php'); $finder->notName('*.py'); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->name('test.ph*'); $finder->name('test.py'); $finder->notName('*.php'); $finder->notName('*.py'); $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->name('test.ph*'); $finder->name('test.py'); $finder->notName('*.p{hp,y}'); $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getRegexNameTestData * * @group regexName */ public function testRegexName($adapter, $regex) { $finder = $this->buildFinder($adapter); $finder->name($regex); $this->assertIterator($this->toAbsolute(array('test.py', 'test.php')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSize($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500')); $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testDate($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->files()->date('until last month')); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testExclude($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->exclude('foo')); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testIgnoreVCS($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false)); $this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false); $this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false)); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testIgnoreDotFiles($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false)); $this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false); $this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false)); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSortByName($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->sortByName()); $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSortByType($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->sortByType()); $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSortByAccessedTime($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->sortByAccessedTime()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSortByChangedTime($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->sortByChangedTime()); $this->assertIterator($this->toAbsolute(array('toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSortByModifiedTime($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->sortByModifiedTime()); $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testSort($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); })); $this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testFilter($adapter) { $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return preg_match('/test/', $f) > 0; })); $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testFollowLinks($adapter) { if ('\\' == DIRECTORY_SEPARATOR) { return; } $finder = $this->buildFinder($adapter); $this->assertSame($finder, $finder->followLinks()); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testIn($adapter) { $finder = $this->buildFinder($adapter); try { $finder->in('foobar'); $this->fail('->in() throws a \InvalidArgumentException if the directory does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '->in() throws a \InvalidArgumentException if the directory does not exist'); } $finder = $this->buildFinder($adapter); $iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator(); $this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php'), $iterator); } /** * @dataProvider getAdaptersTestData */ public function testInWithGlob($adapter) { $finder = $this->buildFinder($adapter); $finder->in(array(__DIR__.'/Fixtures/*/B/C', __DIR__.'/Fixtures/*/*/B/C'))->getIterator(); $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder); } /** * @dataProvider getAdaptersTestData * @expectedException \InvalidArgumentException */ public function testInWithNonDirectoryGlob($adapter) { $finder = $this->buildFinder($adapter); $finder->in(__DIR__.'/Fixtures/A/a*'); } /** * @dataProvider getAdaptersTestData */ public function testGetIterator($adapter) { $finder = $this->buildFinder($adapter); try { $finder->getIterator(); $this->fail('->getIterator() throws a \LogicException if the in() method has not been called'); } catch (\Exception $e) { $this->assertInstanceOf('LogicException', $e, '->getIterator() throws a \LogicException if the in() method has not been called'); } $finder = $this->buildFinder($adapter); $dirs = array(); foreach ($finder->directories()->in(self::$tmpDir) as $dir) { $dirs[] = (string) $dir; } $expected = $this->toAbsolute(array('foo', 'toto')); sort($dirs); sort($expected); $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface'); $finder = $this->buildFinder($adapter); $this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface'); $finder = $this->buildFinder($adapter); $a = iterator_to_array($finder->directories()->in(self::$tmpDir)); $a = array_values(array_map(function ($a) { return (string) $a; }, $a)); sort($a); $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface'); } /** * @dataProvider getAdaptersTestData */ public function testRelativePath($adapter) { $finder = $this->buildFinder($adapter)->in(self::$tmpDir); $paths = array(); foreach ($finder as $file) { $paths[] = $file->getRelativePath(); } $ref = array("", "", "", "", "foo", ""); sort($ref); sort($paths); $this->assertEquals($ref, $paths); } /** * @dataProvider getAdaptersTestData */ public function testRelativePathname($adapter) { $finder = $this->buildFinder($adapter)->in(self::$tmpDir)->sortByName(); $paths = array(); foreach ($finder as $file) { $paths[] = $file->getRelativePathname(); } $ref = array("test.php", "toto", "test.py", "foo", "foo".DIRECTORY_SEPARATOR."bar.tmp", "foo bar"); sort($paths); sort($ref); $this->assertEquals($ref, $paths); } /** * @dataProvider getAdaptersTestData */ public function testAppendWithAFinder($adapter) { $finder = $this->buildFinder($adapter); $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); $finder1 = $this->buildFinder($adapter); $finder1->directories()->in(self::$tmpDir); $finder = $finder->append($finder1); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testAppendWithAnArray($adapter) { $finder = $this->buildFinder($adapter); $finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); $finder->append($this->toAbsolute(array('foo', 'toto'))); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator()); } /** * @dataProvider getAdaptersTestData */ public function testAppendReturnsAFinder($adapter) { $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', $this->buildFinder($adapter)->append(array())); } /** * @dataProvider getAdaptersTestData */ public function testAppendDoesNotRequireIn($adapter) { $finder = $this->buildFinder($adapter); $finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); $finder1 = Finder::create()->append($finder); $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator()); } public function testCountDirectories() { $directory = Finder::create()->directories()->in(self::$tmpDir); $i = 0; foreach ($directory as $dir) { $i++; } $this->assertCount($i, $directory); } public function testCountFiles() { $files = Finder::create()->files()->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'); $i = 0; foreach ($files as $file) { $i++; } $this->assertCount($i, $files); } /** * @expectedException \LogicException */ public function testCountWithoutIn() { $finder = Finder::create()->files(); count($finder); } /** * @dataProvider getContainsTestData * @group grep */ public function testContains($adapter, $matchPatterns, $noMatchPatterns, $expected) { $finder = $this->buildFinder($adapter); $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures') ->name('*.txt')->sortByName() ->contains($matchPatterns) ->notContains($noMatchPatterns); $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); } /** * @dataProvider getAdaptersTestData */ public function testContainsOnDirectory(Adapter\AdapterInterface $adapter) { $finder = $this->buildFinder($adapter); $finder->in(__DIR__) ->directories() ->name('Fixtures') ->contains('abc'); $this->assertIterator(array(), $finder); } /** * @dataProvider getAdaptersTestData */ public function testNotContainsOnDirectory(Adapter\AdapterInterface $adapter) { $finder = $this->buildFinder($adapter); $finder->in(__DIR__) ->directories() ->name('Fixtures') ->notContains('abc'); $this->assertIterator(array(), $finder); } /** * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator * with inner FilesystemIterator in an invalid state. * * @see https://bugs.php.net/bug.php?id=49104 * * @dataProvider getAdaptersTestData */ public function testMultipleLocations(Adapter\AdapterInterface $adapter) { $locations = array( self::$tmpDir.'/', self::$tmpDir.'/toto/', ); // it is expected that there are test.py test.php in the tmpDir $finder = $this->buildFinder($adapter); $finder->in($locations)->depth('< 1')->name('test.php'); $this->assertCount(1, $finder); } /** * Iterator keys must be the file pathname. * * @dataProvider getAdaptersTestData */ public function testIteratorKeys(Adapter\AdapterInterface $adapter) { $finder = $this->buildFinder($adapter)->in(self::$tmpDir); foreach ($finder as $key => $file) { $this->assertEquals($file->getPathname(), $key); } } public function testAdaptersOrdering() { $finder = Finder::create() ->removeAdapters() ->addAdapter(new FakeAdapter\NamedAdapter('a'), 0) ->addAdapter(new FakeAdapter\NamedAdapter('b'), -50) ->addAdapter(new FakeAdapter\NamedAdapter('c'), 50) ->addAdapter(new FakeAdapter\NamedAdapter('d'), -25) ->addAdapter(new FakeAdapter\NamedAdapter('e'), 25); $this->assertEquals( array('c', 'e', 'a', 'd', 'b'), array_map(function (Adapter\AdapterInterface $adapter) { return $adapter->getName(); }, $finder->getAdapters()) ); } public function testAdaptersChaining() { $iterator = new \ArrayIterator(array()); $filenames = $this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')); foreach ($filenames as $file) { $iterator->append(new \Symfony\Component\Finder\SplFileInfo($file, null, null)); } $finder = Finder::create() ->removeAdapters() ->addAdapter(new FakeAdapter\UnsupportedAdapter(), 3) ->addAdapter(new FakeAdapter\FailingAdapter(), 2) ->addAdapter(new FakeAdapter\DummyAdapter($iterator), 1); $this->assertIterator($filenames, $finder->in(sys_get_temp_dir())->getIterator()); } public function getAdaptersTestData() { return array_map( function ($adapter) { return array($adapter); }, $this->getValidAdapters() ); } public function getContainsTestData() { $tests = array( array('', '', array()), array('foo', 'bar', array()), array('', 'foobar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')), array('lorem ipsum dolor sit amet', 'foobar', array('lorem.txt')), array('sit', 'bar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')), array('dolor sit amet', '@^L@m', array('dolor.txt', 'ipsum.txt')), array('/^lorem ipsum dolor sit amet$/m', 'foobar', array('lorem.txt')), array('lorem', 'foobar', array('lorem.txt')), array('', 'lorem', array('dolor.txt', 'ipsum.txt')), array('ipsum dolor sit amet', '/^IPSUM/m', array('lorem.txt')), ); return $this->buildTestData($tests); } public function getRegexNameTestData() { $tests = array( array('~.+\\.p.+~i'), array('~t.*s~i'), ); return $this->buildTestData($tests); } /** * @dataProvider getTestPathData */ public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, array $expected) { $finder = $this->buildFinder($adapter); $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures') ->path($matchPatterns) ->notPath($noMatchPatterns); $this->assertIterator($this->toAbsoluteFixtures($expected), $finder); } public function testAdapterSelection() { // test that by default, PhpAdapter is selected $adapters = Finder::create()->getAdapters(); $this->assertTrue($adapters[0] instanceof Adapter\PhpAdapter); // test another adapter selection $adapters = Finder::create()->setAdapter('gnu_find')->getAdapters(); $this->assertTrue($adapters[0] instanceof Adapter\GnuFindAdapter); // test that useBestAdapter method removes selection $adapters = Finder::create()->useBestAdapter()->getAdapters(); $this->assertFalse($adapters[0] instanceof Adapter\PhpAdapter); } public function getTestPathData() { $tests = array( array('', '', array()), array('/^A\/B\/C/', '/C$/', array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat') ), array('/^A\/B/', 'foobar', array( 'A'.DIRECTORY_SEPARATOR.'B', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', ) ), array('A/B/C', 'foobar', array( 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy', ) ), array('A/B', 'foobar', array( //dirs 'A'.DIRECTORY_SEPARATOR.'B', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C', //files 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat', 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat.copy', 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat.copy', ) ), array('/^with space\//', 'foobar', array( 'with space'.DIRECTORY_SEPARATOR.'foo.txt', ) ), ); return $this->buildTestData($tests); } /** * @dataProvider getAdaptersTestData */ public function testAccessDeniedException(Adapter\AdapterInterface $adapter) { if (defined('PHP_WINDOWS_VERSION_MAJOR')) { $this->markTestSkipped('chmod is not supported on Windows'); } $finder = $this->buildFinder($adapter); $finder->files()->in(self::$tmpDir); // make 'foo' directory non-readable chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0333); try { $this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator()); $this->fail('Finder should throw an exception when opening a non-readable directory.'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\Finder\\Exception\\AccessDeniedException', $e); } // restore original permissions chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0777); } /** * @dataProvider getAdaptersTestData */ public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter) { if (defined('PHP_WINDOWS_VERSION_MAJOR')) { $this->markTestSkipped('chmod is not supported on Windows'); } $finder = $this->buildFinder($adapter); $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir); // make 'foo' directory non-readable chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0333); $this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator()); // restore original permissions chmod(self::$tmpDir.DIRECTORY_SEPARATOR.'foo', 0777); } private function buildTestData(array $tests) { $data = array(); foreach ($this->getValidAdapters() as $adapter) { foreach ($tests as $test) { $data[] = array_merge(array($adapter), $test); } } return $data; } private function buildFinder(Adapter\AdapterInterface $adapter) { return Finder::create() ->removeAdapters() ->addAdapter($adapter); } private function getValidAdapters() { return array_filter( array( new Adapter\BsdFindAdapter(), new Adapter\GnuFindAdapter(), new Adapter\PhpAdapter() ), function (Adapter\AdapterInterface $adapter) { return $adapter->isSupported(); } ); } /** * Searching in multiple locations with sub directories involves * AppendIterator which does an unnecessary rewind which leaves * FilterIterator with inner FilesystemIterator in an invalid state. * * @see https://bugs.php.net/bug.php?id=49104 */ public function testMultipleLocationsWithSubDirectories() { $locations = array( __DIR__.'/Fixtures/one', self::$tmpDir.DIRECTORY_SEPARATOR.'toto', ); $finder = new Finder(); $finder->in($locations)->depth('< 10')->name('*.neon'); $expected = array( __DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon', __DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon', ); $this->assertIterator($expected, $finder); $this->assertIteratorInForeach($expected, $finder); } public function testNonSeekableStream() { try { $i = Finder::create()->in('ftp://ftp.mozilla.org/')->depth(0)->getIterator(); } catch (\UnexpectedValueException $e) { $this->markTestSkipped(sprintf('Unsupported stream "%s".', 'ftp')); } $contains = array( 'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README', 'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'index.html', 'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub', ); $this->assertIteratorInForeach($contains, $i); } } Symfony/Component/Finder/Tests/Iterator/FilenameFilterIteratorTest.php000064400000002770152376005700022240 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\FilenameFilterIterator; class FilenameFilterIteratorTest extends IteratorTestCase { /** * @dataProvider getAcceptData */ public function testAccept($matchPatterns, $noMatchPatterns, $expected) { $inner = new InnerNameIterator(array('test.php', 'test.py', 'foo.php')); $iterator = new FilenameFilterIterator($inner, $matchPatterns, $noMatchPatterns); $this->assertIterator($expected, $iterator); } public function getAcceptData() { return array( array(array('test.*'), array(), array('test.php', 'test.py')), array(array(), array('test.*'), array('foo.php')), array(array('*.php'), array('test.*'), array('foo.php')), array(array('*.php', '*.py'), array('foo.*'), array('test.php', 'test.py')), array(array('/\.php$/'), array(), array('test.php', 'foo.php')), array(array(), array('/\.php$/'), array('test.py')), ); } } class InnerNameIterator extends \ArrayIterator { public function current() { return new \SplFileInfo(parent::current()); } public function getFilename() { return parent::current(); } } Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php000064400000003115152376005700022233 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\FileTypeFilterIterator; class FileTypeFilterIteratorTest extends RealIteratorTestCase { /** * @dataProvider getAcceptData */ public function testAccept($mode, $expected) { $inner = new InnerTypeIterator(self::$files); $iterator = new FileTypeFilterIterator($inner, $mode); $this->assertIterator($expected, $iterator); } 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, $this->toAbsolute($onlyFiles)), array(FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)), ); } } class InnerTypeIterator extends \ArrayIterator { public function current() { return new \SplFileInfo(parent::current()); } public function isFile() { return $this->current()->isFile(); } public function isDir() { return $this->current()->isDir(); } } Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php000064400000004051152376005700022533 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator; class DepthRangeFilterIteratorTest extends RealIteratorTestCase { /** * @dataProvider getAcceptData */ public function testAccept($minDepth, $maxDepth, $expected) { $inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); $iterator = new DepthRangeFilterIterator($inner, $minDepth, $maxDepth); $actual = array_keys(iterator_to_array($iterator)); sort($expected); sort($actual); $this->assertEquals($expected, $actual); } 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, $this->toAbsolute($lessThan1)), array(0, 1, $this->toAbsolute($lessThanOrEqualTo1)), array(2, PHP_INT_MAX, array()), array(1, PHP_INT_MAX, $this->toAbsolute($graterThanOrEqualTo1)), array(1, 1, $this->toAbsolute($equalTo1)), ); } } Symfony/Component/Finder/Tests/Iterator/CustomFilterIteratorTest.php000064400000002355152376005700021771 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\CustomFilterIterator; class CustomFilterIteratorTest extends IteratorTestCase { /** * @expectedException \InvalidArgumentException */ public function testWithInvalidFilter() { new CustomFilterIterator(new Iterator(), array('foo')); } /** * @dataProvider getAcceptData */ public function testAccept($filters, $expected) { $inner = new Iterator(array('test.php', 'test.py', 'foo.php')); $iterator = new CustomFilterIterator($inner, $filters); $this->assertIterator($expected, $iterator); } public function getAcceptData() { return array( array(array(function (\SplFileInfo $fileinfo) { return false; }), array()), array(array(function (\SplFileInfo $fileinfo) { return preg_match('/^test/', $fileinfo) > 0; }), array('test.php', 'test.py')), array(array('is_dir'), array()), ); } } Symfony/Component/Finder/Tests/Iterator/DateRangeFilterIteratorTest.php000064400000003475152376005700022355 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\DateRangeFilterIterator; use Symfony\Component\Finder\Comparator\DateComparator; class DateRangeFilterIteratorTest extends RealIteratorTestCase { /** * @dataProvider getAcceptData */ public function testAccept($size, $expected) { $inner = new Iterator(self::$files); $iterator = new DateRangeFilterIterator($inner, $size); $this->assertIterator($expected, $iterator); } 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')), $this->toAbsolute($since20YearsAgo)), array(array(new DateComparator('since 2 months ago')), $this->toAbsolute($since2MonthsAgo)), array(array(new DateComparator('until last month')), $this->toAbsolute($untilLastMonth)), ); } } Symfony/Component/Finder/Tests/Iterator/FilterIteratorTest.php000064400000002466152376005700020601 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; /** * @author Alex Bogomazov */ class FilterIteratorTest extends RealIteratorTestCase { public function testFilterFilesystemIterators() { $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)); $i->expects($this->any()) ->method('accept') ->will($this->returnCallback(function () use ($i) { return (bool) preg_match('/\.php/', (string) $i->current()); }) ); $c = 0; foreach ($i as $item) { $c++; } $this->assertEquals(1, $c); $i->rewind(); $c = 0; foreach ($i as $item) { $c++; } // This would fail with \FilterIterator but works with Symfony\Component\Finder\Iterator\FilterIterator // see https://bugs.php.net/bug.php?id=49104 $this->assertEquals(1, $c); } } Symfony/Component/Finder/Tests/Iterator/SizeRangeFilterIteratorTest.php000064400000003000152376005700022372 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\SizeRangeFilterIterator; use Symfony\Component\Finder\Comparator\NumberComparator; class SizeRangeFilterIteratorTest extends RealIteratorTestCase { /** * @dataProvider getAcceptData */ public function testAccept($size, $expected) { $inner = new InnerSizeIterator(self::$files); $iterator = new SizeRangeFilterIterator($inner, $size); $this->assertIterator($expected, $iterator); } public function getAcceptData() { $lessThan1KGreaterThan05K = array( '.foo', '.git', 'foo', 'test.php', 'toto', ); return array( array(array(new NumberComparator('< 1K'), new NumberComparator('> 0.5K')), $this->toAbsolute($lessThan1KGreaterThan05K)), ); } } class InnerSizeIterator extends \ArrayIterator { public function current() { return new \SplFileInfo(parent::current()); } public function getFilename() { return parent::current(); } public function isFile() { return $this->current()->isFile(); } public function getSize() { return $this->current()->getSize(); } } Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php000064400000004541152376005700021123 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\SortableIterator; class SortableIteratorTest extends RealIteratorTestCase { public function testConstructor() { try { new SortableIterator(new Iterator(array()), 'foobar'); $this->fail('__construct() throws an \InvalidArgumentException exception if the mode is not valid'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException exception if the mode is not valid'); } } /** * @dataProvider getAcceptData */ public function testAccept($mode, $expected) { $inner = new Iterator(self::$files); $iterator = new SortableIterator($inner, $mode); $this->assertOrderedIterator($expected, $iterator); } public function getAcceptData() { $sortByName = array( '.bar', '.foo', '.foo/.bar', '.foo/bar', '.git', 'foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', ); $sortByType = array( '.foo', '.git', 'foo', 'toto', '.bar', '.foo/.bar', '.foo/bar', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', ); $customComparison = array( '.bar', '.foo', '.foo/.bar', '.foo/bar', '.git', 'foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', ); return array( array(SortableIterator::SORT_BY_NAME, $this->toAbsolute($sortByName)), array(SortableIterator::SORT_BY_TYPE, $this->toAbsolute($sortByType)), array(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }, $this->toAbsolute($customComparison)), ); } } Symfony/Component/Finder/Tests/Iterator/IteratorTestCase.php000064400000004557152376005700020232 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase { protected function assertIterator($expected, \Traversable $iterator) { // set iterator_to_array $use_key to false to avoid values merge // this made FinderTest::testAppendWithAnArray() failed with GnuFinderAdapter $values = array_map(function (\SplFileInfo $fileinfo) { return str_replace('/', DIRECTORY_SEPARATOR, $fileinfo->getPathname()); }, iterator_to_array($iterator, false)); $expected = array_map(function ($path) { return str_replace('/', DIRECTORY_SEPARATOR, $path); }, $expected); sort($values); sort($expected); $this->assertEquals($expected, array_values($values)); } protected function assertOrderedIterator($expected, \Traversable $iterator) { $values = array_map(function (\SplFileInfo $fileinfo) { return $fileinfo->getPathname(); }, iterator_to_array($iterator)); $this->assertEquals($expected, array_values($values)); } /** * Same as IteratorTestCase::assertIterator with foreach usage * * @param array $expected * @param \Traversable $iterator */ protected function assertIteratorInForeach($expected, \Traversable $iterator) { $values = array(); foreach ($iterator as $file) { $this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file); $values[] = $file->getPathname(); } sort($values); sort($expected); $this->assertEquals($expected, array_values($values)); } /** * Same as IteratorTestCase::assertOrderedIterator with foreach usage * * @param array $expected * @param \Traversable $iterator */ protected function assertOrderedIteratorInForeach($expected, \Traversable $iterator) { $values = array(); foreach ($iterator as $file) { $this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file); $values[] = $file->getPathname(); } $this->assertEquals($expected, array_values($values)); } } Symfony/Component/Finder/Tests/Iterator/FilePathsIteratorTest.php000064400000005347152376005700021234 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\FilePathsIterator; class FilePathsIteratorTest extends RealIteratorTestCase { /** * @dataProvider getSubPathData */ public function testSubPath($baseDir, array $paths, array $subPaths, array $subPathnames) { $iterator = new FilePathsIterator($paths, $baseDir); foreach ($iterator as $index => $file) { $this->assertEquals($paths[$index], $file->getPathname()); $this->assertEquals($subPaths[$index], $iterator->getSubPath()); $this->assertEquals($subPathnames[$index], $iterator->getSubPathname()); } } public function getSubPathData() { $tmpDir = sys_get_temp_dir().'/symfony2_finder'; return array( array( $tmpDir, array( // paths $tmpDir.DIRECTORY_SEPARATOR.'.git' => $tmpDir.DIRECTORY_SEPARATOR.'.git', $tmpDir.DIRECTORY_SEPARATOR.'test.py' => $tmpDir.DIRECTORY_SEPARATOR.'test.py', $tmpDir.DIRECTORY_SEPARATOR.'foo' => $tmpDir.DIRECTORY_SEPARATOR.'foo', $tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp' => $tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp', $tmpDir.DIRECTORY_SEPARATOR.'test.php' => $tmpDir.DIRECTORY_SEPARATOR.'test.php', $tmpDir.DIRECTORY_SEPARATOR.'toto' => $tmpDir.DIRECTORY_SEPARATOR.'toto' ), array( // subPaths $tmpDir.DIRECTORY_SEPARATOR.'.git' => '', $tmpDir.DIRECTORY_SEPARATOR.'test.py' => '', $tmpDir.DIRECTORY_SEPARATOR.'foo' => '', $tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp' => 'foo', $tmpDir.DIRECTORY_SEPARATOR.'test.php' => '', $tmpDir.DIRECTORY_SEPARATOR.'toto' => '' ), array( // subPathnames $tmpDir.DIRECTORY_SEPARATOR.'.git' => '.git', $tmpDir.DIRECTORY_SEPARATOR.'test.py' => 'test.py', $tmpDir.DIRECTORY_SEPARATOR.'foo' => 'foo', $tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp' => 'foo'.DIRECTORY_SEPARATOR.'bar.tmp', $tmpDir.DIRECTORY_SEPARATOR.'test.php' => 'test.php', $tmpDir.DIRECTORY_SEPARATOR.'toto' => 'toto' ), ), ); } } Symfony/Component/Finder/Tests/Iterator/RecursiveDirectoryIteratorTest.php000064400000004212152376005700023177 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; class RecursiveDirectoryIteratorTest extends IteratorTestCase { /** * @dataProvider getPaths * * @param string $path * @param Boolean $seekable * @param array $contains * @param string $message */ public function testRewind($path, $seekable, $contains, $message = null) { try { $i = new RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); } catch (\UnexpectedValueException $e) { $this->markTestSkipped(sprintf('Unsupported stream "%s".', $path)); } $i->rewind(); $this->assertTrue(true, $message); } /** * @dataProvider getPaths * * @param string $path * @param Boolean $seekable * @param array $contains * @param string $message */ public function testSeek($path, $seekable, $contains, $message = null) { try { $i = new RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS); } catch (\UnexpectedValueException $e) { $this->markTestSkipped(sprintf('Unsupported stream "%s".', $path)); } $actual = array(); $i->seek(0); $actual[] = $i->getPathname(); $i->seek(1); $actual[] = $i->getPathname(); $i->seek(2); $actual[] = $i->getPathname(); $this->assertEquals($contains, $actual); } public function getPaths() { $data = array(); // ftp $contains = array( 'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README', 'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'index.html', 'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub', ); $data[] = array('ftp://ftp.mozilla.org/', false, $contains); return $data; } } Symfony/Component/Finder/Tests/Iterator/PathFilterIteratorTest.php000064400000006364152376005700021417 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\PathFilterIterator; class PathFilterIteratorTest extends IteratorTestCase { /** * @dataProvider getTestFilterData */ public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray) { $iterator = new PathFilterIterator($inner, $matchPatterns, $noMatchPatterns); $this->assertIterator($resultArray, $iterator); } public function getTestFilterData() { $inner = new MockFileListIterator(); //PATH: A/B/C/abc.dat $inner[] = new MockSplFileInfo(array( 'name' => 'abc.dat', 'relativePathname' => 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', )); //PATH: A/B/ab.dat $inner[] = new MockSplFileInfo(array( 'name' => 'ab.dat', 'relativePathname' => 'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat', )); //PATH: A/a.dat $inner[] = new MockSplFileInfo(array( 'name' => 'a.dat', 'relativePathname' => 'A'.DIRECTORY_SEPARATOR.'a.dat', )); //PATH: copy/A/B/C/abc.dat.copy $inner[] = new MockSplFileInfo(array( 'name' => 'abc.dat.copy', 'relativePathname' => 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat', )); //PATH: copy/A/B/ab.dat.copy $inner[] = new MockSplFileInfo(array( 'name' => 'ab.dat.copy', 'relativePathname' => 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'ab.dat', )); //PATH: copy/A/a.dat.copy $inner[] = new MockSplFileInfo(array( 'name' => 'a.dat.copy', 'relativePathname' => 'copy'.DIRECTORY_SEPARATOR.'A'.DIRECTORY_SEPARATOR.'a.dat', )); return array( array($inner, array('/^A/'), array(), array('abc.dat', 'ab.dat', 'a.dat')), array($inner, array('/^A\/B/'), array(), array('abc.dat', 'ab.dat')), array($inner, array('/^A\/B\/C/'), array(), array('abc.dat')), array($inner, array('/A\/B\/C/'), array(), array('abc.dat', 'abc.dat.copy')), array($inner, array('A'), array(), array('abc.dat', 'ab.dat', 'a.dat', 'abc.dat.copy', 'ab.dat.copy', 'a.dat.copy')), array($inner, array('A/B'), array(), array('abc.dat', 'ab.dat', 'abc.dat.copy', 'ab.dat.copy')), array($inner, array('A/B/C'), array(), array('abc.dat', 'abc.dat.copy')), array($inner, array('copy/A'), array(), array('abc.dat.copy', 'ab.dat.copy', 'a.dat.copy')), array($inner, array('copy/A/B'), array(), array('abc.dat.copy', 'ab.dat.copy')), array($inner, array('copy/A/B/C'), array(), array('abc.dat.copy')), ); } } Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php000064400000006701152376005700017762 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; class MockSplFileInfo extends \SplFileInfo { const TYPE_DIRECTORY = 1; const TYPE_FILE = 2; const TYPE_UNKNOWN = 3; private $contents = null; private $mode = null; private $type = null; private $relativePath = null; private $relativePathname = null; public function __construct($param) { if (is_string($param)) { parent::__construct($param); } elseif (is_array($param)) { $defaults = array( 'name' => 'file.txt', 'contents' => null, 'mode' => null, 'type' => null, 'relativePath' => null, 'relativePathname' => null, ); $defaults = array_merge($defaults, $param); parent::__construct($defaults['name']); $this->setContents($defaults['contents']); $this->setMode($defaults['mode']); $this->setType($defaults['type']); $this->setRelativePath($defaults['relativePath']); $this->setRelativePathname($defaults['relativePathname']); } else { throw new \RuntimeException(sprintf('Incorrect parameter "%s"', $param)); } } public function isFile() { if ($this->type === null) { return preg_match('/file/', $this->getFilename()); }; return self::TYPE_FILE === $this->type; } public function isDir() { if ($this->type === null) { return preg_match('/directory/', $this->getFilename()); } return self::TYPE_DIRECTORY === $this->type; } public function isReadable() { if ($this->mode === null) { return preg_match('/r\+/', $this->getFilename()); } return preg_match('/r\+/', $this->mode); } public function getContents() { return $this->contents; } public function setContents($contents) { $this->contents = $contents; } public function setMode($mode) { $this->mode = $mode; } public function setType($type) { if (is_string($type)) { switch ($type) { case 'directory': $this->type = self::TYPE_DIRECTORY; case 'd': $this->type = self::TYPE_DIRECTORY; break; case 'file': $this->type = self::TYPE_FILE; case 'f': $this->type = self::TYPE_FILE; break; default: $this->type = self::TYPE_UNKNOWN; } } else { $this->type = $type; } } public function setRelativePath($relativePath) { $this->relativePath = $relativePath; } public function setRelativePathname($relativePathname) { $this->relativePathname = $relativePathname; } public function getRelativePath() { return $this->relativePath; } public function getRelativePathname() { return $this->relativePathname; } } Symfony/Component/Finder/Tests/Iterator/Iterator.php000064400000002021152376005700016556 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; class Iterator implements \Iterator { protected $values = array(); public function __construct(array $values = array()) { foreach ($values as $value) { $this->attach(new \SplFileInfo($value)); } $this->rewind(); } public function attach(\SplFileInfo $fileinfo) { $this->values[] = $fileinfo; } public function rewind() { reset($this->values); } public function valid() { return false !== $this->current(); } public function next() { next($this->values); } public function current() { return current($this->values); } public function key() { return key($this->values); } } Symfony/Component/Finder/Tests/Iterator/MockFileListIterator.php000064400000001050152376005700021025 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; class MockFileListIterator extends \ArrayIterator { public function __construct(array $filesArray = array()) { $files = array_map(function ($file) { return new MockSplFileInfo($file); }, $filesArray); parent::__construct($files); } } Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php000064400000005464152376005700021034 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; abstract class RealIteratorTestCase extends IteratorTestCase { protected static $tmpDir; protected static $files; public static function setUpBeforeClass() { self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony2_finder'; self::$files = array( '.git/', '.foo/', '.foo/.bar', '.foo/bar', '.bar', 'test.py', 'foo/', 'foo/bar.tmp', 'test.php', 'toto/', 'foo bar' ); self::$files = self::toAbsolute(self::$files); if (is_dir(self::$tmpDir)) { self::tearDownAfterClass(); } else { mkdir(self::$tmpDir); } foreach (self::$files as $file) { if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) { mkdir($file); } else { touch($file); } } file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800)); file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000)); 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 (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 = realpath(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; } } Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php000064400000003141152376005700023767 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator; use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase { /** * @dataProvider getAcceptData */ public function testAccept($directories, $expected) { $inner = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->toAbsolute(), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST); $iterator = new ExcludeDirectoryFilterIterator($inner, $directories); $this->assertIterator($expected, $iterator); } public function getAcceptData() { $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'), $this->toAbsolute($foo)), array(array('fo'), $this->toAbsolute($fo)), ); } } Symfony/Component/Finder/Tests/Iterator/MultiplePcreFilterIteratorTest.php000064400000004053152376005700023121 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\MultiplePcreFilterIterator; class MultiplePcreFilterIteratorTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider getIsRegexFixtures */ public function testIsRegex($string, $isRegex, $message) { $testIterator = new TestMultiplePcreFilterIterator(); $this->assertEquals($isRegex, $testIterator->isRegex($string), $message); } public function getIsRegexFixtures() { return array( array('foo', false, 'string'), array(' foo ', false, '" " is not a valid delimiter'), array('\\foo\\', false, '"\\" is not a valid delimiter'), array('afooa', false, '"a" is not a valid delimiter'), array('//', false, 'the pattern should contain at least 1 character'), array('/a/', true, 'valid regex'), array('/foo/', true, 'valid regex'), array('/foo/i', true, 'valid regex with a single modifier'), array('/foo/imsxu', true, 'valid regex with multiple modifiers'), array('#foo#', true, '"#" is a valid delimiter'), array('{foo}', true, '"{,}" is a valid delimiter pair'), array('*foo.*', false, '"*" is not considered as a valid delimiter'), array('?foo.?', false, '"?" is not considered as a valid delimiter'), ); } } class TestMultiplePcreFilterIterator extends MultiplePcreFilterIterator { public function __construct() { } public function accept() { throw new \BadFunctionCallException('Not implemented'); } public function isRegex($str) { return parent::isRegex($str); } public function toRegex($str) { throw new \BadFunctionCallException('Not implemented'); } } Symfony/Component/Finder/Tests/Iterator/FilecontentFilterIteratorTest.php000064400000005233152376005700022767 0ustar00 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Finder\Tests\Iterator; use Symfony\Component\Finder\Iterator\FilecontentFilterIterator; class FilecontentFilterIteratorTest extends IteratorTestCase { public function testAccept() { $inner = new MockFileListIterator(array('test.txt')); $iterator = new FilecontentFilterIterator($inner, array(), array()); $this->assertIterator(array('test.txt'), $iterator); } public function testDirectory() { $inner = new MockFileListIterator(array('directory')); $iterator = new FilecontentFilterIterator($inner, array('directory'), array()); $this->assertIterator(array(), $iterator); } public function testUnreadableFile() { $inner = new MockFileListIterator(array('file r-')); $iterator = new FilecontentFilterIterator($inner, array('file r-'), array()); $this->assertIterator(array(), $iterator); } /** * @dataProvider getTestFilterData */ public function testFilter(\Iterator $inner, array $matchPatterns, array $noMatchPatterns, array $resultArray) { $iterator = new FilecontentFilterIterator($inner, $matchPatterns, $noMatchPatterns); $this->assertIterator($resultArray, $iterator); } public function getTestFilterData() { $inner = new MockFileListIterator(); $inner[] = new MockSplFileInfo(array( 'name' => 'a.txt', 'contents' => 'Lorem ipsum...', 'type' => 'file', 'mode' => 'r+') ); $inner[] = new MockSplFileInfo(array( 'name' => 'b.yml', 'contents' => 'dolor sit...', 'type' => 'file', 'mode' => 'r+') ); $inner[] = new MockSplFileInfo(array( 'name' => 'some/other/dir/third.php', 'contents' => 'amet...', 'type' => 'file', 'mode' => 'r+') ); $inner[] = new MockSplFileInfo(array( 'name' => 'unreadable-file.txt', 'contents' => false, 'type' => 'file', 'mode' => 'r+') ); return array( array($inner, array('.'), array(), array('a.txt', 'b.yml', 'some/other/dir/third.php')), array($inner, array('ipsum'), array(), array('a.txt')), array($inner, array('i', 'amet'), array('Lorem', 'amet'), array('b.yml')), ); } } Symfony/Component/Finder/phpunit.xml.dist000064400000001465152376005700014547 0ustar00 ./Tests/ ./ ./Tests ./vendor