Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cbrunnkvist/b5508cd962acc206193b to your computer and use it in GitHub Desktop.
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
<?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