1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ComposerRequireCheckerTest\FileLocator; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use ComposerRequireChecker\FileLocator\LocateFilesByGlobPattern; |
7
|
|
|
use org\bovigo\vfs\vfsStream; |
8
|
|
|
use org\bovigo\vfs\vfsStreamDirectory; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
final class LocateFilesByGlobPatternTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var LocateFilesByGlobPattern |
16
|
|
|
*/ |
17
|
|
|
private $locator; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var vfsStreamDirectory |
21
|
|
|
*/ |
22
|
|
|
private $root; |
23
|
|
|
|
24
|
|
|
protected function setUp(): void |
25
|
|
|
{ |
26
|
|
|
$this->locator = new LocateFilesByGlobPattern(); |
27
|
|
|
$this->root = vfsStream::setup(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testSimpleGlobPattern(): void |
31
|
|
|
{ |
32
|
|
|
vfsStream::create([ |
33
|
|
|
'bin' => [ |
34
|
|
|
'console' => '', |
35
|
|
|
'not-console' => '', |
36
|
|
|
], |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$files = $this->files(['bin/console'], $this->root->url()); |
40
|
|
|
self::assertCount(1, $files); |
41
|
|
|
self::assertContains($this->root->getChild('bin/console')->url(), $files); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGlobPattern(): void |
45
|
|
|
{ |
46
|
|
|
vfsStream::create([ |
47
|
|
|
'bin' => [ |
48
|
|
|
'console.php' => '', |
49
|
|
|
'console123.php' => '', |
50
|
|
|
'not-console' => '', |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
$files = $this->files(['bin/console*.php'], $this->root->url()); |
55
|
|
|
self::assertCount(2, $files); |
56
|
|
|
self::assertContains($this->root->getChild('bin/console.php')->url(), $files); |
57
|
|
|
self::assertContains($this->root->getChild('bin/console123.php')->url(), $files); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string[] |
62
|
|
|
*/ |
63
|
|
|
private function files(array $globPatterns, $dir): array |
64
|
|
|
{ |
65
|
|
|
$files = []; |
66
|
|
|
$filesGenerator = ($this->locator)($globPatterns, $dir); |
67
|
|
|
foreach ($filesGenerator as $file) { |
68
|
|
|
$files[] = $file; |
69
|
|
|
} |
70
|
|
|
return $files; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|