diff --git a/bin/phpdoc b/bin/phpdoc index 619595a54f..8ac607f722 100755 --- a/bin/phpdoc +++ b/bin/phpdoc @@ -1,6 +1,7 @@ #!/usr/bin/env php load(__DIR__.'/../.env'); } diff --git a/composer.json b/composer.json index 5f286d1019..37d65c547c 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "phpdocumentor/type-resolver": "^0.7.1", "psr/cache": "^1.0", "psr/log": "^1.1", + "symfony/cache": "5.0.*", "symfony/config": "5.0.*", "symfony/console": "^5.0", "symfony/dependency-injection": "5.0.*", @@ -58,7 +59,6 @@ "symfony/routing": "5.0.*", "symfony/stopwatch": "^5.0", "symfony/yaml": "^5.0", - "tedivm/stash": "^0.14.2", "twig/twig": "~2.0", "webmozart/assert": "^1.3", "zendframework/zend-serializer": "~2.1", diff --git a/composer.lock b/composer.lock index 718679edd2..1a18a47080 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "99083227dbe6a3e70f8b928d1c537756", + "content-hash": "5de05da43eada1c89aae88690745dc06", "packages": [ { "name": "composer/ca-bundle", @@ -2955,66 +2955,6 @@ "homepage": "https://symfony.com", "time": "2019-11-18T17:27:11+00:00" }, - { - "name": "tedivm/stash", - "version": "v0.14.2", - "source": { - "type": "git", - "url": "https://github.com/tedious/Stash.git", - "reference": "7ea9749784152dcd2dab72c4bbf2bef18c326e41" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/tedious/Stash/zipball/7ea9749784152dcd2dab72c4bbf2bef18c326e41", - "reference": "7ea9749784152dcd2dab72c4bbf2bef18c326e41", - "shasum": "" - }, - "require": { - "php": "^5.4|^7.0", - "psr/cache": "~1.0" - }, - "provide": { - "psr/cache-implementation": "1.0.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^1.9", - "phpunit/phpunit": "4.8.*", - "satooshi/php-coveralls": "1.0.*" - }, - "type": "library", - "autoload": { - "psr-4": { - "Stash\\": "src/Stash/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Robert Hafner", - "email": "tedivm@tedivm.com" - }, - { - "name": "Josh Hall-Bachner", - "email": "charlequin@gmail.com" - } - ], - "description": "The place to keep your cache.", - "homepage": "http://github.com/tedious/Stash", - "keywords": [ - "apc", - "cache", - "caching", - "memcached", - "psr-6", - "psr6", - "redis", - "sessions" - ], - "time": "2017-04-23T17:16:57+00:00" - }, { "name": "twig/twig", "version": "v2.12.2", diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index a31bc82c6a..c45bccb3b5 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -7,3 +7,13 @@ framework: php_errors: log: true + + cache: + app: cache.adapter.filesystem + system: cache.adapter.filesystem + + pools: + files: + adapter: cache.adapter.filesystem + descriptors: + adapter: cache.adapter.filesystem diff --git a/config/packages/prod/monolog.yaml b/config/packages/prod/monolog.yaml index 7eabb31696..95ac79469c 100644 --- a/config/packages/prod/monolog.yaml +++ b/config/packages/prod/monolog.yaml @@ -9,5 +9,7 @@ monolog: process_psr_3_messages: false channels: ["!event", "!doctrine"] verbosity_levels: - VERBOSITY_NORMAL: INFO - VERBOSITY_VERBOSE: INFO + VERBOSITY_NORMAL: ERROR + VERBOSITY_VERBOSE: NOTICE + VERBOSITY_VERY_VERBOSE: INFO + VERBOSITY_DEBUG: DEBUG diff --git a/config/services.yaml b/config/services.yaml index 802007fd5b..c98f1af22d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -213,26 +213,24 @@ services: phpDocumentor\Parser\Middleware\StopwatchMiddleware: tags: [ { name: 'phpdoc.parser.middleware', priority: 5000 } ] + # Increments the progress bar; by placing it in front of the cache you see the progress bar + # increment, even while we only consume the cache + phpDocumentor\Parser\Middleware\EmittingMiddleware: + tags: [ { name: 'phpdoc.parser.middleware', priority: 4500 } ] + phpDocumentor\Parser\Middleware\CacheMiddleware: - arguments: - $dataStore: '@Stash\Pool' tags: [ { name: 'phpdoc.parser.middleware', priority: 4000 } ] phpDocumentor\Parser\Middleware\ErrorHandlingMiddleware: tags: [ { name: 'phpdoc.parser.middleware', priority: 3000 } ] - phpDocumentor\Parser\Middleware\EmittingMiddleware: - tags: [ { name: 'phpdoc.parser.middleware', priority: 0 } ] - ################################################################################### ## Autoloading definitions for external services ################################## ################################################################################### - Psr\Cache\CacheItemPoolInterface: '@Stash\Pool' - - Stash\Interfaces\PoolInterface: '@Stash\Pool' - - Stash\Pool: ~ + phpDocumentor\Descriptor\Cache\ProjectDescriptorMapper: + arguments: + $descriptors: '@descriptors' League\Flysystem\MountManager: ~ diff --git a/config/stages.yaml b/config/stages.yaml index 33c2a46615..d480678ead 100644 --- a/config/stages.yaml +++ b/config/stages.yaml @@ -19,9 +19,9 @@ services: ## Autoloading definitions for cache stages ################################# ################################################################################### - phpDocumentor\Application\Stage\Cache\ConfigureCache: + phpDocumentor\Application\Stage\Cache\PurgeCachesWhenForced: tags: - - { name: 'phpdoc.pipeline.application.cache', priority: 10000 } + - { name: 'phpdoc.pipeline.application.configuration', priority: 7000 } phpDocumentor\Application\Stage\Cache\LoadProjectDescriptorFromCache: tags: diff --git a/src/phpDocumentor/Application.php b/src/phpDocumentor/Application.php index dc73145a98..1e548ad2ff 100644 --- a/src/phpDocumentor/Application.php +++ b/src/phpDocumentor/Application.php @@ -52,16 +52,9 @@ public static function templateDirectory(): string /** * Initializes all components used by phpDocumentor. */ - public function __construct(LoggerInterface $logger) + public function __construct() { $this->defineIniSettings(); - - Dispatcher::getInstance()->addListener( - 'parser.file.pre', - function (PreFileEvent $event) use ($logger) { - $logger->log(LogLevel::NOTICE, 'Parsing ' . $event->getFile()); - } - ); } /** diff --git a/src/phpDocumentor/Application/Stage/Cache/ConfigureCache.php b/src/phpDocumentor/Application/Stage/Cache/ConfigureCache.php deleted file mode 100644 index d5a3400e39..0000000000 --- a/src/phpDocumentor/Application/Stage/Cache/ConfigureCache.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ - -namespace phpDocumentor\Application\Stage\Cache; - -use phpDocumentor\Application\Stage\Payload; -use RuntimeException; -use Stash\Driver\FileSystem; -use Stash\Pool; - -final class ConfigureCache -{ - private $cache; - - public function __construct(Pool $cache) - { - $this->cache = $cache; - } - - /** - * Executes the business logic involved with this command. - * - * @throws RuntimeException if the target location is not a folder. - */ - public function __invoke(Payload $payload): Payload - { - $configuration = $payload->getConfig(); - $target = (string) $configuration['phpdocumentor']['paths']['cache']; - $this->cache->setDriver(new FileSystem(['path' => $target])); - - return $payload; - } -} diff --git a/src/phpDocumentor/Application/Stage/Cache/PurgeCachesWhenForced.php b/src/phpDocumentor/Application/Stage/Cache/PurgeCachesWhenForced.php new file mode 100644 index 0000000000..2b46b47185 --- /dev/null +++ b/src/phpDocumentor/Application/Stage/Cache/PurgeCachesWhenForced.php @@ -0,0 +1,50 @@ + + * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Application\Stage\Cache; + +use phpDocumentor\Application\Stage\Payload; +use Psr\Log\LoggerInterface; +use Symfony\Component\Cache\Adapter\AdapterInterface; + +final class PurgeCachesWhenForced +{ + private $filesCache; + private $descriptorsCache; + private $logger; + + public function __construct( + AdapterInterface $filesCache, + AdapterInterface $descriptorsCache, + LoggerInterface $logger + ) { + $this->filesCache = $filesCache; + $this->descriptorsCache = $descriptorsCache; + $this->logger = $logger; + } + + public function __invoke(Payload $payload) + { + $this->logger->info('Checking whether to purge cache'); + if (! $payload->getConfig()['phpdocumentor']['use-cache']) { + $this->logger->info('Purging cache'); + $this->filesCache->clear(); + $this->descriptorsCache->clear(); + } + + return $payload; + } +} diff --git a/src/phpDocumentor/Application/Stage/Parser/ParseFiles.php b/src/phpDocumentor/Application/Stage/Parser/ParseFiles.php index 2782780f6d..10a7bb4bc9 100644 --- a/src/phpDocumentor/Application/Stage/Parser/ParseFiles.php +++ b/src/phpDocumentor/Application/Stage/Parser/ParseFiles.php @@ -19,6 +19,7 @@ use phpDocumentor\Parser\Parser; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +use Symfony\Component\Cache\Adapter\AdapterInterface; final class ParseFiles { @@ -30,17 +31,29 @@ final class ParseFiles * @var LoggerInterface */ private $logger; + /** + * @var AdapterInterface + */ + private $filesCache; + /** + * @var AdapterInterface + */ + private $descriptorsCache; - public function __construct(Parser $parser, LoggerInterface $logger) - { + public function __construct( + Parser $parser, + LoggerInterface $logger, + AdapterInterface $filesCache, + AdapterInterface $descriptorsCache + ) { $this->parser = $parser; $this->logger = $logger; + $this->filesCache = $filesCache; + $this->descriptorsCache = $descriptorsCache; } public function __invoke(Payload $payload) { - $configuration = $payload->getConfig(); - /* * For now settings of the first api are used. * We need to change this later, when we accept more different things @@ -52,10 +65,9 @@ public function __invoke(Payload $payload) $builder->setMarkers($apiConfig['markers']); $builder->setIncludeSource($apiConfig['include-source']); - $this->parser->setForced(!$configuration['phpdocumentor']['use-cache']); - if ($builder->getProjectDescriptor()->getSettings()->isModified()) { - $this->parser->setForced(true); + $this->filesCache->clear(); + $this->descriptorsCache->clear(); $this->log( 'One of the project\'s settings have changed, forcing a complete rebuild', LogLevel::NOTICE @@ -78,7 +90,7 @@ public function __invoke(Payload $payload) /** * Dispatches a logging request. * - * @param string $priority The logging priority as declared in the LogLevel PSR-3 class. + * @param string $priority The logging priority as declared in the LogLevel PSR-3 class. * @param string[] $parameters */ private function log(string $message, string $priority = LogLevel::INFO, array $parameters = []): void diff --git a/src/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapper.php b/src/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapper.php index b1386eac32..8859e5d9b4 100644 --- a/src/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapper.php +++ b/src/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapper.php @@ -18,29 +18,28 @@ use phpDocumentor\Descriptor\FileDescriptor; use phpDocumentor\Descriptor\ProjectDescriptor; use phpDocumentor\Reflection\File; -use Psr\Cache\CacheItemPoolInterface; -use Stash\Item; +use Psr\Cache\CacheItemInterface; +use Symfony\Component\Cache\Adapter\AdapterInterface; /** * Maps a projectDescriptor to and from a cache instance. */ final class ProjectDescriptorMapper { - const FILE_PREFIX = 'phpDocumentor/projectDescriptor/files/'; + const FILE_PREFIX = 'phpDocumentor-projectDescriptor-files-'; - const FILE_LIST = 'phpDocumentor/projectDescriptor/filelist'; + const FILE_LIST = 'phpDocumentor-projectDescriptor-filelist'; - const KEY_SETTINGS = 'phpDocumentor/projectDescriptor/settings'; + const KEY_SETTINGS = 'phpDocumentor-projectDescriptor-settings'; - /** @var CacheItemPoolInterface */ private $cache; /** * Initializes this mapper with the given cache instance. */ - public function __construct(CacheItemPoolInterface $cache) + public function __construct(AdapterInterface $descriptors) { - $this->cache = $cache; + $this->cache = $descriptors; } /** @@ -52,7 +51,7 @@ public function populate(ProjectDescriptor $projectDescriptor): void $fileList = $this->cache->getItem(self::FILE_LIST)->get(); if ($fileList !== null) { - /** @var Item $item */ + /** @var CacheItemInterface $item */ foreach ($this->cache->getItems($fileList) as $item) { $file = $item->get(); diff --git a/src/phpDocumentor/Descriptor/Filter/ClassFactory.php b/src/phpDocumentor/Descriptor/Filter/ClassFactory.php index a9d31dfb3f..1b40a170d0 100644 --- a/src/phpDocumentor/Descriptor/Filter/ClassFactory.php +++ b/src/phpDocumentor/Descriptor/Filter/ClassFactory.php @@ -16,8 +16,6 @@ namespace phpDocumentor\Descriptor\Filter; use League\Pipeline\Pipeline; -use League\Pipeline\PipelineInterface; -use Zend\Filter\FilterChain; /** * Retrieves a series of filters to manipulate a specific Descriptor with during building. diff --git a/src/phpDocumentor/Parser/Middleware/CacheMiddleware.php b/src/phpDocumentor/Parser/Middleware/CacheMiddleware.php index 13fb4a3f8a..9d33edfc01 100644 --- a/src/phpDocumentor/Parser/Middleware/CacheMiddleware.php +++ b/src/phpDocumentor/Parser/Middleware/CacheMiddleware.php @@ -19,27 +19,21 @@ use phpDocumentor\Reflection\Middleware\Middleware; use phpDocumentor\Reflection\Php\Factory\File\CreateCommand; use phpDocumentor\Reflection\Php\File; -use Stash\Interfaces\PoolInterface; -use Stash\Item; -use Stash\Pool; +use Psr\Log\LoggerInterface; +use Psr\Log\LogLevel; +use Symfony\Contracts\Cache\CacheInterface; final class CacheMiddleware implements Middleware { - /** - * Cache namespace used for this repository. - */ - const CACHE_NAMESPACE = 'Documentation\\Api\\Php'; - - /** - * Cache pool used to store files. - * - * @var Pool - */ - private $dataStore; + /** @var CacheInterface */ + private $cache; + /** @var LoggerInterface */ + private $logger; - public function __construct(PoolInterface $dataStore) + public function __construct(CacheInterface $files, LoggerInterface $logger) { - $this->dataStore = $dataStore; + $this->cache = $files; + $this->logger = $logger; } /** @@ -50,50 +44,22 @@ public function __construct(PoolInterface $dataStore) * @param callable $next * * @return File + * @throws \Psr\Cache\InvalidArgumentException */ public function execute(Command $command, callable $next) { - $itemName = $this->getItemName($command->getFile()->path()); - $item = $this->dataStore->getItem($itemName); - if ($item->isMiss()) { - return $this->updateCache($command, $next, $item); - } - - /** @var File $cachedFile */ - $cachedFile = $item->get(); - - if ($cachedFile === null) { - return $this->updateCache($command, $next, $item); - } + $itemName = md5($command->getFile()->path()); - if ($cachedFile->getHash() !== $command->getFile()->md5()) { - return $this->updateCache($command, $next, $item); - } + $cacheResponse = $this->cache->get( + $itemName . '-' . $command->getFile()->md5(), + function () use ($next, $command) { + $this->logger->log(LogLevel::NOTICE, 'Parsing ' . $command->getFile()->path()); + $file = $next($command); + return base64_encode(serialize($file)); + } + ); + $cachedFile = unserialize(base64_decode($cacheResponse)); return $cachedFile; } - - /** - * @param callable $next - * @param Item $item - * @return mixed - */ - private function updateCache(CreateCommand $command, callable $next, $item) - { - $file = $next($command); - $item->lock(); - $this->dataStore->save($item->set($file)); - return $file; - } - - /** - * Convert path to ItemName - * - * @param string $path - * @return string - */ - private function getItemName($path) - { - return static::CACHE_NAMESPACE . '\\' . md5($path); - } } diff --git a/src/phpDocumentor/Parser/Parser.php b/src/phpDocumentor/Parser/Parser.php index ddee9209da..8788406e09 100644 --- a/src/phpDocumentor/Parser/Parser.php +++ b/src/phpDocumentor/Parser/Parser.php @@ -87,30 +87,6 @@ public function __construct(ProjectFactory $projectFactory, Stopwatch $stopwatch $this->logger = $logger; } - /** - * Sets whether to force a full parse run of all files. - * - * @param bool $forced Forces a full parse. - * - * @api - */ - public function setForced($forced) - { - $this->force = $forced; - } - - /** - * Returns whether a full rebuild is required. - * - * @api - * - * @return bool - */ - public function isForced() - { - return $this->force; - } - /** * Sets whether to run PHPLint on every file. * diff --git a/symfony.lock b/symfony.lock index d3c33e62a5..171aab92eb 100644 --- a/symfony.lock +++ b/symfony.lock @@ -197,9 +197,6 @@ "symfony/yaml": { "version": "v4.0.3" }, - "tedivm/stash": { - "version": "v0.14.2" - }, "twig/twig": { "version": "v1.35.0" }, diff --git a/tests/features/bootstrap/EnvironmentContext.php b/tests/features/bootstrap/EnvironmentContext.php index c1ca303dcf..bdb68158fd 100644 --- a/tests/features/bootstrap/EnvironmentContext.php +++ b/tests/features/bootstrap/EnvironmentContext.php @@ -51,7 +51,7 @@ public function __construct($workingDir, $pharPath = null) */ public function beforeScenario() : void { - //WE no we have some deprecations in phpdocumentor. Let tests pass while we are refactoring stuff. + // We know we have deprecations in phpDocumentor. Let tests pass while we are refactoring stuff. error_reporting(error_reporting() & ~E_USER_DEPRECATED); if (!is_dir($this->getWorkingDir())) { mkdir($this->getWorkingDir(), 0755, true); diff --git a/tests/unit/phpDocumentor/Application/Stage/Cache/ConfigureCacheTest.php b/tests/unit/phpDocumentor/Application/Stage/Cache/ConfigureCacheTest.php deleted file mode 100644 index 084367bfa7..0000000000 --- a/tests/unit/phpDocumentor/Application/Stage/Cache/ConfigureCacheTest.php +++ /dev/null @@ -1,70 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ - -namespace phpDocumentor\Application\Stage\Cache; - -use \Mockery as m; -use Mockery\Adapter\Phpunit\MockeryTestCase; -use phpDocumentor\Application\Stage\Payload; -use phpDocumentor\Descriptor\ProjectDescriptorBuilder; -use phpDocumentor\Path; -use Stash\Pool; - -class ConfigureCacheTest extends MockeryTestCase -{ - /** - * @dataProvider cacheDirProvider - * @throws \Exception - */ - public function testInvokeWithCachePath($configuredPath) : void - { - $configuration = [ - 'phpdocumentor' => [ - 'paths' => [ - 'cache' => $configuredPath, - ], - ], - ]; - - $cacheStorage = m::mock(Pool::class); - $cacheStorage->shouldReceive('setDriver') - ->with(m::type(\Stash\Driver\FileSystem::class)) - ->once(); - - $stage = new ConfigureCache($cacheStorage); - - $payload = new Payload($configuration, m::mock(ProjectDescriptorBuilder::class)); - - self::assertSame( - $payload, - $stage($payload) - ); - } - - public function cacheDirProvider() : array - { - return [ - [ - '/tmp/cache', - ], - [ - 'cache/relative', - ], - [ - new Path('/tmp/cache'), - ], - [ - new Path('cache/relative'), - ], - ]; - } -} diff --git a/tests/unit/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapperTest.php b/tests/unit/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapperTest.php index a5c3608773..5aafe4bf74 100644 --- a/tests/unit/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapperTest.php +++ b/tests/unit/phpDocumentor/Descriptor/Cache/ProjectDescriptorMapperTest.php @@ -17,6 +17,7 @@ use phpDocumentor\Descriptor\ProjectDescriptor; use Stash\Driver\Ephemeral; use Stash\Pool; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; /** * @coversDefaultClass \phpDocumentor\Descriptor\Cache\ProjectDescriptorMapper @@ -34,7 +35,7 @@ final class ProjectDescriptorMapperTest extends \Mockery\Adapter\Phpunit\Mockery protected function setUp(): void { - $this->cachePool = new Pool(new Ephemeral()); + $this->cachePool = new FilesystemAdapter(); $this->mapper = new ProjectDescriptorMapper($this->cachePool); } diff --git a/tests/unit/phpDocumentor/Parser/Middleware/CacheMiddlewareTest.php b/tests/unit/phpDocumentor/Parser/Middleware/CacheMiddlewareTest.php deleted file mode 100644 index 70da94eb90..0000000000 --- a/tests/unit/phpDocumentor/Parser/Middleware/CacheMiddlewareTest.php +++ /dev/null @@ -1,186 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ - -namespace phpDocumentor\Parser\Middleware; - -use Mockery as m; -use Mockery\Adapter\Phpunit\MockeryTestCase; -use phpDocumentor\Reflection\File as SourceFile; -use phpDocumentor\Reflection\Php\Factory\File\CreateCommand; -use phpDocumentor\Reflection\Php\File; -use phpDocumentor\Reflection\Php\ProjectFactoryStrategies; -use phpDocumentor\Reflection\Php\StrategyContainer; -use Stash\Item; -use Stash\Pool; - -/** - * @coversDefaultClass \phpDocumentor\Parser\Middleware\CacheMiddleware - * @covers :: - * @covers ::__construct - */ -final class CacheMiddlewareTest extends MockeryTestCase -{ - /** - * @covers ::execute - * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand - * @uses \phpDocumentor\Reflection\Php\File - */ - public function testCachedFileIsReturnedWhenValid() : void - { - $commandFile = new SourceFile\LocalFile(__FILE__); - $file = new File($commandFile->md5(), __FILE__); - - $poolMock = m::mock(Pool::class); - $poolMock->shouldReceive('getItem')->andReturnSelf(); - $poolMock->shouldReceive('getItem->isMiss')->andReturn(false); - $poolMock->shouldReceive('getItem->get')->andReturn($file); - $poolMock->shouldReceive('getItem->lock')->never(); - $poolMock->shouldReceive('getItem->set')->never(); - $poolMock->shouldReceive('save')->never(); - - $command = new CreateCommand($commandFile, new ProjectFactoryStrategies([])); - - $fixture = new CacheMiddleware($poolMock); - - $result = $fixture->execute($command, function () { - $this->fail('Parsing should not be done, the cached item should be returned'); - }); - - $this->assertSame($file, $result); - } - - /** - * @covers ::execute - * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand - * @uses \phpDocumentor\Reflection\Php\File - */ - public function testCacheIsUpdatedOnAMiss() : void - { - $file = new File('hash', 'myFile.php'); - $item = new Item(); - $poolMock = m::mock(Pool::class); - $poolMock->shouldReceive('getItem')->andReturnSelf(); - $poolMock->shouldReceive('getItem->isMiss')->andReturn(true); - $poolMock->shouldReceive('getItem->lock')->once(); - $poolMock->shouldReceive('getItem->set')->andReturn($item)->with($file); - $poolMock->shouldReceive('getItem->get')->never(); - $poolMock->shouldReceive('save')->with($item); - - $sourceFile = m::mock(SourceFile::class); - $sourceFile->shouldReceive('path')->andReturn('myFile.php'); - $stategies = m::mock(StrategyContainer::class); - $command = new CreateCommand($sourceFile, $stategies); - $fixture = new CacheMiddleware($poolMock); - - $result = $fixture->execute($command, function () use ($file) { - return $file; - }); - - $this->assertSame($file, $result); - } - - /** - * @covers ::execute - * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand - * @uses \phpDocumentor\Reflection\Php\File - */ - public function testCacheFileIfItIsNotInThePool() : void - { - $freshFile = new File('NewHash', 'myFile.php'); - - $item = new Item(); - $poolMock = m::mock(Pool::class); - $poolMock->shouldReceive('getItem') - ->andReturnSelf(); - - $poolMock->shouldReceive('getItem->isMiss') - ->once() - ->andReturn(false); - - $poolMock->shouldReceive('getItem->lock') - ->once(); - - $poolMock->shouldReceive('getItem->set') - ->once() - ->with($freshFile) - ->andReturn($item); - - $poolMock->shouldReceive('getItem->get') - ->once() - ->andReturn(null); - - $poolMock->shouldReceive('save')->with($item); - - $sourceFile = m::mock(SourceFile::class); - $sourceFile->shouldReceive('path')->andReturn('myFile.php'); - $sourceFile->shouldReceive('md5') - ->andReturn('NewHash'); - $stategies = m::mock(StrategyContainer::class); - - $command = new CreateCommand($sourceFile, $stategies); - $fixture = new CacheMiddleware($poolMock); - - $result = $fixture->execute($command, function () use ($freshFile) { - return $freshFile; - }); - - $this->assertSame($freshFile, $result); - } - - /** - * @covers ::execute - * @uses \phpDocumentor\Reflection\Php\Factory\File\CreateCommand - * @uses \phpDocumentor\Reflection\Php\File - */ - public function testCacheNewFileIfHashMismatches() : void - { - $cachedFile = new File('OldHash', 'myFile.php'); - $freshFile = new File('NewHash', 'myFile.php'); - $item = new Item(); - $poolMock = m::mock(Pool::class); - $poolMock->shouldReceive('getItem') - ->andReturnSelf(); - - $poolMock->shouldReceive('getItem->isMiss') - ->once() - ->andReturn(false); - - $poolMock->shouldReceive('getItem->lock') - ->once(); - - $poolMock->shouldReceive('getItem->set') - ->once() - ->with($freshFile) - ->andReturn($item); - - $poolMock->shouldReceive('getItem->get') - ->once() - ->andReturn($cachedFile); - - $poolMock->shouldReceive('save')->with($item); - - $sourceFile = m::mock(SourceFile::class); - $sourceFile->shouldReceive('path')->andReturn('myFile.php'); - $sourceFile->shouldReceive('md5') - ->andReturn('NewHash'); - $stategies = m::mock(StrategyContainer::class); - - $command = new CreateCommand($sourceFile, $stategies); - $fixture = new CacheMiddleware($poolMock); - - $result = $fixture->execute($command, function () use ($freshFile) { - return $freshFile; - }); - - $this->assertSame($freshFile, $result); - } -} diff --git a/tests/unit/phpDocumentor/Parser/ParserTest.php b/tests/unit/phpDocumentor/Parser/ParserTest.php index e2864e1f2b..10fdc03ee4 100644 --- a/tests/unit/phpDocumentor/Parser/ParserTest.php +++ b/tests/unit/phpDocumentor/Parser/ParserTest.php @@ -58,18 +58,6 @@ public function testSetAndGetIgnoredTags() : void $this->assertEquals(['param'], $parser->getIgnoredTags()); } - /** - * @covers ::setForced - * @covers ::isForced - */ - public function testSetAndCheckWhetherParsingIsForced() : void - { - $this->assertEquals(false, $this->fixture->isForced()); - - $this->fixture->setForced(true); - $this->assertEquals(true, $this->fixture->isForced()); - } - /** * @covers ::setEncoding * @covers ::getEncoding