From cbe31cac3bbc270d66757c066e3d0b00ecc9b892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Mon, 18 Dec 2017 07:46:18 +0100 Subject: [PATCH] Support for eZ kernel 7.0 (#122) * Allow installation on eZ kernel 7.0 * Implement reset method in data collector * Remove usage of deprecated GatewayCachePurger * Replace Stash cache pool with Symfony one * Remove generating of Stash configuration * Update tests * Require only eZ kernel 7.0 * Refactor cache code for symfony cache implementation of persistence cache * Fix cache purger tests --- .travis.yml | 3 +- bundle/Cache/PersistenceCachePurger.php | 133 +++++++++--------- bundle/Cache/SwitchableHttpCachePurger.php | 30 ++-- bundle/Collector/LegacyTemplatesCollector.php | 5 + .../Compiler/HttpCachePass.php | 42 ------ bundle/EzPublishLegacyBundle.php | 2 - bundle/LegacyMapper/Configuration.php | 14 +- bundle/Resources/config/services.yml | 6 +- bundle/SetupWizard/ConfigurationConverter.php | 48 ------- .../Cache/PersistenceCachePurgerTest.php | 120 ++++------------ .../Cache/SwitchableHttpCachePurgerTest.php | 18 +-- .../ConfigurationConverterTest.php | 9 -- composer.json | 9 +- .../Tests/Twig/LoaderStringTest.php | 2 +- 14 files changed, 147 insertions(+), 294 deletions(-) delete mode 100644 bundle/DependencyInjection/Compiler/HttpCachePass.php diff --git a/.travis.yml b/.travis.yml index f1c2c899..80513acd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,8 @@ language: php # run tests on php misc php versions php: - - 5.6 - - 7.0 - 7.1 + - 7.2 cache: directories: diff --git a/bundle/Cache/PersistenceCachePurger.php b/bundle/Cache/PersistenceCachePurger.php index 5d2f3f70..4471a586 100644 --- a/bundle/Cache/PersistenceCachePurger.php +++ b/bundle/Cache/PersistenceCachePurger.php @@ -8,12 +8,11 @@ */ namespace eZ\Bundle\EzPublishLegacyBundle\Cache; +use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; +use eZ\Publish\API\Repository\Exceptions\NotFoundException as APINotFoundException; use eZ\Publish\SPI\Persistence\Content\Location\Handler as LocationHandlerInterface; use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType; -use eZ\Publish\Core\Base\Exceptions\NotFoundException; -use eZ\Publish\Core\Persistence\Cache\CacheServiceDecorator; -use Psr\Log\LoggerInterface; /** * Class PersistenceCachePurger. @@ -23,7 +22,7 @@ class PersistenceCachePurger implements CacheClearerInterface use Switchable; /** - * @var \eZ\Publish\Core\Persistence\Cache\CacheServiceDecorator + * @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */ protected $cache; @@ -33,34 +32,29 @@ class PersistenceCachePurger implements CacheClearerInterface protected $locationHandler; /** - * Avoid clearing sub elements if all cache is already cleared, avoids redundant calls to Stash. + * Avoid clearing sub elements if all cache is already cleared, avoids redundant calls to cache. * * @var bool */ protected $allCleared = false; - /** - * @var \Psr\Log\LoggerInterface - */ - protected $logger; - /** * Setups current handler with everything needed. * - * @param \eZ\Publish\Core\Persistence\Cache\CacheServiceDecorator $cache - * @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $locationHandler - * @param \Psr\Log\LoggerInterface $logger + * @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $cache + * @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $locationHandler (using SPI cache instance so calls are cached) */ - public function __construct(CacheServiceDecorator $cache, LocationHandlerInterface $locationHandler, LoggerInterface $logger) + public function __construct(TagAwareAdapterInterface $cache, LocationHandlerInterface $locationHandler) { $this->cache = $cache; $this->locationHandler = $locationHandler; - $this->logger = $logger; } /** * Clear all persistence cache. * + * In legacy kernel used when user presses clear all cache button in admin interface. + * * Sets a internal flag 'allCleared' to avoid clearing cache several times */ public function all() @@ -98,7 +92,9 @@ public function resetAllCleared() /** * Clear all content persistence cache, or by locationIds (legacy content/cache mechanism is location based). * - * Either way all location and urlAlias cache is cleared as well. + * In legacy kernel used when any kind of event triggers cache clearing for content. + * If amount of accepted nodes goes over threshold, or in case where all content cache is cleared from admin + * interface, argument will be empty. * * @param int|int[]|null $locationIds Ids of location we need to purge content cache for. Purges all content cache if null * @@ -113,36 +109,32 @@ public function content($locationIds = null) } if ($locationIds === null) { - $this->cache->clear('content'); - goto relatedCache; - } elseif (!is_array($locationIds)) { - $locationIds = array($locationIds); + $this->cache->clear(); + + return $locationIds; } + if (!is_array($locationIds)) { + $locationIds = [$locationIds]; + } + + $tags = []; foreach ($locationIds as $id) { if (!is_scalar($id)) { throw new InvalidArgumentType('$id', 'int[]|null', $id); } + $tags[] = 'location-' . $id; + $tags[] = 'urlAlias-location-' . $id; + try { $location = $this->locationHandler->load($id); - $this->cache->clear('content', $location->contentId); - $this->cache->clear('content', 'info', $location->contentId); - $this->cache->clear('content', 'info', 'remoteId'); - $this->cache->clear('content', 'locations', $location->contentId); - $this->cache->clear('user', 'role', 'assignments', 'byGroup', $location->contentId); - $this->cache->clear('user', 'role', 'assignments', 'byGroup', 'inherited', $location->contentId); - } catch (NotFoundException $e) { - $this->logger->notice( - "Unable to load the location with the id '$id' to clear its cache" - ); + $tags[] = 'content-' . $location->contentId; + } catch (APINotFoundException $e) { + // Location might be deleted, so catch and we clear by location id which is ok for most cases. } } - - // clear content related cache as well - relatedCache: - $this->cache->clear('urlAlias'); - $this->cache->clear('location'); + $this->cache->invalidateTags($tags); return $locationIds; } @@ -150,6 +142,8 @@ public function content($locationIds = null) /** * Clears persistence cache for given $contentId and $versionNo. * + * In legacy kernel used when storing a draft. + * * @param int $contentId * @param int $versionNo */ @@ -159,12 +153,16 @@ public function contentVersion($contentId, $versionNo) return; } - $this->cache->clear('content', $contentId, $versionNo); + $this->cache->deleteItem("ez-content-version-info-${contentId}-${versionNo}"); + $this->cache->invalidateTags(["content-${contentId}-version-list"]); } /** * Clear all contentType persistence cache, or by id. * + * In legacy kernel used when editing content type, in this case we get id. + * Also used when clearing content type meta data cache in admin cache interface (no id). + * * @param int|null $id Purges all contentType cache if null * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType On invalid $id type */ @@ -175,63 +173,61 @@ public function contentType($id = null) } if ($id === null) { - $this->cache->clear('contentType'); + $this->cache->invalidateTags(['type-map']); } elseif (is_scalar($id)) { - $this->cache->clear('contentType', $id); + $this->cache->invalidateTags(['type-' . $id]); } else { throw new InvalidArgumentType('$id', 'int|null', $id); } } /** - * Clear all contentTypeGroup persistence cache, or by id. + * Clear contentTypeGroup persistence cache by id. * - * Either way, contentType cache is also cleared as it contains the relation to contentTypeGroups + * In legacy kernel used when editing/removing content type group, so there is always an id. * - * @param int|null $id Purges all contentTypeGroup cache if null + * @param int $id * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType On invalid $id type */ - public function contentTypeGroup($id = null) + public function contentTypeGroup($id) { if ($this->allCleared === true || $this->isSwitchedOff()) { return; } - if ($id === null) { - $this->cache->clear('contentTypeGroup'); - } elseif (is_scalar($id)) { - $this->cache->clear('contentTypeGroup', $id); + if (is_scalar($id)) { + // @todo should also clear content type cache for items themselves in case of link/unlink changes, kernel should have a "type-all" tag for this + $this->cache->invalidateTags(['type-group-' . $id, 'type-map']); } else { throw new InvalidArgumentType('$id', 'int|null', $id); } - - // clear content type in case of changes as it contains the relation to groups - $this->cache->clear('contentType'); } /** - * Clear all section persistence cache, or by id. + * Clear section persistence cache by id. * - * @param int|null $id Purges all section cache if null + * In legacy kernel used when editing section, so there is always an id. + * + * @param int $id * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType On invalid $id type */ - public function section($id = null) + public function section($id) { if ($this->allCleared === true || $this->isSwitchedOff()) { return; } - if ($id === null) { - $this->cache->clear('section'); - } elseif (is_scalar($id)) { - $this->cache->clear('section', $id); + if (is_scalar($id)) { + $this->cache->invalidateTags(['section-' . $id]); } else { throw new InvalidArgumentType('$id', 'int|null', $id); } } /** - * Clear all language persistence cache, or by id. + * Clear language persistence cache by id. + * + * In legacy kernel used when editing language, so there is always an id. * * @param array|int $ids */ @@ -242,27 +238,34 @@ public function languages($ids) } $ids = (array)$ids; + $tags = []; foreach ($ids as $id) { - $this->cache->clear('language', $id); + $tags[] = 'language-' . $id; } + + $this->cache->invalidateTags($tags); } /** * Clear object state assignment persistence cache by content id. * + * In legacy kernel used when assigning statet to an content. + * * @param int $contentId */ public function stateAssign($contentId) { - if ($this->allCleared === true || $this->enabled === false) { + if ($this->allCleared === true || $this->isSwitchedOff()) { return; } - $this->cache->clear('objectstate', 'byContent', $contentId); + $this->cache->invalidateTags(['content-' . $contentId]); } /** - * Clear all user persistence cache. + * Clear meta info on users in Persistence. + * + * In legacy kernel used when clearing meta info cache on users in eZUser, never with id. * * @param int|null $id Purges all users cache if null * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType On invalid $id type @@ -274,9 +277,11 @@ public function user($id = null) } if ($id === null) { - $this->cache->clear('user'); + // @todo From the looks of usage in legacy we only need to clear meta data here, and there is no such thing + // in persistence so we ignore it for now. + //$this->cache->clear(); } elseif (is_scalar($id)) { - $this->cache->clear('user', $id); + $this->cache->invalidateTags(['user-' . $id]); } else { throw new InvalidArgumentType('$id', 'int|null', $id); } @@ -285,6 +290,8 @@ public function user($id = null) /** * Clears any caches necessary. * + * Used by symfony cache clear command. + * * @param string $cacheDir the cache directory */ public function clear($cacheDir) diff --git a/bundle/Cache/SwitchableHttpCachePurger.php b/bundle/Cache/SwitchableHttpCachePurger.php index dd67c90f..9af84989 100644 --- a/bundle/Cache/SwitchableHttpCachePurger.php +++ b/bundle/Cache/SwitchableHttpCachePurger.php @@ -7,21 +7,23 @@ */ namespace eZ\Bundle\EzPublishLegacyBundle\Cache; -use eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger; +use EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface; /** - * A GatewayCachePurger decorator that allows the actual purger to be switched on/off. + * A PurgeClient decorator that allows the actual purger to be switched on/off. */ -class SwitchableHttpCachePurger implements GatewayCachePurger +class SwitchableHttpCachePurger implements PurgeClientInterface { use Switchable; - /** @var \eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger */ - private $gatewayCachePurger; + /** + * @var \EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface + */ + private $purgeClient; - public function __construct(GatewayCachePurger $gatewayCachePurger) + public function __construct(PurgeClientInterface $purgeClient) { - $this->gatewayCachePurger = $gatewayCachePurger; + $this->purgeClient = $purgeClient; } public function purge($locationIds) @@ -30,7 +32,7 @@ public function purge($locationIds) return $locationIds; } - return $this->gatewayCachePurger->purge($locationIds); + return $this->purgeClient->purge($locationIds); } public function purgeAll() @@ -39,15 +41,21 @@ public function purgeAll() return; } - $this->gatewayCachePurger->purgeAll(); + $this->purgeClient->purgeAll(); } + /** + * Implemented for BC with deprecated PurgeClientInterface::purgeForContent from eZ kernel. + * + * @param int $contentId + * @param array $locationIds + */ public function purgeForContent($contentId, $locationIds = array()) { - if ($this->isSwitchedOff()) { + if ($this->isSwitchedOff() || !method_exists($this->purgeClient, 'purgeForContent')) { return; } - $this->gatewayCachePurger->purgeForContent($contentId, $locationIds); + $this->purgeClient->purgeForContent($contentId, $locationIds); } } diff --git a/bundle/Collector/LegacyTemplatesCollector.php b/bundle/Collector/LegacyTemplatesCollector.php index 5e6d5884..0429af60 100644 --- a/bundle/Collector/LegacyTemplatesCollector.php +++ b/bundle/Collector/LegacyTemplatesCollector.php @@ -46,4 +46,9 @@ public function getLegacyTemplates() { return $this->data['legacyTemplates']; } + + public function reset() + { + $this->data = ['legacyTemplates' => []]; + } } diff --git a/bundle/DependencyInjection/Compiler/HttpCachePass.php b/bundle/DependencyInjection/Compiler/HttpCachePass.php deleted file mode 100644 index 01853d19..00000000 --- a/bundle/DependencyInjection/Compiler/HttpCachePass.php +++ /dev/null @@ -1,42 +0,0 @@ -hasAlias('ezplatform.http_cache.purge_client')) { - return; - } - - $container->addDefinitions([ - 'ezplatform.http_cache.purger' => new Definition(InstantCachePurger::class, - [ - new Reference('ezplatform.http_cache.purge_client'), - new Reference('ezpublish.api.service.inner_content'), - new Reference('ezpublish.http_cache.event_dispatcher'), - new Reference('ezpublish.api.repository'), - ] - ), - ]); - - $container->getDefinition('ezpublish_legacy.switchable_http_cache_purger') - ->replaceArgument(0, new Reference('ezplatform.http_cache.purger')); - } -} diff --git a/bundle/EzPublishLegacyBundle.php b/bundle/EzPublishLegacyBundle.php index 68e3b228..8d61d40b 100644 --- a/bundle/EzPublishLegacyBundle.php +++ b/bundle/EzPublishLegacyBundle.php @@ -8,7 +8,6 @@ */ namespace eZ\Bundle\EzPublishLegacyBundle; -use eZ\Bundle\EzPublishLegacyBundle\DependencyInjection\Compiler\HttpCachePass; use eZ\Bundle\EzPublishLegacyBundle\DependencyInjection\Compiler\RememberMeListenerPass; use eZ\Bundle\EzPublishLegacyBundle\DependencyInjection\Compiler\LegacyBundlesPass; use eZ\Bundle\EzPublishLegacyBundle\DependencyInjection\Compiler\LegacySessionPass; @@ -56,7 +55,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RoutingPass()); $container->addCompilerPass(new LegacySessionPass()); $container->addCompilerPass(new RememberMeListenerPass()); - $container->addCompilerPass(new HttpCachePass()); /** @var \Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension $securityExtension */ $securityExtension = $container->getExtension('security'); diff --git a/bundle/LegacyMapper/Configuration.php b/bundle/LegacyMapper/Configuration.php index f42f3706..c1258990 100644 --- a/bundle/LegacyMapper/Configuration.php +++ b/bundle/LegacyMapper/Configuration.php @@ -12,7 +12,7 @@ use eZ\Publish\Core\MVC\Legacy\LegacyEvents; use eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent; use eZ\Publish\Core\MVC\ConfigResolverInterface; -use eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger; +use EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface; use eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger; use eZ\Publish\Core\MVC\Symfony\Routing\Generator\UrlAliasGenerator; use eZ\Publish\Core\Persistence\Database\DatabaseHandler; @@ -36,9 +36,9 @@ class Configuration implements EventSubscriberInterface private $configResolver; /** - * @var \eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger + * @var \EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface */ - private $gatewayCachePurger; + private $purgeClient; /** * @var \eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger @@ -74,7 +74,7 @@ class Configuration implements EventSubscriberInterface public function __construct( ConfigResolverInterface $configResolver, - GatewayCachePurger $gatewayCachePurger, + PurgeClientInterface $purgeClient, PersistenceCachePurger $persistenceCachePurger, UrlAliasGenerator $urlAliasGenerator, DatabaseHandler $legacyDbHandler, @@ -82,7 +82,7 @@ public function __construct( array $options = array() ) { $this->configResolver = $configResolver; - $this->gatewayCachePurger = $gatewayCachePurger; + $this->purgeClient = $purgeClient; $this->persistenceCachePurger = $persistenceCachePurger; $this->urlAliasGenerator = $urlAliasGenerator; $this->legacyDbHandler = $legacyDbHandler; @@ -203,8 +203,8 @@ public function onBuildKernel(PreBuildKernelEvent $event) // Register http cache content/cache event listener $ezpEvent = ezpEvent::getInstance(); - $ezpEvent->attach('content/cache', array($this->gatewayCachePurger, 'purge')); - $ezpEvent->attach('content/cache/all', array($this->gatewayCachePurger, 'purgeAll')); + $ezpEvent->attach('content/cache', array($this->purgeClient, 'purge')); + $ezpEvent->attach('content/cache/all', array($this->purgeClient, 'purgeAll')); // Register persistence cache event listeners $ezpEvent->attach('content/cache', array($this->persistenceCachePurger, 'content')); diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index 52227e0e..8802e304 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -240,7 +240,9 @@ services: ezpublish_legacy.persistence_cache_purger: class: "%ezpublish_legacy.persistence_cache_purger.class%" - arguments: ["@ezpublish.cache_pool.spi.cache.decorator", "@ezpublish.spi.persistence.cache.locationHandler", "@logger"] + arguments: + - "@ezpublish.cache_pool" + - "@ezpublish.spi.persistence.cache.locationHandler" tags: - { name: kernel.cache_clearer } lazy: true @@ -259,7 +261,7 @@ services: ezpublish_legacy.switchable_http_cache_purger: class: "%ezpublish_legacy.switchable_http_cache_purger.class%" - arguments: ["@ezpublish.http_cache.purger"] + arguments: ["@ezplatform.http_cache.purge_client"] ezpublish_legacy.content_exception_handler: class: "%ezpublish_legacy.content_exception_handler.class%" diff --git a/bundle/SetupWizard/ConfigurationConverter.php b/bundle/SetupWizard/ConfigurationConverter.php index 9f68e73d..421053b8 100644 --- a/bundle/SetupWizard/ConfigurationConverter.php +++ b/bundle/SetupWizard/ConfigurationConverter.php @@ -12,7 +12,6 @@ use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException; use eZINI; use eZSiteAccess; -use Stash\Driver\FileSystem as FileSystemDriver; /** * Handles conversionlegacy eZ Publish 4 parameters from a set of settings to a configuration array @@ -151,8 +150,6 @@ public function fromLegacy($sitePackage, $adminSiteaccess) } } - $settings['stash'] = $this->getStashCacheSettings(); - ksort($settings); ksort($settings['ezpublish']); @@ -205,51 +202,6 @@ protected function getDoctrineSettings(array $databaseSettings) return $doctrineSettings; } - /** - * Returns cache settings based on which cache functionality is available on the current server. - * - * Order of preference: - * - FileSystem - * - APC - * - Memcache [DISABLED, SEE INLINE] - * - Xcache [DISABLED, SEE INLINE] - * - variable instance cache [DISABLED, SEE INLINE] - * - * @return array - */ - protected function getStashCacheSettings() - { - // Should only contain one out of the box - $handlers = array(); - $inMemory = false; - $handlerSetting = array(); - if (FileSystemDriver::isAvailable()) { - $handlers[] = 'FileSystem'; - $inMemory = true; - // If running on Windows, use "crc32" keyHashFunction - if (stripos(php_uname(), 'win') === 0) { - $handlerSetting['FileSystem'] = array( - 'keyHashFunction' => 'crc32', - ); - } - } else { - // '/dev/null' fallback driver, no cache at all - $handlers[] = 'BlackHole'; - $inMemory = true; - } - - return array( - 'caches' => array( - 'default' => array( - 'drivers' => $handlers, - // inMemory will enable/disable "Ephemeral", not allowed as separate handler in stash-bundle - 'inMemory' => $inMemory, - 'registerDoctrineAdapter' => false, - ) + $handlerSetting, - ), - ); - } - /** * Returns the languages list for all siteaccess unless it's the same for * each one, in this case, it returns the languages list for the group. diff --git a/bundle/Tests/Cache/PersistenceCachePurgerTest.php b/bundle/Tests/Cache/PersistenceCachePurgerTest.php index dd9e8edb..f8a93953 100644 --- a/bundle/Tests/Cache/PersistenceCachePurgerTest.php +++ b/bundle/Tests/Cache/PersistenceCachePurgerTest.php @@ -12,9 +12,8 @@ use eZ\Publish\SPI\Persistence\Content\Location; use eZ\Publish\SPI\Persistence\Content\Location\Handler; use eZ\Publish\Core\Base\Exceptions\NotFoundException; -use eZ\Publish\Core\Persistence\Cache\CacheServiceDecorator; +use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; class PersistenceCachePurgerTest extends TestCase { @@ -33,20 +32,15 @@ class PersistenceCachePurgerTest extends TestCase */ private $cachePurger; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $logger; - protected function setUp() { parent::setUp(); - $this->cacheService = $this->createMock(CacheServiceDecorator::class); + $this->cacheService = $this->createMock(TagAwareAdapterInterface::class); $this->locationHandler = $this->createMock(Handler::class); - $this->logger = $this->createMock(LoggerInterface::class); $this->cachePurger = new PersistenceCachePurger( - $this->cacheService, $this->locationHandler, $this->logger + $this->cacheService, + $this->locationHandler ); } @@ -61,10 +55,6 @@ public function testNotFoundLocation() ->method('load') ->will($this->throwException(new NotFoundException('location', $id))); - $this->logger - ->expects($this->once()) - ->method('notice'); - $this->cachePurger->content($id); } @@ -140,15 +130,10 @@ public function testClearAllDisabled() */ public function testClearAllContent() { - $map = array( - array('content', null), - array('urlAlias', null), - array('location', null), - ); $this->cacheService - ->expects($this->exactly(count($map))) - ->method('clear') - ->will($this->returnValueMap($map)); + ->expects($this->once()) + ->method('clear'); + $this->assertNull($this->cachePurger->content()); } @@ -261,8 +246,8 @@ public function testClearContentTypeAll() { $this->cacheService ->expects($this->once()) - ->method('clear') - ->with('contentType'); + ->method('invalidateTags') + ->with(['type-map']); $this->cachePurger->contentType(); } @@ -274,8 +259,8 @@ public function testClearContentType() { $this->cacheService ->expects($this->once()) - ->method('clear') - ->with('contentType', 123); + ->method('invalidateTags') + ->with(['type-123']); $this->cachePurger->contentType(123); } @@ -290,42 +275,15 @@ public function testClearContentTypeFail() $this->cachePurger->contentType(new \stdClass()); } - /** - * @covers \eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger::contentTypeGroup - */ - public function testClearContentTypeGroupAll() - { - $this->cacheService - ->expects($this->exactly(2)) - ->method('clear') - ->will( - $this->returnValueMap( - array( - array('contentTypeGroup', null), - array('contentType', null), - ) - ) - ); - - $this->cachePurger->contentTypeGroup(); - } - /** * @covers \eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger::contentTypeGroup */ public function testClearContentTypeGroup() { $this->cacheService - ->expects($this->exactly(2)) - ->method('clear') - ->will( - $this->returnValueMap( - array( - array('contentTypeGroup', 123, null), - array('contentType', null), - ) - ) - ); + ->expects($this->once()) + ->method('invalidateTags') + ->with(['type-group-123', 'type-map']); $this->cachePurger->contentTypeGroup(123); } @@ -340,19 +298,6 @@ public function testClearContentTypeGroupFail() $this->cachePurger->contentTypeGroup(new \stdClass()); } - /** - * @covers \eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger::section - */ - public function testClearSectionAll() - { - $this->cacheService - ->expects($this->once()) - ->method('clear') - ->with('section'); - - $this->cachePurger->section(); - } - /** * @covers \eZ\Bundle\EzPublishLegacyBundle\Cache\PersistenceCachePurger::section */ @@ -360,8 +305,8 @@ public function testClearSection() { $this->cacheService ->expects($this->once()) - ->method('clear') - ->with('section', 123); + ->method('invalidateTags') + ->with(['section-123']); $this->cachePurger->section(123); } @@ -386,17 +331,9 @@ public function testClearLanguages() $languageId3 = 789; $this->cacheService - ->expects($this->exactly(3)) - ->method('clear') - ->will( - $this->returnValueMap( - array( - array($languageId1, null), - array($languageId2, null), - array($languageId3, null), - ) - ) - ); + ->expects($this->once()) + ->method('invalidateTags') + ->with(['language-123', 'language-456', 'language-789']); $this->cachePurger->languages(array($languageId1, $languageId2, $languageId3)); } @@ -410,14 +347,8 @@ public function testClearOneLanguage() $this->cacheService ->expects($this->once()) - ->method('clear') - ->will( - $this->returnValueMap( - array( - array($languageId, null), - ) - ) - ); + ->method('invalidateTags') + ->with(['language-123']); $this->cachePurger->languages($languageId); } @@ -427,10 +358,11 @@ public function testClearOneLanguage() */ public function testClearUserAll() { + $this->markTestSkipped('Enable when clearing all user cache is implemented.'); + $this->cacheService ->expects($this->once()) - ->method('clear') - ->with('user'); + ->method('clear'); $this->cachePurger->user(); } @@ -442,8 +374,8 @@ public function testClearUser() { $this->cacheService ->expects($this->once()) - ->method('clear') - ->with('user', 123); + ->method('invalidateTags') + ->with(['user-123']); $this->cachePurger->user(123); } diff --git a/bundle/Tests/Cache/SwitchableHttpCachePurgerTest.php b/bundle/Tests/Cache/SwitchableHttpCachePurgerTest.php index 5abf9703..69c3c4a5 100644 --- a/bundle/Tests/Cache/SwitchableHttpCachePurgerTest.php +++ b/bundle/Tests/Cache/SwitchableHttpCachePurgerTest.php @@ -8,28 +8,28 @@ namespace eZ\Bundle\EzPublishLegacyBundle\Tests\Cache; use eZ\Bundle\EzPublishLegacyBundle\Cache\SwitchableHttpCachePurger; -use eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger; +use EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface; use PHPUnit\Framework\TestCase; class SwitchableHttpCachePurgerTest extends TestCase { - /** @var \eZ\Publish\Core\MVC\Symfony\Cache\GatewayCachePurger|\PHPUnit_Framework_MockObject_MockObject */ - private $gatewayCachePurgerMock; + /** @var \EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $purgeClientMockMock; /** @var \eZ\Bundle\EzPublishLegacyBundle\Cache\SwitchableHttpCachePurger */ private $httpCachePurger; public function setUp() { - $this->gatewayCachePurgerMock = $this->createMock(GatewayCachePurger::class); - $this->httpCachePurger = new SwitchableHttpCachePurger($this->gatewayCachePurgerMock); + $this->purgeClientMockMock = $this->createMock(PurgeClientInterface::class); + $this->httpCachePurger = new SwitchableHttpCachePurger($this->purgeClientMockMock); } public function testPurgeSwitchedOn() { $this->httpCachePurger->switchOn(); - $this->gatewayCachePurgerMock->expects($this->once())->method('purge')->willReturn($this->getCacheElements()); + $this->purgeClientMockMock->expects($this->once())->method('purge')->willReturn($this->getCacheElements()); self::assertEquals( $this->getCacheElements(), $this->httpCachePurger->purge($this->getCacheElements()) @@ -39,7 +39,7 @@ public function testPurgeSwitchedOn() public function testPurgeSwitchedOff() { $this->httpCachePurger->switchOff(); - $this->gatewayCachePurgerMock->expects($this->never())->method('purge'); + $this->purgeClientMockMock->expects($this->never())->method('purge'); self::assertEquals( $this->getCacheElements(), $this->httpCachePurger->purge($this->getCacheElements()) @@ -49,14 +49,14 @@ public function testPurgeSwitchedOff() public function testPurgeAllSwitchedOn() { $this->httpCachePurger->switchOn(); - $this->gatewayCachePurgerMock->expects($this->once())->method('purgeAll'); + $this->purgeClientMockMock->expects($this->once())->method('purgeAll'); $this->httpCachePurger->purgeAll(); } public function testPurgeAllSwitchedOff() { $this->httpCachePurger->switchOff(); - $this->gatewayCachePurgerMock->expects($this->never())->method('purgeAll'); + $this->purgeClientMockMock->expects($this->never())->method('purgeAll'); $this->httpCachePurger->purgeAll(); } diff --git a/bundle/Tests/SetupWizard/ConfigurationConverterTest.php b/bundle/Tests/SetupWizard/ConfigurationConverterTest.php index edb21315..4178ad5e 100644 --- a/bundle/Tests/SetupWizard/ConfigurationConverterTest.php +++ b/bundle/Tests/SetupWizard/ConfigurationConverterTest.php @@ -171,15 +171,6 @@ public function providerForTestFromLegacy() 'path' => '/usr/bin/convert', ), ), - 'stash' => array( - 'caches' => array( - 'default' => array( - 'drivers' => array('FileSystem'), // If this fails then APC or Memcached is enabled on PHP-CLI - 'inMemory' => true, - 'registerDoctrineAdapter' => false, - ), - ), - ), ); $exceptionType = InvalidArgumentException::class; diff --git a/composer.json b/composer.json index adb60ae8..bb60da77 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,13 @@ "minimum-stability": "stable", "require": { "ezsystems/ezpublish-legacy-installer": "^2.0.4", - "ezsystems/ezpublish-legacy": ">=2017.08@dev", - "ezsystems/ezpublish-kernel": "^6.11@dev", - "sensio/distribution-bundle": "^3.0.36|^4.0.6|^5.0.6", + "ezsystems/ezpublish-legacy": ">=2017.10@dev", + "ezsystems/ezpublish-kernel": "^7.0@dev", + "sensio/distribution-bundle": "^5.0.6", "twig/twig": "^1.27 | ^2.0" }, "require-dev": { + "ezsystems/ezplatform-http-cache": "*", "matthiasnoback/symfony-dependency-injection-test": "^1.0", "phpunit/phpunit": "^5.7", "mikey179/vfsStream": "~1.1.0" @@ -34,7 +35,7 @@ "extra": { "ezpublish-legacy-dir": "ezpublish_legacy", "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/mvc/Templating/Tests/Twig/LoaderStringTest.php b/mvc/Templating/Tests/Twig/LoaderStringTest.php index 971c2bc0..3ab51a2d 100644 --- a/mvc/Templating/Tests/Twig/LoaderStringTest.php +++ b/mvc/Templating/Tests/Twig/LoaderStringTest.php @@ -35,7 +35,7 @@ public function testGetCacheKey() public function testIsFresh() { $loaderString = new LoaderString(); - $this->assertSame(true, $loaderString->isFresh('foo', time())); + $this->assertTrue($loaderString->isFresh('foo', time())); } /**