merged branch alquerci/issue-4922 (PR #8127)
This PR was squashed before being merged into the 2.1 branch (closes #8127).
Discussion
----------
[Finder] Fix unexpected duplicate sub path related AppendIterator issue
Bug fix: yes
New feature: no
BC breaks: no
Deprecations: no
Tests pass: yes
Fixes: https://github.com/symfony/symfony/pull/4993#issuecomment-8515845
Todo: -
License of the code: MIT
> @dg: I am afraid it is not working, see this example http://davidgrudl.com/tmp/appenditerator-finder.zip.
Commits
-------
45b68e0
[Finder] Fix unexpected duplicate sub path related AppendIterator issue
This commit is contained in:
commit
927718afa9
@ -38,4 +38,12 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
|||||||
{
|
{
|
||||||
return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
|
return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rewind()
|
||||||
|
{
|
||||||
|
// @see https://bugs.php.net/bug.php?id=49104
|
||||||
|
parent::next();
|
||||||
|
|
||||||
|
parent::rewind();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,4 +459,30 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
|||||||
|
|
||||||
$this->assertEquals(1, count($finder));
|
$this->assertEquals(1, count($finder));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searching in multiple locations with sub directories involves
|
||||||
|
* AppendIterator which does an unnecessary rewind which leaves
|
||||||
|
* FilterIterator with inner FilesystemIterator in an ivalid state.
|
||||||
|
*
|
||||||
|
* @see https://bugs.php.net/bug.php?id=49104
|
||||||
|
*/
|
||||||
|
public function testMultipleLocationsWithSubDirectories()
|
||||||
|
{
|
||||||
|
$locations = array(
|
||||||
|
__DIR__.'/Fixtures/one',
|
||||||
|
self::$files[8],
|
||||||
|
);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
0
src/Symfony/Component/Finder/Tests/Fixtures/one/a
Normal file
0
src/Symfony/Component/Finder/Tests/Fixtures/one/a
Normal file
@ -29,4 +29,41 @@ abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals($expected, array_values($values));
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user