diff --git a/src/Iterator/GlobIterator.php b/src/Iterator/GlobIterator.php index 8fb4691..ed11ac4 100644 --- a/src/Iterator/GlobIterator.php +++ b/src/Iterator/GlobIterator.php @@ -78,8 +78,8 @@ public function __construct(string $glob, int $flags = 0, bool $skipErrors = fal RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS ), - RecursiveIteratorIterator::SELF_FIRST - | ($skipErrors ? RecursiveIteratorIterator::SELF_FIRST : 0) + RecursiveIteratorIterator::SELF_FIRST, + ($skipErrors ? RecursiveIteratorIterator::CATCH_GET_CHILD : 0) ), GlobFilterIterator::FILTER_VALUE, $flags diff --git a/tests/Iterator/GlobIteratorErrorTest.php b/tests/Iterator/GlobIteratorErrorTest.php new file mode 100644 index 0000000..9cfc322 --- /dev/null +++ b/tests/Iterator/GlobIteratorErrorTest.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Webmozart\Glob\Tests\Iterator; + +use Symfony\Component\Filesystem\Filesystem; +use Webmozart\Glob\Iterator\GlobIterator; +use Webmozart\Glob\Test\TestUtil; + +/** + * @since 1.0 + * + * @author Bernhard Schussek + */ +class GlobIteratorErrorTest extends \PHPUnit\Framework\TestCase +{ + private $tempDir; + + protected function setUp(): void + { + $this->tempDir = TestUtil::makeTempDir('webmozart-glob', __CLASS__); + + $filesystem = new Filesystem(); + $filesystem->mirror(__DIR__.'/../Fixtures', $this->tempDir); + } + + protected function tearDown(): void + { + $filesystem = new Filesystem(); + chmod($this->tempDir.'/js', 0777); + $filesystem->remove($this->tempDir); + } + + public function testIterateError() + { + if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + $this->markTestSkipped('chmod tests only on Linux.'); + + return; + } + $this->expectException(\UnexpectedValueException::class); + chmod($this->tempDir.'/js', 0111); + $iterator = new GlobIterator($this->tempDir.'/**/*.css'); + iterator_to_array($iterator); + } + + public function testIterateWithoutError() + { + if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + $this->markTestSkipped('chmod tests only on Linux.'); + + return; + } + chmod($this->tempDir.'/js', 0111); + $iterator = new GlobIterator($this->tempDir.'/**/*.css', 0, true); + $this->assertNotEmpty(iterator_to_array($iterator)); + } + +}