Last active
August 29, 2015 14:18
-
-
Save cbrunnkvist/b5508cd962acc206193b to your computer and use it in GitHub Desktop.
Try to keep PHP/Symfony/Doctrine functional tests memory usage from exploding #uphillbattle
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 MVMS\ApiBundle\Tests; | |
trait ReflectsAndCleansPropertiesAfterTestTrait | |
{ | |
/** @after */ | |
public function cleanUpTestAndContainerProperties() | |
{ | |
if (($container = $this->getContainer()) != null) { | |
$refl = new \ReflectionObject($container); | |
foreach ($refl->getProperties() as $prop) { | |
$prop->setAccessible(true); | |
$prop->setValue($container, null); | |
} | |
} | |
$refl = new \ReflectionObject($this); | |
foreach ($refl->getProperties() as $prop) { | |
if (!$prop->isStatic()) { | |
$prop->setAccessible(true); | |
$prop->setValue($this, null); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment