Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Finder] fixed various CS issues and added a reference to the relevan…

…t PHP bug
  • Loading branch information...
commit 304b90eed4b2fed6f4831b569c2a7fb68ea61a14 1 parent 008b92d
@fabpot fabpot authored
View
19 Iterator/FilterIterator.php
@@ -3,7 +3,7 @@
/*
* This file is part of the Symfony package.
*
- * (c) Alex Bogomazov
+ * (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -14,6 +14,8 @@
/**
* This iterator just overrides the rewind method in order to correct a PHP bug.
*
+ * @see https://bugs.php.net/bug.php?id=49104
+ *
* @author Alex Bogomazov
*/
abstract class FilterIterator extends \FilterIterator
@@ -21,19 +23,20 @@
/**
* This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
* rewind in some cases.
+ *
* @see FilterIterator::rewind()
*/
- public function rewind()
+ public function rewind()
{
$iterator = $this;
while ($iterator instanceof \OuterIterator) {
- if ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
- $iterator->getInnerIterator()->next();
- $iterator->getInnerIterator()->rewind();
+ if ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
+ $iterator->getInnerIterator()->next();
+ $iterator->getInnerIterator()->rewind();
}
- $iterator = $iterator->getInnerIterator();
+ $iterator = $iterator->getInnerIterator();
}
- parent::rewind();
- }
+ parent::rewind();
+ }
}
View
22 Tests/FinderTest.php
@@ -443,20 +443,20 @@ public function testNotContainsOnDirectory()
/**
* Searching in multiple locations 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 testMultipleLocations()
- {
- $tmpDir = sys_get_temp_dir() . '/symfony2_finder';
-
- $locations = array(
- $tmpDir . '/',
- $tmpDir . '/toto/',
+ public function testMultipleLocations()
+ {
+ $locations = array(
+ self::$tmpDir.'/',
+ self::$tmpDir.'/toto/',
);
-
+
// it is expected that there are test.py test.php in the tmpDir
- $finder = new Finder();
+ $finder = new Finder();
$finder->in($locations)->depth('< 1')->name('test.php');
- $this->assertEquals(1, count($finder));
- }
+ $this->assertEquals(1, count($finder));
+ }
}
View
24 Tests/Iterator/FilterIteratorTest.php
@@ -3,7 +3,7 @@
/*
* This file is part of the Symfony package.
*
- * (c) Alex Bogomazov
+ * (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,28 +11,30 @@
namespace Symfony\Component\Finder\Tests\Iterator;
+/**
+ * @author Alex Bogomazov
+ */
class FilterIteratorTest extends RealIteratorTestCase
{
public function testFilterFilesystemIterators()
{
- $tmpDir = sys_get_temp_dir().'/symfony2_finder';
-
-
- $i = new \FilesystemIterator($tmpDir);
+ $i = new \FilesystemIterator(sys_get_temp_dir().'/symfony2_finder');
// 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());
- }));
+ $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 works
- $this->assertEquals(1, $c);
+ $this->assertEquals(1, $c);
$i->rewind();
@@ -40,7 +42,9 @@ public function testFilterFilesystemIterators()
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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.