Skip to content

Commit

Permalink
Fix cache purger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Dec 16, 2017
1 parent a122e55 commit ec3ded4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 98 deletions.
10 changes: 1 addition & 9 deletions bundle/Cache/PersistenceCachePurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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 Psr\Log\LoggerInterface;

/**
* Class PersistenceCachePurger.
Expand All @@ -39,23 +38,16 @@ class PersistenceCachePurger implements CacheClearerInterface
*/
protected $allCleared = false;

/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

/**
* Setups current handler with everything needed.
*
* @param \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface $cache
* @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $locationHandler (using SPI cache instance so calls are cached)
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(TagAwareAdapterInterface $cache, LocationHandlerInterface $locationHandler, LoggerInterface $logger)
public function __construct(TagAwareAdapterInterface $cache, LocationHandlerInterface $locationHandler)
{
$this->cache = $cache;
$this->locationHandler = $locationHandler;
$this->logger = $logger;
}

/**
Expand Down
1 change: 0 additions & 1 deletion bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ services:
arguments:
- "@ezpublish.cache_pool"
- "@ezpublish.spi.persistence.cache.locationHandler"
- "@logger"
tags:
- { name: kernel.cache_clearer }
lazy: true
Expand Down
107 changes: 19 additions & 88 deletions bundle/Tests/Cache/PersistenceCachePurgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class PersistenceCachePurgerTest extends TestCase
{
Expand All @@ -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(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
);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -261,8 +246,8 @@ public function testClearContentTypeAll()
{
$this->cacheService
->expects($this->once())
->method('clear')
->with('contentType');
->method('invalidateTags')
->with(['type-map']);

$this->cachePurger->contentType();
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -340,28 +298,15 @@ 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
*/
public function testClearSection()
{
$this->cacheService
->expects($this->once())
->method('clear')
->with('section', 123);
->method('invalidateTags')
->with(['section-123']);

$this->cachePurger->section(123);
}
Expand All @@ -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));
}
Expand All @@ -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);
}
Expand Down

0 comments on commit ec3ded4

Please sign in to comment.