1 | <?php |
||
7 | class TestFileLoader |
||
8 | { |
||
9 | /** |
||
10 | * The pattern used for grabbing test files. Uses the *Test.php convention |
||
11 | * that PHPUnit defaults to. |
||
12 | */ |
||
13 | const TEST_PATTERN = '/.+Test\.php$/'; |
||
14 | |||
15 | /** |
||
16 | * Matches php files. |
||
17 | */ |
||
18 | const FILE_PATTERN = '/.+\.php$/'; |
||
19 | |||
20 | /** |
||
21 | * Used to ignore directory paths '.' and '..'. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private static $dotPattern = '/([.]+)$/'; |
||
26 | |||
27 | /** |
||
28 | * The collection of loaded files for this test suite. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $files = []; |
||
33 | |||
34 | /** |
||
35 | * The collection of excluded files. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $excludedFiles = []; |
||
40 | |||
41 | /** |
||
42 | * When true, the SuiteLoader add the files to excluded files. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $excludingFiles = false; |
||
47 | |||
48 | 24 | public function __construct(Options $options = null) |
|
52 | |||
53 | /** |
||
54 | * Loads a SuitePath and makes sure to |
||
55 | * take into account the excluded directory / files. |
||
56 | * |
||
57 | * @param SuitePath $path |
||
58 | * |
||
59 | * @return string[] |
||
60 | */ |
||
61 | 12 | public function loadSuitePath(SuitePath $path): array |
|
80 | |||
81 | /** |
||
82 | * Loads suites based on a specific path. |
||
83 | * A valid path can be a directory or file. |
||
84 | * |
||
85 | * @param $path |
||
86 | * @param $pattern |
||
87 | * |
||
88 | * @throws \InvalidArgumentException |
||
89 | * |
||
90 | * @return string[] |
||
91 | */ |
||
92 | 22 | public function loadPath(string $path, string $pattern = null): array |
|
109 | |||
110 | /** |
||
111 | * Loads suites from a directory. |
||
112 | * |
||
113 | * @param string $path |
||
114 | * @param string $pattern |
||
115 | */ |
||
116 | 13 | private function loadDir(string $path, string $pattern = self::TEST_PATTERN) |
|
123 | |||
124 | /** |
||
125 | * Load a single suite file. |
||
126 | * |
||
127 | * @param $path |
||
128 | */ |
||
129 | 11 | private function loadFile(string $path) |
|
133 | |||
134 | /** |
||
135 | * Attempts to load suites from a path. |
||
136 | * |
||
137 | * @param string $path |
||
138 | * @param string $pattern regular expression for matching file names |
||
139 | */ |
||
140 | 20 | private function tryLoadTests(string $path, string $pattern = self::TEST_PATTERN) |
|
154 | } |
||
155 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: