Skip to content

Commit

Permalink
MERGE: Merge branch '8.1' into 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kdambekalns committed Oct 12, 2023
2 parents de25786 + e0a7f8d commit 0aaf4d5
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions Neos.Cache/Tests/Unit/Backend/RedisBackendTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neos\Cache\Tests\Unit\Backend;

include_once(__DIR__ . '/../../BaseTestCase.php');
Expand All @@ -15,8 +16,8 @@

use Neos\Cache\Backend\RedisBackend;
use Neos\Cache\EnvironmentConfiguration;
use Neos\Cache\Tests\BaseTestCase;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Tests\BaseTestCase;

/**
* Testcase for the redis cache backend
Expand All @@ -27,7 +28,7 @@
class RedisBackendTest extends BaseTestCase
{
/**
* @var \PHPUnit\Framework\MockObject\MockObject
* @var \PHPUnit\Framework\MockObject\MockObject|\Redis
*/
private $redis;

Expand All @@ -37,7 +38,7 @@ class RedisBackendTest extends BaseTestCase
private $backend;

/**
* @var \PHPUnit\Framework\MockObject\MockObject
* @var \PHPUnit\Framework\MockObject\MockObject|FrontendInterface
*/
private $cache;

Expand All @@ -54,9 +55,8 @@ protected function setUp(): void

$this->redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
$this->cache = $this->createMock(FrontendInterface::class);
$this->cache->expects(self::any())
->method('getIdentifier')
->will(self::returnValue('Foo_Cache'));
$this->cache->method('getIdentifier')
->willReturn('Foo_Cache');

$mockEnvironmentConfiguration = $this->getMockBuilder(EnvironmentConfiguration::class)->setConstructorArgs([
__DIR__ . '~Testing',
Expand All @@ -76,24 +76,27 @@ protected function setUp(): void
/**
* @test
*/
public function findIdentifiersByTagInvokesRedis()
public function findIdentifiersByTagInvokesRedis(): void
{
$this->redis->expects(self::once())
->method('sMembers')
->with('d41d8cd98f00b204e9800998ecf8427e:Foo_Cache:tag:some_tag')
->will(self::returnValue(['entry_1', 'entry_2']));
->willReturn(['entry_1', 'entry_2']);

$this->assertEquals(['entry_1', 'entry_2'], $this->backend->findIdentifiersByTag('some_tag'));
}

/**
* @test
*/
public function freezeInvokesRedis()
public function freezeInvokesRedis(): void
{
$this->redis->method('exec')
->willReturn($this->redis);

$this->redis->expects(self::once())
->method('keys')
->will(self::returnValue(['entry_1', 'entry_2']));
->willReturn(['entry_1', 'entry_2']);

$this->redis->expects(self::exactly(2))
->method('persist');
Expand All @@ -108,14 +111,13 @@ public function freezeInvokesRedis()
/**
* @test
*/
public function setUsesDefaultLifetimeIfNotProvided()
public function setUsesDefaultLifetimeIfNotProvided(): void
{
$defaultLifetime = rand(1, 9999);
$defaultLifetime = random_int(1, 9999);
$this->backend->setDefaultLifetime($defaultLifetime);
$expected = ['ex' => $defaultLifetime];

$this->redis->expects(self::any())
->method('multi')
$this->redis->method('multi')
->willReturn($this->redis);

$this->redis->expects(self::once())
Expand All @@ -129,14 +131,13 @@ public function setUsesDefaultLifetimeIfNotProvided()
/**
* @test
*/
public function setUsesProvidedLifetime()
public function setUsesProvidedLifetime(): void
{
$defaultLifetime = 3600;
$this->backend->setDefaultLifetime($defaultLifetime);
$expected = ['ex' => 1600];

$this->redis->expects(self::any())
->method('multi')
$this->redis->method('multi')
->willReturn($this->redis);

$this->redis->expects(self::once())
Expand All @@ -150,10 +151,9 @@ public function setUsesProvidedLifetime()
/**
* @test
*/
public function setAddsEntryToRedis()
public function setAddsEntryToRedis(): void
{
$this->redis->expects(self::any())
->method('multi')
$this->redis->method('multi')
->willReturn($this->redis);

$this->redis->expects(self::once())
Expand All @@ -167,25 +167,25 @@ public function setAddsEntryToRedis()
/**
* @test
*/
public function getInvokesRedis()
public function getInvokesRedis(): void
{
$this->redis->expects(self::once())
->method('get')
->with('d41d8cd98f00b204e9800998ecf8427e:Foo_Cache:entry:foo')
->will(self::returnValue('bar'));
->willReturn('bar');

self::assertEquals('bar', $this->backend->get('foo'));
}

/**
* @test
*/
public function hasInvokesRedis()
public function hasInvokesRedis(): void
{
$this->redis->expects(self::once())
->method('exists')
->with('d41d8cd98f00b204e9800998ecf8427e:Foo_Cache:entry:foo')
->will(self::returnValue(true));
->willReturn(true);

self::assertEquals(true, $this->backend->has('foo'));
}
Expand All @@ -195,14 +195,14 @@ public function hasInvokesRedis()
* @dataProvider writingOperationsProvider
* @param string $method
*/
public function writingOperationsThrowAnExceptionIfCacheIsFrozen($method)
public function writingOperationsThrowAnExceptionIfCacheIsFrozen(string $method): void
{
$this->expectException(\RuntimeException::class);
$this->inject($this->backend, 'frozen', null);
$this->redis->expects(self::once())
->method('exists')
->with('d41d8cd98f00b204e9800998ecf8427e:Foo_Cache:frozen')
->will(self::returnValue(true));
->willReturn(true);

$this->backend->$method('foo', 'bar');
}
Expand All @@ -212,22 +212,22 @@ public function writingOperationsThrowAnExceptionIfCacheIsFrozen($method)
* @dataProvider batchWritingOperationsProvider
* @param string $method
*/
public function batchWritingOperationsThrowAnExceptionIfCacheIsFrozen($method)
public function batchWritingOperationsThrowAnExceptionIfCacheIsFrozen(string $method): void
{
$this->expectException(\RuntimeException::class);
$this->inject($this->backend, 'frozen', null);
$this->redis->expects(self::once())
->method('exists')
->with('d41d8cd98f00b204e9800998ecf8427e:Foo_Cache:frozen')
->will(self::returnValue(true));
->willReturn(true);

$this->backend->$method(['foo', 'bar']);
}

/**
* @return array
*/
public static function writingOperationsProvider()
public static function writingOperationsProvider(): array
{
return [
['set'],
Expand All @@ -240,7 +240,7 @@ public static function writingOperationsProvider()
/**
* @return array
*/
public static function batchWritingOperationsProvider()
public static function batchWritingOperationsProvider(): array
{
return [
['flushByTags'],
Expand Down

0 comments on commit 0aaf4d5

Please sign in to comment.