-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.x'
* origin/1.x: Add path wildcard feature to Enumerator (#300) Conflicts: composer.json composer.lock
- Loading branch information
Showing
4 changed files
with
260 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace Go\Instrument; | ||
|
||
use Go\Instrument\FileSystem\Enumerator; | ||
use org\bovigo\vfs\vfsStream; | ||
use Vfs\FileSystem; | ||
|
||
class EnumeratorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** @var FileSystem */ | ||
protected static $fileSystem; | ||
|
||
/** | ||
* Set up fixture test folders and files | ||
* | ||
* @throws \Exception | ||
* @return void | ||
*/ | ||
public static function setUpBeforeClass() | ||
{ | ||
static::$fileSystem = FileSystem::factory('vfs://'); | ||
static::$fileSystem->mount(); | ||
|
||
$testPaths = [ | ||
'/base/sub/test', | ||
'/base/sub/sub/test' | ||
]; | ||
|
||
// Setup some files we test against | ||
foreach ($testPaths as $path) { | ||
mkdir('vfs://' . $path, 0777, true); | ||
touch('vfs://' . $path . DIRECTORY_SEPARATOR . 'TestClass.php'); | ||
} | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
{ | ||
static::$fileSystem->unmount(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function pathsProvider() | ||
{ | ||
return [ | ||
[ | ||
// No include or exclude, every folder should be there | ||
['vfs://base/sub/test', 'vfs://base/sub/sub/test'], | ||
[], | ||
[] | ||
], | ||
[ | ||
// Exclude double sub folder | ||
['vfs://base/sub/test'], | ||
[], | ||
['vfs://base/sub/sub/test'] | ||
], | ||
[ | ||
// Exclude all, expected shout be empty | ||
[], | ||
[], | ||
['vfs://base/sub/test', 'vfs://base/sub/sub/test'] | ||
], | ||
[ | ||
// Exclude all sub using wildcard | ||
[], | ||
[], | ||
['vfs://base/*/test'] | ||
], | ||
[ | ||
// Includepath using wildcard should not break | ||
['vfs://base/sub/test', 'vfs://base/sub/sub/test'], | ||
['vfs://base/*'], | ||
[] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Test wildcard path matching for Enumerator. | ||
* | ||
* @dataProvider pathsProvider | ||
* | ||
* @param array $expectedPaths | ||
* @param array $includePaths | ||
* @param array $excludePaths | ||
*/ | ||
public function testExclude($expectedPaths, $includePaths, $excludePaths) | ||
{ | ||
$testPaths = []; | ||
|
||
/** @var Enumerator $mock */ | ||
$mock = $this->getMockBuilder(Enumerator::class) | ||
->setConstructorArgs(['vfs://base', $includePaths, $excludePaths]) | ||
->setMethods(['getFileFullPath']) | ||
->getMock(); | ||
|
||
// Mock getFileRealPath method to provide a pathname | ||
// VFS does not support getRealPath() | ||
$mock->expects($this->any()) | ||
->method('getFileFullPath') | ||
->will($this->returnCallback(function (\SplFileInfo $file) { | ||
return $file->getPathname(); | ||
})); | ||
|
||
$iterator = $mock->enumerate(); | ||
|
||
foreach ($iterator as $file) { | ||
$testPaths[] = $file->getPath(); | ||
} | ||
|
||
sort($testPaths); | ||
sort($expectedPaths); | ||
|
||
$this->assertEquals($expectedPaths, $testPaths); | ||
} | ||
} |