Speedup tests

This commit is contained in:
William Durand 2015-10-23 10:07:45 +02:00
parent e66fb209b5
commit 4b72190f4d
No known key found for this signature in database
GPG Key ID: A509BCF1C1274F3B
3 changed files with 21 additions and 30 deletions

View File

@ -73,10 +73,8 @@ class CachingApiDocExtractor extends ApiDocExtractor
{ {
$cache = $this->getViewCache($view); $cache = $this->getViewCache($view);
if ($cache->isFresh() === false) { if (!$cache->isFresh()) {
$resources = array(); $resources = array();
foreach ($this->getRoutes() as $route) { foreach ($this->getRoutes() as $route) {
if ( null !== ($method = $this->getReflectionMethod($route->getDefault('_controller'))) if ( null !== ($method = $this->getReflectionMethod($route->getDefault('_controller')))
&& null !== ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS))) { && null !== ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS))) {
@ -94,8 +92,14 @@ class CachingApiDocExtractor extends ApiDocExtractor
return $data; return $data;
} }
return unserialize(file_get_contents($cache)); // For BC
if (method_exists($cache, 'getPath')) {
$cachePath = $cache->getPath();
} else {
$cachePath = (string) $cache;
}
return unserialize(file_get_contents($cachePath));
} }
/** /**

View File

@ -67,8 +67,6 @@ class CachingApiDocExtractorTest extends WebTestCase
$expectedViewCacheFile = $cacheFile.'.'.$view; $expectedViewCacheFile = $cacheFile.'.'.$view;
$this->assertFileNotExists($expectedViewCacheFile);
set_error_handler(array($this, 'handleDeprecation')); set_error_handler(array($this, 'handleDeprecation'));
$data = $extractor->all($view); $data = $extractor->all($view);

View File

@ -17,10 +17,10 @@ use Symfony\Component\HttpKernel\Kernel;
abstract class WebTestCase extends BaseWebTestCase abstract class WebTestCase extends BaseWebTestCase
{ {
public static $container;
protected function setUp() protected function setUp()
{ {
$this->deleteTmpDir();
parent::setUp(); parent::setUp();
if (version_compare(Kernel::VERSION, '2.2.0', '<')) { if (version_compare(Kernel::VERSION, '2.2.0', '<')) {
@ -28,16 +28,6 @@ abstract class WebTestCase extends BaseWebTestCase
} }
} }
protected function deleteTmpDir()
{
if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION)) {
return;
}
$fs = new Filesystem();
$fs->remove($dir);
}
public static function handleDeprecation($errorNumber, $message, $file, $line, $context) public static function handleDeprecation($errorNumber, $message, $file, $line, $context)
{ {
if ($errorNumber & E_USER_DEPRECATED) { if ($errorNumber & E_USER_DEPRECATED) {
@ -49,12 +39,17 @@ abstract class WebTestCase extends BaseWebTestCase
protected function getContainer(array $options = array()) protected function getContainer(array $options = array())
{ {
if (!static::$container) {
if (!static::$kernel) { if (!static::$kernel) {
static::$kernel = static::createKernel($options); static::$kernel = static::createKernel($options);
} }
static::$kernel->boot(); static::$kernel->boot();
return static::$kernel->getContainer(); static::$container = static::$kernel->getContainer();
}
return static::$container;
} }
protected static function getKernelClass() protected static function getKernelClass()
@ -73,10 +68,4 @@ abstract class WebTestCase extends BaseWebTestCase
isset($options['debug']) ? $options['debug'] : true isset($options['debug']) ? $options['debug'] : true
); );
} }
public function tearDown()
{
parent::tearDown();
$this->deleteTmpDir();
}
} }