Created
October 21, 2021 04:16
-
-
Save DarkGhostHunter/1a17f38e51de37147c6e11b9d8776f1f to your computer and use it in GitHub Desktop.
Removes any user property for garbage collection at the end of each test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
trait ClearProperties | |
{ | |
/** | |
* Unset each property declared in this test class and its traits. | |
* | |
* @return void | |
*/ | |
protected function clearProperties(): void | |
{ | |
foreach ((new \ReflectionObject($this))->getProperties() as $property) { | |
if (!$property->isStatic() && __CLASS__ === $property->getDeclaringClass()->getName()) { | |
unset($this->{$property->getName()}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment