Skip to content

Commit 0886627

Browse files
authored
Fix #40: Make RedisCache::$client readonly
1 parent f973f70 commit 0886627

9 files changed

Lines changed: 17 additions & 16 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- '8.2'
2828
- '8.3'
2929
- '8.4'
30+
- '8.5'
3031

3132
steps:
3233
- name: Checkout

.github/workflows/composer-require-checker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
os: >-
2222
['ubuntu-latest']
2323
php: >-
24-
['8.1', '8.2', '8.3', '8.4']
24+
['8.1', '8.2', '8.3', '8.4', '8.5']

.github/workflows/mutation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
matrix:
2525
os: [ 'ubuntu-latest' ]
26-
php: [ '8.4' ]
26+
php: [ '8.5' ]
2727

2828
steps:
2929
- name: Checkout

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
matrix:
2626
os: ['ubuntu-latest']
27-
php: ['8.1', '8.2', '8.3', '8.4']
27+
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
2828

2929
steps:
3030
- name: Checkout

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Enh #30: Remove unneeded casting to array in private method `RedisCache::iterableToArray()` (@vjik)
66
- Chg #38: Bump minimum PHP version to `8.1` (@s1lver)
7+
- Chg #40: Make `RedisCache::$client` readonly (@s1lver)
78

89
## 2.0.0 July 10, 2023
910

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
"url": "https://github.com/sponsors/yiisoft"
3030
}
3131
],
32-
"minimum-stability": "dev",
33-
"prefer-stable": true,
3432
"require": {
35-
"php": "^8.1",
33+
"php": "8.1 - 8.5",
3634
"predis/predis": "^v3.0.0",
3735
"psr/simple-cache": "^3.0"
3836
},

src/RedisCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class RedisCache implements CacheInterface
3838
/**
3939
* @param ClientInterface $client Predis client instance to use.
4040
*/
41-
public function __construct(private ClientInterface $client)
41+
public function __construct(private readonly ClientInterface $client)
4242
{
4343
$this->connections = $this->client->getConnection();
4444
}

tests/RedisCacheTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use IteratorAggregate;
1111
use PHPUnit\Framework\TestCase;
1212
use Predis\ClientInterface;
13+
use Predis\Connection\ConnectionInterface;
1314
use Psr\SimpleCache\InvalidArgumentException;
1415
use Predis\Client;
1516
use ReflectionException;
@@ -257,19 +258,18 @@ public function testSetMultipleFailure(): void
257258
{
258259
$client = $this
259260
->getMockBuilder(ClientInterface::class)
261+
->onlyMethods(['getConnection'])
260262
->addMethods(['exec'])
261-
->getMockForAbstractClass()
262-
;
263+
->getMockForAbstractClass();
263264

264-
$client
265+
$client->method('getConnection')
266+
->willReturn($this->createMock(ConnectionInterface::class));
267+
268+
$client->expects($this->once())
265269
->method('exec')
266270
->willReturn([null]);
267271

268-
$reflection = new ReflectionObject($this->cache);
269-
$property = $reflection->getProperty('client');
270-
$property->setValue($this->cache, $client);
271-
272-
$this->assertFalse($this->cache->setMultiple(['key' => 'value'], time()));
272+
$this->assertFalse((new RedisCache($client))->setMultiple(['key' => 'value'], time()));
273273
}
274274

275275
public function testGetMultiple(): void

tests/docker/php/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ FROM php:${PHP_VERSION}-cli-alpine
55

66
RUN apk add unzip zlib-dev libzip-dev libsodium-dev icu-dev autoconf g++ make
77

8-
RUN docker-php-ext-install zip opcache bcmath sodium intl
8+
RUN docker-php-ext-install zip bcmath sodium intl \
9+
&& docker-php-ext-install opcache || true # For backward compatibility with PHP versions below 8.5
910
RUN pecl install pcov
1011
RUN docker-php-ext-enable pcov
1112

0 commit comments

Comments
 (0)