1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | /** |
||||
6 | * @package phpunit-garbage-collector |
||||
7 | * @version 1.0.0 |
||||
8 | * @author John Rayes <[email protected]> |
||||
9 | * @copyright Copyright (c) 2022, John Rayes |
||||
10 | * @license http://opensource.org/licenses/MIT MIT |
||||
11 | */ |
||||
12 | |||||
13 | namespace live627\PHPUnitGarbageCollector; |
||||
14 | |||||
15 | use PHPUnit\Framework\Test; |
||||
16 | use PHPUnit\Framework\TestListener; |
||||
17 | use PHPUnit\Framework\TestListenerDefaultImplementation; |
||||
18 | use ReflectionObject; |
||||
19 | |||||
20 | class MemoryGuard implements TestListener |
||||
0 ignored issues
–
show
|
|||||
21 | { |
||||
22 | use TestListenerDefaultImplementation; |
||||
0 ignored issues
–
show
The trait
PHPUnit\Framework\TestLi...erDefaultImplementation has been deprecated: The `TestListener` interface is deprecated
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This trait has been deprecated. The supplier of the trait has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the trait will be removed and what other trait to use instead. ![]() |
|||||
23 | |||||
24 | private IgnoreTestPolicy $ignorePolicy; |
||||
25 | |||||
26 | 2 | public function __construct(IgnoreTestPolicy $ignorePolicy = null) |
|||
27 | { |
||||
28 | 2 | $this->ignorePolicy = $ignorePolicy ?: new NeverIgnoreTestPolicy; |
|||
29 | } |
||||
30 | |||||
31 | 2 | public function endTest(Test $test, float $time): void |
|||
32 | { |
||||
33 | 2 | $testReflection = new ReflectionObject($test); |
|||
34 | |||||
35 | 2 | if ($this->ignorePolicy->shouldIgnore($testReflection)) |
|||
36 | 1 | return; |
|||
37 | |||||
38 | 1 | foreach ($testReflection->getProperties() as $prop) |
|||
39 | { |
||||
40 | 1 | if ($prop->isStatic() || strpos($prop->getDeclaringClass()->getName(), 'PHPUnit\\') === 0) |
|||
41 | 1 | continue; |
|||
42 | |||||
43 | 1 | unset($test->{$prop->getName()}); |
|||
44 | } |
||||
45 | } |
||||
46 | } |
||||
47 | |||||
48 | class NeverIgnoreTestPolicy implements IgnoreTestPolicy |
||||
49 | { |
||||
50 | 1 | public function shouldIgnore(ReflectionObject $testReflection): bool |
|||
51 | { |
||||
52 | 1 | return false; |
|||
53 | } |
||||
54 | } |
||||
55 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.