From 4b72190f4d89454cb489a1c05a1681f0aeebe675 Mon Sep 17 00:00:00 2001 From: William Durand Date: Fri, 23 Oct 2015 10:07:45 +0200 Subject: [PATCH] Speedup tests --- Extractor/CachingApiDocExtractor.php | 14 +++++--- .../Extractor/CachingApiDocExtractorTest.php | 2 -- Tests/WebTestCase.php | 35 +++++++------------ 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Extractor/CachingApiDocExtractor.php b/Extractor/CachingApiDocExtractor.php index 997fa48..b3ff882 100644 --- a/Extractor/CachingApiDocExtractor.php +++ b/Extractor/CachingApiDocExtractor.php @@ -73,14 +73,12 @@ class CachingApiDocExtractor extends ApiDocExtractor { $cache = $this->getViewCache($view); - if ($cache->isFresh() === false) { - + if (!$cache->isFresh()) { $resources = array(); - foreach ($this->getRoutes() as $route) { if ( null !== ($method = $this->getReflectionMethod($route->getDefault('_controller'))) && null !== ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS))) { - $file = $method->getDeclaringClass()->getFileName(); + $file = $method->getDeclaringClass()->getFileName(); $resources[] = new FileResource($file); } } @@ -94,8 +92,14 @@ class CachingApiDocExtractor extends ApiDocExtractor 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)); } /** diff --git a/Tests/Extractor/CachingApiDocExtractorTest.php b/Tests/Extractor/CachingApiDocExtractorTest.php index 36892b8..8303121 100644 --- a/Tests/Extractor/CachingApiDocExtractorTest.php +++ b/Tests/Extractor/CachingApiDocExtractorTest.php @@ -67,8 +67,6 @@ class CachingApiDocExtractorTest extends WebTestCase $expectedViewCacheFile = $cacheFile.'.'.$view; - $this->assertFileNotExists($expectedViewCacheFile); - set_error_handler(array($this, 'handleDeprecation')); $data = $extractor->all($view); diff --git a/Tests/WebTestCase.php b/Tests/WebTestCase.php index f986df9..53f3826 100644 --- a/Tests/WebTestCase.php +++ b/Tests/WebTestCase.php @@ -17,10 +17,10 @@ use Symfony\Component\HttpKernel\Kernel; abstract class WebTestCase extends BaseWebTestCase { + public static $container; + protected function setUp() { - $this->deleteTmpDir(); - parent::setUp(); 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) { if ($errorNumber & E_USER_DEPRECATED) { @@ -49,12 +39,17 @@ abstract class WebTestCase extends BaseWebTestCase protected function getContainer(array $options = array()) { - if (!static::$kernel) { - static::$kernel = static::createKernel($options); - } - static::$kernel->boot(); + if (!static::$container) { + if (!static::$kernel) { + static::$kernel = static::createKernel($options); + } - return static::$kernel->getContainer(); + static::$kernel->boot(); + + static::$container = static::$kernel->getContainer(); + } + + return static::$container; } protected static function getKernelClass() @@ -73,10 +68,4 @@ abstract class WebTestCase extends BaseWebTestCase isset($options['debug']) ? $options['debug'] : true ); } - - public function tearDown() - { - parent::tearDown(); - $this->deleteTmpDir(); - } }