diff --git a/src/PropertyGarbageCollection.php b/src/PropertyGarbageCollection.php new file mode 100644 index 0000000..189fc59 --- /dev/null +++ b/src/PropertyGarbageCollection.php @@ -0,0 +1,46 @@ +getProperties() as $property) { + if ($property->isStatic() || \str_starts_with($property->getDeclaringClass()->getName(), 'PHPUnit\\')) { + continue; + } + + unset($this->{$property->getName()}); // @phpstan-ignore-line + } + + while (($parent = $reflection->getParentClass()) !== false) { + if (\str_starts_with($parent->getName(), 'PHPUnit\\')) { + break; + } + + foreach ($parent->getProperties() as $property) { + if ($property->isStatic() || \str_starts_with($property->getDeclaringClass()->getName(), 'PHPUnit\\')) { + continue; + } + + (function () use ($property): void { + unset($this->{$property->getName()}); // @phpstan-ignore-line + })->bindTo($this, $parent->getName())->call($this); + } + } + + \gc_collect_cycles(); + } +} diff --git a/src/TestCase.php b/src/TestCase.php index 2dd26f8..570c696 100644 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -9,4 +9,5 @@ abstract class TestCase extends PHPUnitTestCase { use StrictMocking; + use PropertyGarbageCollection; }