Skip to content

Instantly share code, notes, and snippets.

@Aliance
Created October 29, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aliance/46a4611e6352eea661130c37a17193ee to your computer and use it in GitHub Desktop.
Save Aliance/46a4611e6352eea661130c37a17193ee to your computer and use it in GitHub Desktop.
Automatically unset all properties with PHPUnit.
<?php
use PHPUnit\Framework\TestCase;
/**
* Base class for all unit tests.
*/
abstract class UnitTestCase extends TestCase
{
/**
* @inheritdoc
*/
protected function tearDown()
{
$reflection = new \ReflectionObject($this);
foreach ($reflection->getProperties() as $property) {
if ($property->isStatic()) {
continue;
}
if (strpos($property->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
$property->setAccessible(true);
$property->setValue($this, null);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment