Skip to content

Instantly share code, notes, and snippets.

@digitalkaoz
Created November 24, 2012 14:03
Show Gist options
  • Save digitalkaoz/4139811 to your computer and use it in GitHub Desktop.
Save digitalkaoz/4139811 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