Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Created October 21, 2021 04:16
Show Gist options
  • Save DarkGhostHunter/1a17f38e51de37147c6e11b9d8776f1f to your computer and use it in GitHub Desktop.
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
<?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