Skip to content

Commit 7eb5b43

Browse files
Use Yii2 22. (#273)
1 parent bfec5b6 commit 7eb5b43

16 files changed

+1723
-223
lines changed

.github/workflows/build.yml

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,56 @@
11
on:
2-
- pull_request
3-
- push
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
10+
push:
11+
paths-ignore:
12+
- 'docs/**'
13+
- 'README.md'
14+
- 'CHANGELOG.md'
15+
- '.gitignore'
16+
- '.gitattributes'
417

518
name: build
619

720
jobs:
821
tests:
9-
name: PHP ${{ matrix.php }}-redis-4
22+
name: PHP ${{ matrix.php }}-redis-${{ matrix.redis }}
1023

1124
runs-on: ${{ matrix.os }}
1225

1326
strategy:
27+
fail-fast: false
28+
1429
matrix:
1530
os:
1631
- ubuntu-latest
1732

1833
php:
19-
- "5.4"
20-
- "5.5"
21-
- "5.6"
22-
- "7.0"
23-
- "7.1"
24-
- "7.2"
25-
- "7.3"
26-
- "7.4"
34+
- 8.1
35+
- 8.2
36+
- 8.3
37+
- 8.4
38+
39+
redis:
40+
- 6
41+
- 7
42+
- 8
43+
44+
services:
45+
redis:
46+
image: redis:${{ matrix.redis }}
47+
ports:
48+
- 6379:6379
49+
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=5
2750

2851
steps:
2952
- name: Checkout
30-
uses: actions/checkout@v2
31-
32-
- name: Start Redis v4
33-
uses: superchargejs/[email protected]
34-
with:
35-
redis-version: 4
53+
uses: actions/checkout@v4
3654

3755
- name: Install PHP with extensions
3856
uses: shivammathur/setup-php@v2
@@ -42,19 +60,20 @@ jobs:
4260
ini-values: date.timezone='UTC'
4361
tools: composer:v2, pecl
4462

45-
- name: Get Composer cache directory
46-
id: composer-cache
47-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
48-
49-
- name: Cache Composer dependencies
50-
uses: actions/[email protected]
51-
with:
52-
path: ${{ steps.composer-cache.outputs.dir }}
53-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
54-
restore-keys: ${{ runner.os }}-composer-
55-
5663
- name: Install dependencies with Composer
5764
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
5865

59-
- name: Run Redis tests with PhpUnit
60-
run: vendor/bin/phpunit --coverage-clover=coverage.clover
66+
- name: Run tests with phpunit.
67+
if: matrix.php != '8.1'
68+
run: vendor/bin/phpunit --colors=always
69+
70+
- name: Run tests with phpunit and generate coverage.
71+
if: matrix.php == '8.1'
72+
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always
73+
74+
- name: Upload coverage to Codecov.
75+
if: matrix.php == '8.1'
76+
uses: codecov/codecov-action@v4
77+
with:
78+
token: ${{ secrets.CODECOV_TOKEN }}
79+
files: ./coverage.xml

.github/workflows/ci-redis.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
2222
Requirements
2323
------------
2424

25-
At least redis version 2.6.12 is required for all components to work properly.
25+
At least redis version is required for all components to work properly.
2626

2727
Installation
2828
------------
@@ -32,13 +32,13 @@ The preferred way to install this extension is through [composer](https://getcom
3232
Either run
3333

3434
```
35-
php composer.phar require --prefer-dist yiisoft/yii2-redis:"~2.0.0"
35+
php composer.phar require --prefer-dist yiisoft/yii2-redis:^22.x-dev
3636
```
3737

3838
or add
3939

4040
```json
41-
"yiisoft/yii2-redis": "~2.0.0"
41+
"yiisoft/yii2-redis": "^22.x-dev"
4242
```
4343

4444
to the require section of your composer.json.

composer.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"name": "yiisoft/yii2-redis",
33
"description": "Redis Cache, Session and ActiveRecord for the Yii framework",
4-
"keywords": ["yii2", "redis", "active-record", "cache", "session"],
4+
"keywords": [
5+
"yii2",
6+
"redis",
7+
"active-record",
8+
"cache",
9+
"session"
10+
],
511
"type": "yii2-extension",
612
"license": "BSD-3-Clause",
713
"support": {
@@ -18,30 +24,19 @@
1824
}
1925
],
2026
"require": {
21-
"yiisoft/yii2": "~2.0.39",
22-
"ext-openssl": "*"
27+
"php": ">=8.1",
28+
"ext-openssl": "*",
29+
"yiisoft/yii2": "22.0.x-dev"
2330
},
2431
"require-dev": {
25-
"phpunit/phpunit": "<7",
26-
"yiisoft/yii2-dev": "~2.0.39"
32+
"phpunit/phpunit": "^9.6"
2733
},
2834
"autoload": {
2935
"psr-4": { "yii\\redis\\": "src" }
3036
},
3137
"autoload-dev": {
3238
"psr-4": { "yiiunit\\extensions\\redis\\": "tests/"}
3339
},
34-
"extra": {
35-
"branch-alias": {
36-
"dev-master": "2.0.x-dev"
37-
}
38-
},
39-
"repositories": [
40-
{
41-
"type": "composer",
42-
"url": "https://asset-packagist.org"
43-
}
44-
],
4540
"config": {
4641
"allow-plugins": {
4742
"yiisoft/yii2-composer": true

phpunit.xml.dist

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<phpunit bootstrap="./tests/bootstrap.php"
3-
colors="true"
4-
convertErrorsToExceptions="true"
5-
convertNoticesToExceptions="true"
6-
convertWarningsToExceptions="true"
7-
stopOnFailure="false">
8-
<testsuites>
9-
<testsuite name="Test Suite">
10-
<directory>./tests</directory>
11-
</testsuite>
12-
</testsuites>
13-
<filter>
14-
<whitelist processUncoveredFilesFromWhitelist="true">
15-
<directory suffix=".php">src/</directory>
16-
</whitelist>
17-
</filter>
2+
<phpunit
3+
bootstrap="./tests/bootstrap.php"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
stopOnFailure="false"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
11+
>
12+
<testsuites>
13+
<testsuite name="Yii2-Redis">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<coverage>
18+
<include>
19+
<directory suffix=".php">src</directory>
20+
</include>
21+
</coverage>
1822
</phpunit>

src/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public function open()
631631
}
632632

633633
$connection = $this->connectionString . ', database=' . $this->database;
634-
\Yii::trace('Opening redis DB connection: ' . $connection, __METHOD__);
634+
\Yii::debug('Opening redis DB connection: ' . $connection, __METHOD__);
635635
$socket = @stream_socket_client(
636636
$this->connectionString,
637637
$errorNumber,
@@ -672,7 +672,7 @@ public function close()
672672
{
673673
foreach ($this->_pool as $socket) {
674674
$connection = $this->connectionString . ', database=' . $this->database;
675-
\Yii::trace('Closing DB connection: ' . $connection, __METHOD__);
675+
\Yii::debug('Closing DB connection: ' . $connection, __METHOD__);
676676
try {
677677
$this->executeCommand('QUIT');
678678
} catch (SocketException $e) {
@@ -769,7 +769,7 @@ public function executeCommand($name, $params = [])
769769
$command .= '$' . mb_strlen($arg ?? '', '8bit') . "\r\n" . $arg . "\r\n";
770770
}
771771

772-
\Yii::trace("Executing Redis Command: {$name}", __METHOD__);
772+
\Yii::debug("Executing Redis Command: {$name}", __METHOD__);
773773
if ($this->retries > 0) {
774774
$tries = $this->retries;
775775
while ($tries-- > 0) {

tests/ActiveDataProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
class ActiveDataProviderTest extends TestCase
1313
{
14-
public function setUp()
14+
public function setUp(): void
1515
{
1616
parent::setUp();
1717
ActiveRecord::$db = $this->getConnection();

tests/ActiveRecordTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
use yii\redis\ActiveQuery;
66
use yii\redis\LuaScriptBuilder;
7+
use yiiunit\extensions\redis\base\ActiveRecordTestTrait;
78
use yiiunit\extensions\redis\data\ar\ActiveRecord;
89
use yiiunit\extensions\redis\data\ar\Customer;
910
use yiiunit\extensions\redis\data\ar\OrderItem;
1011
use yiiunit\extensions\redis\data\ar\Order;
1112
use yiiunit\extensions\redis\data\ar\Item;
1213
use yiiunit\extensions\redis\data\ar\OrderItemWithNullFK;
1314
use yiiunit\extensions\redis\data\ar\OrderWithNullFK;
14-
use yiiunit\framework\ar\ActiveRecordTestTrait;
1515

1616
/**
1717
* @group redis
@@ -68,7 +68,7 @@ public function getOrderItemWithNullFKmClass()
6868
return OrderItemWithNullFK::className();
6969
}
7070

71-
public function setUp()
71+
public function setUp(): void
7272
{
7373
parent::setUp();
7474
ActiveRecord::$db = $this->getConnection();
@@ -539,10 +539,10 @@ public function testValueEscapingInWhere($filterWithInjection, $expectedStrings,
539539
$script = $lua->buildOne($query);
540540

541541
foreach($expectedStrings as $string) {
542-
$this->assertContains($string, $script);
542+
$this->assertStringContainsString($string, $script);
543543
}
544544
foreach($unexpectedStrings as $string) {
545-
$this->assertNotContains($string, $script);
545+
$this->assertStringNotContainsString($string, $script);
546546
}
547547
}
548548

@@ -594,10 +594,10 @@ public function testValueEscapingInFindByCondition($filterWithInjection, $expect
594594
$script = $lua->buildOne($query);
595595

596596
foreach($expectedStrings as $string) {
597-
$this->assertContains($string, $script);
597+
$this->assertStringContainsString($string, $script);
598598
}
599599
foreach($unexpectedStrings as $string) {
600-
$this->assertNotContains($string, $script);
600+
$this->assertStringNotContainsString($string, $script);
601601
}
602602
// ensure injected FLUSHALL call did not succeed
603603
$query->one();

tests/RedisCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
use yii\redis\Cache;
66
use yii\redis\Connection;
7-
use yiiunit\framework\caching\CacheTestCase;
7+
use yiiunit\extensions\redis\base\AbstractCacheTestCase;
88

99
/**
1010
* Class for testing redis cache backend
1111
* @group redis
1212
* @group caching
1313
*/
14-
class RedisCacheTest extends CacheTestCase
14+
class RedisCacheTest extends AbstractCacheTestCase
1515
{
1616
private $_cacheInstance;
1717

0 commit comments

Comments
 (0)