DepthRangeIteratorTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Finder\Iterator;
  11. use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
  12. use Symfony\Component\Finder\Comparator\NumberComparator;
  13. require_once __DIR__.'/RealIteratorTestCase.php';
  14. class DepthRangeFilterIteratorTest extends RealIteratorTestCase
  15. {
  16. /**
  17. * @dataProvider getAcceptData
  18. */
  19. public function testAccept($size, $expected)
  20. {
  21. $inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getAbsolutePath(''), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
  22. $iterator = new DepthRangeFilterIterator($inner, $size);
  23. $actual = array_keys(iterator_to_array($iterator));
  24. sort($expected);
  25. sort($actual);
  26. $this->assertEquals($expected, $actual);
  27. }
  28. public function getAcceptData()
  29. {
  30. return array(
  31. array(array(new NumberComparator('< 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'))),
  32. array(array(new NumberComparator('<= 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'))),
  33. array(array(new NumberComparator('> 1')), array()),
  34. array(array(new NumberComparator('>= 1')), array($this->getAbsolutePath('/foo/bar.tmp'))),
  35. array(array(new NumberComparator('1')), array($this->getAbsolutePath('/foo/bar.tmp'))),
  36. );
  37. }
  38. protected function getAbsolutePath($path)
  39. {
  40. return sys_get_temp_dir().'/symfony2_finder'.str_replace('/', DIRECTORY_SEPARATOR, $path);
  41. }
  42. }