99 */
1010namespace PHPUnit \Util ;
1111
12- use Composer \Autoload \ClassLoader ;
13- use DeepCopy \DeepCopy ;
14- use Doctrine \Instantiator \Instantiator ;
15- use PharIo \Manifest \Manifest ;
16- use PharIo \Version \Version as PharIoVersion ;
17- use PHP_Token ;
18- use phpDocumentor \Reflection \DocBlock ;
19- use phpDocumentor \Reflection \Project ;
20- use phpDocumentor \Reflection \Type ;
21- use PHPUnit \Framework \TestCase ;
22- use Prophecy \Prophet ;
23- use SebastianBergmann \CodeCoverage \CodeCoverage ;
24- use SebastianBergmann \CodeUnit \CodeUnit ;
25- use SebastianBergmann \CodeUnitReverseLookup \Wizard ;
26- use SebastianBergmann \Comparator \Comparator ;
27- use SebastianBergmann \Diff \Diff ;
28- use SebastianBergmann \Environment \Runtime ;
29- use SebastianBergmann \Exporter \Exporter ;
30- use SebastianBergmann \FileIterator \Facade as FileIteratorFacade ;
31- use SebastianBergmann \GlobalState \Snapshot ;
32- use SebastianBergmann \Invoker \Invoker ;
33- use SebastianBergmann \ObjectEnumerator \Enumerator ;
34- use SebastianBergmann \RecursionContext \Context ;
35- use SebastianBergmann \ResourceOperations \ResourceOperations ;
36- use SebastianBergmann \Template \Template ;
37- use SebastianBergmann \Timer \Timer ;
38- use SebastianBergmann \Type \TypeName ;
39- use SebastianBergmann \Version ;
40- use TheSeer \Tokenizer \Tokenizer ;
41- use Webmozart \Assert \Assert ;
42-
12+ /**
13+ * @deprecated Use ExcludeList instead
14+ */
4315final class Blacklist
4416{
45- /**
46- * @var array<string,int>
47- */
48- private const BLACKLISTED_CLASS_NAMES = [
49- // composer
50- ClassLoader::class => 1 ,
51-
52- // doctrine/instantiator
53- Instantiator::class => 1 ,
54-
55- // myclabs/deepcopy
56- DeepCopy::class => 1 ,
57-
58- // phar-io/manifest
59- Manifest::class => 1 ,
60-
61- // phar-io/version
62- PharIoVersion::class => 1 ,
63-
64- // phpdocumentor/reflection-common
65- Project::class => 1 ,
66-
67- // phpdocumentor/reflection-docblock
68- DocBlock::class => 1 ,
69-
70- // phpdocumentor/type-resolver
71- Type::class => 1 ,
72-
73- // phpspec/prophecy
74- Prophet::class => 1 ,
75-
76- // phpunit/phpunit
77- TestCase::class => 2 ,
78-
79- // phpunit/php-code-coverage
80- CodeCoverage::class => 1 ,
81-
82- // phpunit/php-file-iterator
83- FileIteratorFacade::class => 1 ,
84-
85- // phpunit/php-invoker
86- Invoker::class => 1 ,
87-
88- // phpunit/php-text-template
89- Template::class => 1 ,
90-
91- // phpunit/php-timer
92- Timer::class => 1 ,
93-
94- // phpunit/php-token-stream
95- PHP_Token::class => 1 ,
96-
97- // sebastian/code-unit
98- CodeUnit::class => 1 ,
99-
100- // sebastian/code-unit-reverse-lookup
101- Wizard::class => 1 ,
102-
103- // sebastian/comparator
104- Comparator::class => 1 ,
105-
106- // sebastian/diff
107- Diff::class => 1 ,
108-
109- // sebastian/environment
110- Runtime::class => 1 ,
111-
112- // sebastian/exporter
113- Exporter::class => 1 ,
114-
115- // sebastian/global-state
116- Snapshot::class => 1 ,
117-
118- // sebastian/object-enumerator
119- Enumerator::class => 1 ,
120-
121- // sebastian/recursion-context
122- Context::class => 1 ,
123-
124- // sebastian/resource-operations
125- ResourceOperations::class => 1 ,
126-
127- // sebastian/type
128- TypeName::class => 1 ,
129-
130- // sebastian/version
131- Version::class => 1 ,
132-
133- // theseer/tokenizer
134- Tokenizer::class => 1 ,
135-
136- // webmozart/assert
137- Assert::class => 1 ,
138- ];
139-
140- /**
141- * @var string[]
142- */
143- private static $ directories ;
144-
14517 public static function addDirectory (string $ directory ): void
14618 {
147- if (!\is_dir ($ directory )) {
148- throw new Exception (
149- \sprintf (
150- '"%s" is not a directory ' ,
151- $ directory
152- )
153- );
154- }
155-
156- self ::$ directories [] = \realpath ($ directory );
19+ ExcludeList::addDirectory ($ directory );
15720 }
15821
15922 /**
@@ -163,69 +26,14 @@ public static function addDirectory(string $directory): void
16326 */
16427 public function getBlacklistedDirectories (): array
16528 {
166- $ this ->initialize ();
167-
168- return self ::$ directories ;
29+ return (new ExcludeList )->getExcludedDirectories ();
16930 }
17031
17132 /**
17233 * @throws Exception
17334 */
17435 public function isBlacklisted (string $ file ): bool
17536 {
176- if (\defined ('PHPUNIT_TESTSUITE ' )) {
177- return false ;
178- }
179-
180- $ this ->initialize ();
181-
182- foreach (self ::$ directories as $ directory ) {
183- if (\strpos ($ file , $ directory ) === 0 ) {
184- return true ;
185- }
186- }
187-
188- return false ;
189- }
190-
191- /**
192- * @throws Exception
193- */
194- private function initialize (): void
195- {
196- if (self ::$ directories === null ) {
197- self ::$ directories = [];
198-
199- foreach (self ::BLACKLISTED_CLASS_NAMES as $ className => $ parent ) {
200- if (!\class_exists ($ className )) {
201- continue ;
202- }
203-
204- try {
205- $ directory = (new \ReflectionClass ($ className ))->getFileName ();
206- // @codeCoverageIgnoreStart
207- } catch (\ReflectionException $ e ) {
208- throw new Exception (
209- $ e ->getMessage (),
210- (int ) $ e ->getCode (),
211- $ e
212- );
213- }
214- // @codeCoverageIgnoreEnd
215-
216- for ($ i = 0 ; $ i < $ parent ; $ i ++) {
217- $ directory = \dirname ($ directory );
218- }
219-
220- self ::$ directories [] = $ directory ;
221- }
222-
223- // Hide process isolation workaround on Windows.
224- if (\DIRECTORY_SEPARATOR === '\\' ) {
225- // tempnam() prefix is limited to first 3 chars.
226- // @see https://php.net/manual/en/function.tempnam.php
227- self ::$ directories [] = \sys_get_temp_dir () . '\\PHP ' ;
228- }
229- }
37+ return (new ExcludeList )->isExcluded ($ file );
23038 }
23139}
0 commit comments