FilePathsIteratorTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Component\Finder\Tests\Iterator;
  11. use Symfony\Component\Finder\Iterator\FilePathsIterator;
  12. /**
  13. * @group legacy
  14. */
  15. class FilePathsIteratorTest extends RealIteratorTestCase
  16. {
  17. /**
  18. * @dataProvider getSubPathData
  19. */
  20. public function testSubPath($baseDir, array $paths, array $subPaths, array $subPathnames)
  21. {
  22. $iterator = new FilePathsIterator($paths, $baseDir);
  23. foreach ($iterator as $index => $file) {
  24. $this->assertEquals($paths[$index], $file->getPathname());
  25. $this->assertEquals($subPaths[$index], $iterator->getSubPath());
  26. $this->assertEquals($subPathnames[$index], $iterator->getSubPathname());
  27. }
  28. }
  29. public function getSubPathData()
  30. {
  31. $tmpDir = sys_get_temp_dir().'/symfony_finder';
  32. return array(
  33. array(
  34. $tmpDir,
  35. array(
  36. // paths
  37. $tmpDir.\DIRECTORY_SEPARATOR.'.git' => $tmpDir.\DIRECTORY_SEPARATOR.'.git',
  38. $tmpDir.\DIRECTORY_SEPARATOR.'test.py' => $tmpDir.\DIRECTORY_SEPARATOR.'test.py',
  39. $tmpDir.\DIRECTORY_SEPARATOR.'foo' => $tmpDir.\DIRECTORY_SEPARATOR.'foo',
  40. $tmpDir.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar.tmp' => $tmpDir.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar.tmp',
  41. $tmpDir.\DIRECTORY_SEPARATOR.'test.php' => $tmpDir.\DIRECTORY_SEPARATOR.'test.php',
  42. $tmpDir.\DIRECTORY_SEPARATOR.'toto' => $tmpDir.\DIRECTORY_SEPARATOR.'toto',
  43. ),
  44. array(
  45. // subPaths
  46. $tmpDir.\DIRECTORY_SEPARATOR.'.git' => '',
  47. $tmpDir.\DIRECTORY_SEPARATOR.'test.py' => '',
  48. $tmpDir.\DIRECTORY_SEPARATOR.'foo' => '',
  49. $tmpDir.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar.tmp' => 'foo',
  50. $tmpDir.\DIRECTORY_SEPARATOR.'test.php' => '',
  51. $tmpDir.\DIRECTORY_SEPARATOR.'toto' => '',
  52. ),
  53. array(
  54. // subPathnames
  55. $tmpDir.\DIRECTORY_SEPARATOR.'.git' => '.git',
  56. $tmpDir.\DIRECTORY_SEPARATOR.'test.py' => 'test.py',
  57. $tmpDir.\DIRECTORY_SEPARATOR.'foo' => 'foo',
  58. $tmpDir.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'bar.tmp' => 'foo'.\DIRECTORY_SEPARATOR.'bar.tmp',
  59. $tmpDir.\DIRECTORY_SEPARATOR.'test.php' => 'test.php',
  60. $tmpDir.\DIRECTORY_SEPARATOR.'toto' => 'toto',
  61. ),
  62. ),
  63. );
  64. }
  65. }