Created
October 29, 2017 19:34
-
-
Save Aliance/46a4611e6352eea661130c37a17193ee to your computer and use it in GitHub Desktop.
Automatically unset all properties with PHPUnit.
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 | |
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