Repository navigation
Expand file tree
/
Copy pathLoader.php
More file actions
120 lines (105 loc) · 2.98 KB
/
Copy pathLoader.php
File metadata and controls
120 lines (105 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?hh // strict
namespace HackPack\HackUnit\Tests\Test;
use HackPack\HackUnit\Contract\Assert;
use HackPack\HackUnit\Test\Loader;
class LoaderTest {
private string $fileDir;
private Vector<string> $fileNames = Vector {};
private Loader $loader;
public function __construct() {
$this->fileDir = dirname(__DIR__).'/Fixtures/LoadingFiles';
$this->loader = new Loader(
$filename ==> {
$this->fileNames->add($filename);
return Vector {};
},
);
}
<<Test>>
public function ignoresMultipleFiles(Assert $assert): void {
$this->loader
->including($this->fileDir)
->excluding($this->fileDir.'/IgnoreMe/file1')
->excluding($this->fileDir.'/IgnoreMe/file2');
$this->assertExpectedFiles(
$assert,
Vector {
$this->fileDir.'/file1',
$this->fileDir.'/file2',
$this->fileDir.'/file3',
$this->fileDir.'/IgnoreMe/file3',
},
);
}
<<Test>>
public function ignoresFile(Assert $assert): void {
$this->loader
->including($this->fileDir)
->excluding($this->fileDir.'/IgnoreMe/file1');
$this->assertExpectedFiles(
$assert,
Vector {
$this->fileDir.'/file1',
$this->fileDir.'/file2',
$this->fileDir.'/file3',
$this->fileDir.'/IgnoreMe/file2',
$this->fileDir.'/IgnoreMe/file3',
},
);
}
<<Test>>
public function ignoresFolder(Assert $assert): void {
$this->loader
->including($this->fileDir)
->excluding($this->fileDir.'/IgnoreMe');
$this->assertExpectedFiles(
$assert,
Vector {
$this->fileDir.'/file1',
$this->fileDir.'/file2',
$this->fileDir.'/file3',
},
);
}
<<Test>>
public function loadsAllFiles(Assert $assert): void {
$this->loader->including($this->fileDir);
$this->assertExpectedFiles(
$assert,
Vector {
$this->fileDir.'/file1',
$this->fileDir.'/file2',
$this->fileDir.'/file3',
$this->fileDir.'/IgnoreMe/file1',
$this->fileDir.'/IgnoreMe/file2',
$this->fileDir.'/IgnoreMe/file3',
},
);
}
<<Test>>
public function loadsSingleFile(Assert $assert): void {
$this->loader->including($this->fileDir.'/file1');
$this->assertExpectedFiles($assert, Vector {$this->fileDir.'/file1'});
}
<<Test>>
public function loadsMultipleFiles(Assert $assert): void {
$this->loader
->including($this->fileDir.'/file1')
->including($this->fileDir.'/file2');
$this->assertExpectedFiles(
$assert,
Vector {$this->fileDir.'/file1', $this->fileDir.'/file2'},
);
}
private function assertExpectedFiles(
Assert $assert,
Vector<string> $expectedFiles,
): void {
// This actually hits the filesystem
$this->loader->testSuites();
$missing = array_diff($expectedFiles, $this->fileNames);
$extra = array_diff($this->fileNames, $expectedFiles);
$assert->int(count($missing))->eq(0);
$assert->int(count($extra))->eq(0);
}
}