Skip to content

Instantly share code, notes, and snippets.

@edorian
Forked from digitalkaoz/BaseTestCase.php
Created November 25, 2012 13:57
Show Gist options
  • Save edorian/4143622 to your computer and use it in GitHub Desktop.
Save edorian/4143622 to your computer and use it in GitHub Desktop.
PHPUnit Cache Clear beforeClass
<?php
namespace Lingwa\Bundle\CoreBundle\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
abstract class BaseTestCase extends WebTestCase
{
static $cleared = false;
public static function setupBeforeClass()
{
$class = get_called_class();
if (strpos($class, '\\Controller\\') && !self::$cleared) {
require_once SF_ROOT.'/app/AppKernel.php';
$interpreter = PHP_OS == 'WINNT' ? 'php.exe' : 'php';
@passthru(sprintf('%s app/console cache:clear --env=test --no-debug', $interpreter));
self::$cleared = true;
}
}
protected function tearDown()
{
$refl = new \ReflectionObject($this);
foreach ($refl->getProperties() as $prop) {
if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
$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