Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Framework;
11
 
12
use const PHP_EOL;
13
use function array_keys;
14
use function array_map;
15
use function array_merge;
16
use function array_slice;
17
use function array_unique;
18
use function basename;
19
use function call_user_func;
20
use function class_exists;
21
use function count;
22
use function dirname;
23
use function get_declared_classes;
24
use function implode;
25
use function is_bool;
26
use function is_callable;
27
use function is_file;
28
use function is_object;
29
use function is_string;
30
use function method_exists;
31
use function preg_match;
32
use function preg_quote;
33
use function sprintf;
34
use function strpos;
35
use function substr;
36
use Iterator;
37
use IteratorAggregate;
38
use PHPUnit\Runner\BaseTestRunner;
39
use PHPUnit\Runner\Filter\Factory;
40
use PHPUnit\Runner\PhptTestCase;
41
use PHPUnit\Util\FileLoader;
42
use PHPUnit\Util\Reflection;
43
use PHPUnit\Util\Test as TestUtil;
44
use ReflectionClass;
45
use ReflectionException;
46
use ReflectionMethod;
47
use Throwable;
48
 
49
/**
50
 * @template-implements IteratorAggregate<int, Test>
51
 *
52
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
53
 */
54
class TestSuite implements IteratorAggregate, Reorderable, SelfDescribing, Test
55
{
56
    /**
57
     * Enable or disable the backup and restoration of the $GLOBALS array.
58
     *
59
     * @var bool
60
     */
61
    protected $backupGlobals;
62
 
63
    /**
64
     * Enable or disable the backup and restoration of static attributes.
65
     *
66
     * @var bool
67
     */
68
    protected $backupStaticAttributes;
69
 
70
    /**
71
     * @var bool
72
     */
73
    protected $runTestInSeparateProcess = false;
74
 
75
    /**
76
     * The name of the test suite.
77
     *
78
     * @var string
79
     */
80
    protected $name = '';
81
 
82
    /**
83
     * The test groups of the test suite.
84
     *
85
     * @psalm-var array<string,list<Test>>
86
     */
87
    protected $groups = [];
88
 
89
    /**
90
     * The tests in the test suite.
91
     *
92
     * @var Test[]
93
     */
94
    protected $tests = [];
95
 
96
    /**
97
     * The number of tests in the test suite.
98
     *
99
     * @var int
100
     */
101
    protected $numTests = -1;
102
 
103
    /**
104
     * @var bool
105
     */
106
    protected $testCase = false;
107
 
108
    /**
109
     * @var string[]
110
     */
111
    protected $foundClasses = [];
112
 
113
    /**
114
     * @var null|list<ExecutionOrderDependency>
115
     */
116
    protected $providedTests;
117
 
118
    /**
119
     * @var null|list<ExecutionOrderDependency>
120
     */
121
    protected $requiredTests;
122
 
123
    /**
124
     * @var bool
125
     */
126
    private $beStrictAboutChangesToGlobalState;
127
 
128
    /**
129
     * @var Factory
130
     */
131
    private $iteratorFilter;
132
 
133
    /**
134
     * @var int
135
     */
136
    private $declaredClassesPointer;
137
 
138
    /**
139
     * @psalm-var array<int,string>
140
     */
141
    private $warnings = [];
142
 
143
    /**
144
     * Constructs a new TestSuite.
145
     *
146
     *   - PHPUnit\Framework\TestSuite() constructs an empty TestSuite.
147
     *
148
     *   - PHPUnit\Framework\TestSuite(ReflectionClass) constructs a
149
     *     TestSuite from the given class.
150
     *
151
     *   - PHPUnit\Framework\TestSuite(ReflectionClass, String)
152
     *     constructs a TestSuite from the given class with the given
153
     *     name.
154
     *
155
     *   - PHPUnit\Framework\TestSuite(String) either constructs a
156
     *     TestSuite from the given class (if the passed string is the
157
     *     name of an existing class) or constructs an empty TestSuite
158
     *     with the given name.
159
     *
160
     * @param ReflectionClass|string $theClass
161
     *
162
     * @throws Exception
163
     */
164
    public function __construct($theClass = '', string $name = '')
165
    {
166
        if (!is_string($theClass) && !$theClass instanceof ReflectionClass) {
167
            throw InvalidArgumentException::create(
168
                1,
169
                'ReflectionClass object or string'
170
            );
171
        }
172
 
173
        $this->declaredClassesPointer = count(get_declared_classes());
174
 
175
        if (!$theClass instanceof ReflectionClass) {
176
            if (class_exists($theClass, true)) {
177
                if ($name === '') {
178
                    $name = $theClass;
179
                }
180
 
181
                try {
182
                    $theClass = new ReflectionClass($theClass);
183
                } catch (ReflectionException $e) {
184
                    throw new Exception(
185
                        $e->getMessage(),
186
                        $e->getCode(),
187
                        $e
188
                    );
189
                }
190
                // @codeCoverageIgnoreEnd
191
            } else {
192
                $this->setName($theClass);
193
 
194
                return;
195
            }
196
        }
197
 
198
        if (!$theClass->isSubclassOf(TestCase::class)) {
199
            $this->setName((string) $theClass);
200
 
201
            return;
202
        }
203
 
204
        if ($name !== '') {
205
            $this->setName($name);
206
        } else {
207
            $this->setName($theClass->getName());
208
        }
209
 
210
        $constructor = $theClass->getConstructor();
211
 
212
        if ($constructor !== null &&
213
            !$constructor->isPublic()) {
214
            $this->addTest(
215
                new WarningTestCase(
216
                    sprintf(
217
                        'Class "%s" has no public constructor.',
218
                        $theClass->getName()
219
                    )
220
                )
221
            );
222
 
223
            return;
224
        }
225
 
226
        foreach ((new Reflection)->publicMethodsInTestClass($theClass) as $method) {
227
            if (!TestUtil::isTestMethod($method)) {
228
                continue;
229
            }
230
 
231
            $this->addTestMethod($theClass, $method);
232
        }
233
 
234
        if (empty($this->tests)) {
235
            $this->addTest(
236
                new WarningTestCase(
237
                    sprintf(
238
                        'No tests found in class "%s".',
239
                        $theClass->getName()
240
                    )
241
                )
242
            );
243
        }
244
 
245
        $this->testCase = true;
246
    }
247
 
248
    /**
249
     * Returns a string representation of the test suite.
250
     */
251
    public function toString(): string
252
    {
253
        return $this->getName();
254
    }
255
 
256
    /**
257
     * Adds a test to the suite.
258
     *
259
     * @param array $groups
260
     */
261
    public function addTest(Test $test, $groups = []): void
262
    {
263
        try {
264
            $class = new ReflectionClass($test);
265
            // @codeCoverageIgnoreStart
266
        } catch (ReflectionException $e) {
267
            throw new Exception(
268
                $e->getMessage(),
269
                $e->getCode(),
270
                $e
271
            );
272
        }
273
        // @codeCoverageIgnoreEnd
274
 
275
        if (!$class->isAbstract()) {
276
            $this->tests[] = $test;
277
            $this->clearCaches();
278
 
279
            if ($test instanceof self && empty($groups)) {
280
                $groups = $test->getGroups();
281
            }
282
 
283
            if ($this->containsOnlyVirtualGroups($groups)) {
284
                $groups[] = 'default';
285
            }
286
 
287
            foreach ($groups as $group) {
288
                if (!isset($this->groups[$group])) {
289
                    $this->groups[$group] = [$test];
290
                } else {
291
                    $this->groups[$group][] = $test;
292
                }
293
            }
294
 
295
            if ($test instanceof TestCase) {
296
                $test->setGroups($groups);
297
            }
298
        }
299
    }
300
 
301
    /**
302
     * Adds the tests from the given class to the suite.
303
     *
304
     * @psalm-param object|class-string $testClass
305
     *
306
     * @throws Exception
307
     */
308
    public function addTestSuite($testClass): void
309
    {
310
        if (!(is_object($testClass) || (is_string($testClass) && class_exists($testClass)))) {
311
            throw InvalidArgumentException::create(
312
                1,
313
                'class name or object'
314
            );
315
        }
316
 
317
        if (!is_object($testClass)) {
318
            try {
319
                $testClass = new ReflectionClass($testClass);
320
                // @codeCoverageIgnoreStart
321
            } catch (ReflectionException $e) {
322
                throw new Exception(
323
                    $e->getMessage(),
324
                    $e->getCode(),
325
                    $e
326
                );
327
            }
328
            // @codeCoverageIgnoreEnd
329
        }
330
 
331
        if ($testClass instanceof self) {
332
            $this->addTest($testClass);
333
        } elseif ($testClass instanceof ReflectionClass) {
334
            $suiteMethod = false;
335
 
336
            if (!$testClass->isAbstract() && $testClass->hasMethod(BaseTestRunner::SUITE_METHODNAME)) {
337
                try {
338
                    $method = $testClass->getMethod(
339
                        BaseTestRunner::SUITE_METHODNAME
340
                    );
341
                    // @codeCoverageIgnoreStart
342
                } catch (ReflectionException $e) {
343
                    throw new Exception(
344
                        $e->getMessage(),
345
                        $e->getCode(),
346
                        $e
347
                    );
348
                }
349
                // @codeCoverageIgnoreEnd
350
 
351
                if ($method->isStatic()) {
352
                    $this->addTest(
353
                        $method->invoke(null, $testClass->getName())
354
                    );
355
 
356
                    $suiteMethod = true;
357
                }
358
            }
359
 
360
            if (!$suiteMethod && !$testClass->isAbstract() && $testClass->isSubclassOf(TestCase::class)) {
361
                $this->addTest(new self($testClass));
362
            }
363
        } else {
364
            throw new Exception;
365
        }
366
    }
367
 
368
    public function addWarning(string $warning): void
369
    {
370
        $this->warnings[] = $warning;
371
    }
372
 
373
    /**
374
     * Wraps both <code>addTest()</code> and <code>addTestSuite</code>
375
     * as well as the separate import statements for the user's convenience.
376
     *
377
     * If the named file cannot be read or there are no new tests that can be
378
     * added, a <code>PHPUnit\Framework\WarningTestCase</code> will be created instead,
379
     * leaving the current test run untouched.
380
     *
381
     * @throws Exception
382
     */
383
    public function addTestFile(string $filename): void
384
    {
385
        if (is_file($filename) && substr($filename, -5) === '.phpt') {
386
            $this->addTest(new PhptTestCase($filename));
387
 
388
            $this->declaredClassesPointer = count(get_declared_classes());
389
 
390
            return;
391
        }
392
 
393
        $numTests = count($this->tests);
394
 
395
        // The given file may contain further stub classes in addition to the
396
        // test class itself. Figure out the actual test class.
397
        $filename   = FileLoader::checkAndLoad($filename);
398
        $newClasses = array_slice(get_declared_classes(), $this->declaredClassesPointer);
399
 
400
        // The diff is empty in case a parent class (with test methods) is added
401
        // AFTER a child class that inherited from it. To account for that case,
402
        // accumulate all discovered classes, so the parent class may be found in
403
        // a later invocation.
404
        if (!empty($newClasses)) {
405
            // On the assumption that test classes are defined first in files,
406
            // process discovered classes in approximate LIFO order, so as to
407
            // avoid unnecessary reflection.
408
            $this->foundClasses           = array_merge($newClasses, $this->foundClasses);
409
            $this->declaredClassesPointer = count(get_declared_classes());
410
        }
411
 
412
        // The test class's name must match the filename, either in full, or as
413
        // a PEAR/PSR-0 prefixed short name ('NameSpace_ShortName'), or as a
414
        // PSR-1 local short name ('NameSpace\ShortName'). The comparison must be
415
        // anchored to prevent false-positive matches (e.g., 'OtherShortName').
416
        $shortName      = basename($filename, '.php');
417
        $shortNameRegEx = '/(?:^|_|\\\\)' . preg_quote($shortName, '/') . '$/';
418
 
419
        foreach ($this->foundClasses as $i => $className) {
420
            if (preg_match($shortNameRegEx, $className)) {
421
                try {
422
                    $class = new ReflectionClass($className);
423
                    // @codeCoverageIgnoreStart
424
                } catch (ReflectionException $e) {
425
                    throw new Exception(
426
                        $e->getMessage(),
427
                        $e->getCode(),
428
                        $e
429
                    );
430
                }
431
                // @codeCoverageIgnoreEnd
432
 
433
                if ($class->getFileName() == $filename) {
434
                    $newClasses = [$className];
435
                    unset($this->foundClasses[$i]);
436
 
437
                    break;
438
                }
439
            }
440
        }
441
 
442
        foreach ($newClasses as $className) {
443
            try {
444
                $class = new ReflectionClass($className);
445
                // @codeCoverageIgnoreStart
446
            } catch (ReflectionException $e) {
447
                throw new Exception(
448
                    $e->getMessage(),
449
                    $e->getCode(),
450
                    $e
451
                );
452
            }
453
            // @codeCoverageIgnoreEnd
454
 
455
            if (dirname($class->getFileName()) === __DIR__) {
456
                continue;
457
            }
458
 
459
            if (!$class->isAbstract()) {
460
                if ($class->hasMethod(BaseTestRunner::SUITE_METHODNAME)) {
461
                    try {
462
                        $method = $class->getMethod(
463
                            BaseTestRunner::SUITE_METHODNAME
464
                        );
465
                        // @codeCoverageIgnoreStart
466
                    } catch (ReflectionException $e) {
467
                        throw new Exception(
468
                            $e->getMessage(),
469
                            $e->getCode(),
470
                            $e
471
                        );
472
                    }
473
                    // @codeCoverageIgnoreEnd
474
 
475
                    if ($method->isStatic()) {
476
                        $this->addTest($method->invoke(null, $className));
477
                    }
478
                } elseif ($class->implementsInterface(Test::class)) {
479
                    // Do we have modern namespacing ('Foo\Bar\WhizBangTest') or old-school namespacing ('Foo_Bar_WhizBangTest')?
480
                    $isPsr0            = (!$class->inNamespace()) && (strpos($class->getName(), '_') !== false);
481
                    $expectedClassName = $isPsr0 ? $className : $shortName;
482
 
483
                    if (($pos = strpos($expectedClassName, '.')) !== false) {
484
                        $expectedClassName = substr(
485
                            $expectedClassName,
486
                            0,
487
                            $pos
488
                        );
489
                    }
490
 
491
                    if ($class->getShortName() !== $expectedClassName) {
492
                        $this->addWarning(
493
                            sprintf(
494
                                "Test case class not matching filename is deprecated\n               in %s\n               Class name was '%s', expected '%s'",
495
                                $filename,
496
                                $class->getShortName(),
497
                                $expectedClassName
498
                            )
499
                        );
500
                    }
501
 
502
                    $this->addTestSuite($class);
503
                }
504
            }
505
        }
506
 
507
        if (count($this->tests) > ++$numTests) {
508
            $this->addWarning(
509
                sprintf(
510
                    "Multiple test case classes per file is deprecated\n               in %s",
511
                    $filename
512
                )
513
            );
514
        }
515
 
516
        $this->numTests = -1;
517
    }
518
 
519
    /**
520
     * Wrapper for addTestFile() that adds multiple test files.
521
     *
522
     * @throws Exception
523
     */
524
    public function addTestFiles(iterable $fileNames): void
525
    {
526
        foreach ($fileNames as $filename) {
527
            $this->addTestFile((string) $filename);
528
        }
529
    }
530
 
531
    /**
532
     * Counts the number of test cases that will be run by this test.
533
     *
534
     * @todo refactor usage of numTests in DefaultResultPrinter
535
     */
536
    public function count(): int
537
    {
538
        $this->numTests = 0;
539
 
540
        foreach ($this as $test) {
541
            $this->numTests += count($test);
542
        }
543
 
544
        return $this->numTests;
545
    }
546
 
547
    /**
548
     * Returns the name of the suite.
549
     */
550
    public function getName(): string
551
    {
552
        return $this->name;
553
    }
554
 
555
    /**
556
     * Returns the test groups of the suite.
557
     *
558
     * @psalm-return list<string>
559
     */
560
    public function getGroups(): array
561
    {
562
        return array_map(
563
            static function ($key): string
564
            {
565
                return (string) $key;
566
            },
567
            array_keys($this->groups)
568
        );
569
    }
570
 
571
    public function getGroupDetails(): array
572
    {
573
        return $this->groups;
574
    }
575
 
576
    /**
577
     * Set tests groups of the test case.
578
     */
579
    public function setGroupDetails(array $groups): void
580
    {
581
        $this->groups = $groups;
582
    }
583
 
584
    /**
585
     * Runs the tests and collects their result in a TestResult.
586
     *
587
     * @throws \PHPUnit\Framework\CodeCoverageException
588
     * @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException
589
     * @throws \SebastianBergmann\CodeCoverage\UnintentionallyCoveredCodeException
590
     * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
591
     * @throws Warning
592
     */
593
    public function run(TestResult $result = null): TestResult
594
    {
595
        if ($result === null) {
596
            $result = $this->createResult();
597
        }
598
 
599
        if (count($this) === 0) {
600
            return $result;
601
        }
602
 
603
        /** @psalm-var class-string $className */
604
        $className   = $this->name;
605
        $hookMethods = TestUtil::getHookMethods($className);
606
 
607
        $result->startTestSuite($this);
608
 
609
        $test = null;
610
 
611
        if ($this->testCase && class_exists($this->name, false)) {
612
            try {
613
                foreach ($hookMethods['beforeClass'] as $beforeClassMethod) {
614
                    if (method_exists($this->name, $beforeClassMethod)) {
615
                        if ($missingRequirements = TestUtil::getMissingRequirements($this->name, $beforeClassMethod)) {
616
                            $this->markTestSuiteSkipped(implode(PHP_EOL, $missingRequirements));
617
                        }
618
 
619
                        call_user_func([$this->name, $beforeClassMethod]);
620
                    }
621
                }
622
            } catch (SkippedTestSuiteError $error) {
623
                foreach ($this->tests() as $test) {
624
                    $result->startTest($test);
625
                    $result->addFailure($test, $error, 0);
626
                    $result->endTest($test, 0);
627
                }
628
 
629
                $result->endTestSuite($this);
630
 
631
                return $result;
632
            } catch (Throwable $t) {
633
                $errorAdded = false;
634
 
635
                foreach ($this->tests() as $test) {
636
                    if ($result->shouldStop()) {
637
                        break;
638
                    }
639
 
640
                    $result->startTest($test);
641
 
642
                    if (!$errorAdded) {
643
                        $result->addError($test, $t, 0);
644
 
645
                        $errorAdded = true;
646
                    } else {
647
                        $result->addFailure(
648
                            $test,
649
                            new SkippedTestError('Test skipped because of an error in hook method'),
650
 
651
                        );
652
                    }
653
 
654
                    $result->endTest($test, 0);
655
                }
656
 
657
                $result->endTestSuite($this);
658
 
659
                return $result;
660
            }
661
        }
662
 
663
        foreach ($this as $test) {
664
            if ($result->shouldStop()) {
665
                break;
666
            }
667
 
668
            if ($test instanceof TestCase || $test instanceof self) {
669
                $test->setBeStrictAboutChangesToGlobalState($this->beStrictAboutChangesToGlobalState);
670
                $test->setBackupGlobals($this->backupGlobals);
671
                $test->setBackupStaticAttributes($this->backupStaticAttributes);
672
                $test->setRunTestInSeparateProcess($this->runTestInSeparateProcess);
673
            }
674
 
675
            $test->run($result);
676
        }
677
 
678
        if ($this->testCase && class_exists($this->name, false)) {
679
            foreach ($hookMethods['afterClass'] as $afterClassMethod) {
680
                if (method_exists($this->name, $afterClassMethod)) {
681
                    try {
682
                        call_user_func([$this->name, $afterClassMethod]);
683
                    } catch (Throwable $t) {
684
                        $message = "Exception in {$this->name}::{$afterClassMethod}" . PHP_EOL . $t->getMessage();
685
                        $error   = new SyntheticError($message, 0, $t->getFile(), $t->getLine(), $t->getTrace());
686
 
687
                        $placeholderTest = clone $test;
688
                        $placeholderTest->setName($afterClassMethod);
689
 
690
                        $result->startTest($placeholderTest);
691
                        $result->addFailure($placeholderTest, $error, 0);
692
                        $result->endTest($placeholderTest, 0);
693
                    }
694
                }
695
            }
696
        }
697
 
698
        $result->endTestSuite($this);
699
 
700
        return $result;
701
    }
702
 
703
    public function setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void
704
    {
705
        $this->runTestInSeparateProcess = $runTestInSeparateProcess;
706
    }
707
 
708
    public function setName(string $name): void
709
    {
710
        $this->name = $name;
711
    }
712
 
713
    /**
714
     * Returns the tests as an enumeration.
715
     *
716
     * @return Test[]
717
     */
718
    public function tests(): array
719
    {
720
        return $this->tests;
721
    }
722
 
723
    /**
724
     * Set tests of the test suite.
725
     *
726
     * @param Test[] $tests
727
     */
728
    public function setTests(array $tests): void
729
    {
730
        $this->tests = $tests;
731
    }
732
 
733
    /**
734
     * Mark the test suite as skipped.
735
     *
736
     * @param string $message
737
     *
738
     * @throws SkippedTestSuiteError
739
     *
740
     * @psalm-return never-return
741
     */
742
    public function markTestSuiteSkipped($message = ''): void
743
    {
744
        throw new SkippedTestSuiteError($message);
745
    }
746
 
747
    /**
748
     * @param bool $beStrictAboutChangesToGlobalState
749
     */
750
    public function setBeStrictAboutChangesToGlobalState($beStrictAboutChangesToGlobalState): void
751
    {
752
        if (null === $this->beStrictAboutChangesToGlobalState && is_bool($beStrictAboutChangesToGlobalState)) {
753
            $this->beStrictAboutChangesToGlobalState = $beStrictAboutChangesToGlobalState;
754
        }
755
    }
756
 
757
    /**
758
     * @param bool $backupGlobals
759
     */
760
    public function setBackupGlobals($backupGlobals): void
761
    {
762
        if (null === $this->backupGlobals && is_bool($backupGlobals)) {
763
            $this->backupGlobals = $backupGlobals;
764
        }
765
    }
766
 
767
    /**
768
     * @param bool $backupStaticAttributes
769
     */
770
    public function setBackupStaticAttributes($backupStaticAttributes): void
771
    {
772
        if (null === $this->backupStaticAttributes && is_bool($backupStaticAttributes)) {
773
            $this->backupStaticAttributes = $backupStaticAttributes;
774
        }
775
    }
776
 
777
    /**
778
     * Returns an iterator for this test suite.
779
     */
780
    public function getIterator(): Iterator
781
    {
782
        $iterator = new TestSuiteIterator($this);
783
 
784
        if ($this->iteratorFilter !== null) {
785
            $iterator = $this->iteratorFilter->factory($iterator, $this);
786
        }
787
 
788
        return $iterator;
789
    }
790
 
791
    public function injectFilter(Factory $filter): void
792
    {
793
        $this->iteratorFilter = $filter;
794
 
795
        foreach ($this as $test) {
796
            if ($test instanceof self) {
797
                $test->injectFilter($filter);
798
            }
799
        }
800
    }
801
 
802
    /**
803
     * @psalm-return array<int,string>
804
     */
805
    public function warnings(): array
806
    {
807
        return array_unique($this->warnings);
808
    }
809
 
810
    /**
811
     * @return list<ExecutionOrderDependency>
812
     */
813
    public function provides(): array
814
    {
815
        if ($this->providedTests === null) {
816
            $this->providedTests = [];
817
 
818
            if (is_callable($this->sortId(), true)) {
819
                $this->providedTests[] = new ExecutionOrderDependency($this->sortId());
820
            }
821
 
822
            foreach ($this->tests as $test) {
823
                if (!($test instanceof Reorderable)) {
824
                    // @codeCoverageIgnoreStart
825
                    continue;
826
                    // @codeCoverageIgnoreEnd
827
                }
828
                $this->providedTests = ExecutionOrderDependency::mergeUnique($this->providedTests, $test->provides());
829
            }
830
        }
831
 
832
        return $this->providedTests;
833
    }
834
 
835
    /**
836
     * @return list<ExecutionOrderDependency>
837
     */
838
    public function requires(): array
839
    {
840
        if ($this->requiredTests === null) {
841
            $this->requiredTests = [];
842
 
843
            foreach ($this->tests as $test) {
844
                if (!($test instanceof Reorderable)) {
845
                    // @codeCoverageIgnoreStart
846
                    continue;
847
                    // @codeCoverageIgnoreEnd
848
                }
849
                $this->requiredTests = ExecutionOrderDependency::mergeUnique(
850
                    ExecutionOrderDependency::filterInvalid($this->requiredTests),
851
                    $test->requires()
852
                );
853
            }
854
 
855
            $this->requiredTests = ExecutionOrderDependency::diff($this->requiredTests, $this->provides());
856
        }
857
 
858
        return $this->requiredTests;
859
    }
860
 
861
    public function sortId(): string
862
    {
863
        return $this->getName() . '::class';
864
    }
865
 
866
    /**
867
     * Creates a default TestResult object.
868
     */
869
    protected function createResult(): TestResult
870
    {
871
        return new TestResult;
872
    }
873
 
874
    /**
875
     * @throws Exception
876
     */
877
    protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method): void
878
    {
879
        $methodName = $method->getName();
880
 
881
        $test = (new TestBuilder)->build($class, $methodName);
882
 
883
        if ($test instanceof TestCase || $test instanceof DataProviderTestSuite) {
884
            $test->setDependencies(
885
                TestUtil::getDependencies($class->getName(), $methodName)
886
            );
887
        }
888
 
889
        $this->addTest(
890
            $test,
891
            TestUtil::getGroups($class->getName(), $methodName)
892
        );
893
    }
894
 
895
    private function clearCaches(): void
896
    {
897
        $this->numTests      = -1;
898
        $this->providedTests = null;
899
        $this->requiredTests = null;
900
    }
901
 
902
    private function containsOnlyVirtualGroups(array $groups): bool
903
    {
904
        foreach ($groups as $group) {
905
            if (strpos($group, '__phpunit_') !== 0) {
906
                return false;
907
            }
908
        }
909
 
910
        return true;
911
    }
912
}