Skip to content

Commit

Permalink
Tests for skipErrors.
Browse files Browse the repository at this point in the history
  • Loading branch information
zobo committed May 17, 2022
1 parent fd16e84 commit 84830d9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Iterator/GlobIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions tests/Iterator/GlobIteratorErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
* This file is part of the webmozart/glob package.
*
* (c) Bernhard Schussek <bschussek@gmail.com>
*
* 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 <bschussek@gmail.com>
*/
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));
}

}

0 comments on commit 84830d9

Please sign in to comment.