Skip to content

Commit ac3b44b

Browse files
Update phpunit 10, fix minor corrections. (#54)
1 parent 6b7e8f3 commit ac3b44b

21 files changed

+280
-131
lines changed

.github/workflows/mutation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- ubuntu-latest
3737

3838
php:
39-
- 8.1
39+
- 8.0
4040

4141
services:
4242
mssql:

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ This package implements database-based [PSR-16](https://www.php-fig.org/psr/psr-
1818

1919
## Support databases:
2020

21-
|Packages| PHP | Versions | CI-Actions
22-
|:------:|:----:|:------------------------:|:-----------:|
23-
[[db-mssql]](https://github.com/yiisoft/db-mssql)|**8.0 - 8.1**| **2017 - 2019**|[![mssql](https://github.com/yiisoft/cache-db/actions/workflows/mssql.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/mssql.yml) | |
24-
[[db-mysql]](https://github.com/yiisoft/db-mysql)|**8.0 - 8.1**| **5.7 - 8.0**|[![mysql](https://github.com/yiisoft/cache-db/actions/workflows/mysql.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/mysql.yml)|
25-
[[db-oracle]](https://github.com/yiisoft/db-oracle)|**8.0 - 8.1**| **11c - 12c**|[![oracle](https://github.com/yiisoft/cache-db/actions/workflows/oracle.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/oracle.yml)|
26-
|[[db-pgsql]](https://github.com/yiisoft/db-pgsql)|**8.0 - 8.1**| **9.0 - 14.0**|[![pgsql](https://github.com/yiisoft/cache-db/actions/workflows/pgsql.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/pgsql.yml)|
27-
|[[db-sqlite]](https://github.com/yiisoft/db-sqlite)|**8,0 - 8.1**| **3:latest**|[![sqlite](https://github.com/yiisoft/cache-db/actions/workflows/sqlite.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/sqlite.yml)|
21+
| Packages | PHP | Versions | CI-Actions |
22+
|:---------------------------------------------------:|:-------------:|:---------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------:|
23+
| [[db-mssql]](https://github.com/yiisoft/db-mssql) | **8.0 - 8.1** | **2017 - 2019** | [![mssql](https://github.com/yiisoft/cache-db/actions/workflows/mssql.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/mssql.yml) | |
24+
| [[db-mysql]](https://github.com/yiisoft/db-mysql) | **8.0 - 8.1** | **5.7 - 8.0** | [![mysql](https://github.com/yiisoft/cache-db/actions/workflows/mysql.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/mysql.yml) |
25+
| [[db-oracle]](https://github.com/yiisoft/db-oracle) | **8.0 - 8.1** | **11c - 21c** | [![oracle](https://github.com/yiisoft/cache-db/actions/workflows/oracle.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/oracle.yml) |
26+
| [[db-pgsql]](https://github.com/yiisoft/db-pgsql) | **8.0 - 8.1** | **9.0 - 15.0** | [![pgsql](https://github.com/yiisoft/cache-db/actions/workflows/pgsql.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/pgsql.yml) |
27+
| [[db-sqlite]](https://github.com/yiisoft/db-sqlite) | **8,0 - 8.1** | **3:latest** | [![sqlite](https://github.com/yiisoft/cache-db/actions/workflows/sqlite.yml/badge.svg)](https://github.com/yiisoft/cache-db/actions/workflows/sqlite.yml) |
2828

2929
## Requirements
3030

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
},
3434
"require-dev": {
3535
"maglnet/composer-require-checker": "^4.2",
36-
"phpunit/phpunit": "^9.5",
36+
"phpunit/phpunit": "^9.6|^10.0",
3737
"rector/rector": "^0.15.20",
38-
"roave/infection-static-analysis-plugin": "^1.16",
38+
"roave/infection-static-analysis-plugin": "^1.25|^1.29",
3939
"spatie/phpunit-watcher": "^1.23",
40-
"vimeo/psalm": "^4.18",
40+
"vimeo/psalm": "^4.8|^5.6",
4141
"yiisoft/cache": "^3.0",
4242
"yiisoft/log": "^2.0"
4343
},

phpunit.xml.dist

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,31 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit bootstrap="vendor/autoload.php"
4-
colors="true"
5-
verbose="true"
6-
failOnRisky="true"
7-
failOnWarning="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
stopOnFailure="false"
12-
executionOrder="random"
13-
resolveDependencies="true"
14-
backupGlobals="false"
15-
>
16-
<php>
17-
<ini name="error_reporting" value="-1"/>
18-
</php>
19-
20-
<coverage>
21-
<include>
22-
<directory>./src</directory>
23-
</include>
24-
</coverage>
25-
<testsuites>
26-
<testsuite name="CacheDb">
27-
<directory>./tests</directory>
28-
</testsuite>
29-
<testsuite name="Mssql">
30-
<directory>./tests/Mssql</directory>
31-
</testsuite>
32-
<testsuite name="Mysql">
33-
<directory>./tests/Mysql</directory>
34-
</testsuite>
35-
<testsuite name="Oracle">
36-
<directory>./tests/Oracle</directory>
37-
</testsuite>
38-
<testsuite name="Pgsql">
39-
<directory>./tests/Pgsql</directory>
40-
</testsuite>
41-
<testsuite name="Sqlite">
42-
<directory>./tests/Sqlite</directory>
43-
</testsuite>
44-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="true" stopOnFailure="false" executionOrder="random" resolveDependencies="true" backupGlobals="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
3+
<php>
4+
<ini name="error_reporting" value="-1"/>
5+
</php>
6+
<coverage>
7+
<include>
8+
<directory>./src</directory>
9+
</include>
10+
</coverage>
11+
<testsuites>
12+
<testsuite name="CacheDb">
13+
<directory>./tests/Driver</directory>
14+
</testsuite>
15+
<testsuite name="Mssql">
16+
<directory>./tests/Driver/Mssql</directory>
17+
</testsuite>
18+
<testsuite name="Mysql">
19+
<directory>./tests/Driver/Mysql</directory>
20+
</testsuite>
21+
<testsuite name="Oracle">
22+
<directory>./tests/Driver/Oracle</directory>
23+
</testsuite>
24+
<testsuite name="Pgsql">
25+
<directory>./tests/Driver/Pgsql</directory>
26+
</testsuite>
27+
<testsuite name="Sqlite">
28+
<directory>./tests/Driver/Sqlite</directory>
29+
</testsuite>
30+
</testsuites>
4531
</phpunit>

psalm.xml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="1"
4-
resolveFromConfigFile="true"
5-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6-
xmlns="https://getpsalm.org/schema/config"
7-
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
3+
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
6+
resolveFromConfigFile="true"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
810
>
9-
<projectFiles>
10-
<directory name="src" />
11-
<ignoreFiles>
12-
<directory name="vendor" />
13-
</ignoreFiles>
14-
</projectFiles>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="vendor" />
15+
</ignoreFiles>
16+
</projectFiles>
1517
</psalm>

src/DbCache.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Psr\Log\LoggerAwareTrait;
1111
use Psr\Log\LogLevel;
1212
use Psr\SimpleCache\CacheInterface;
13+
use Psr\SimpleCache\InvalidArgumentException;
1314
use Throwable;
1415
use Traversable;
1516
use Yiisoft\Db\Command\Param;
@@ -73,7 +74,7 @@ public function get(string $key, mixed $default = null): mixed
7374
{
7475
$this->validateKey($key);
7576

76-
/** @var bool|float|int|string|null */
77+
/** @var bool|float|int|string|null $value */
7778
$value = $this->getData($key, ['data'], 'scalar');
7879

7980
return $value === false ? $default : unserialize((string) $value);
@@ -83,6 +84,8 @@ public function get(string $key, mixed $default = null): mixed
8384
* @param string $key The cache data ID.
8485
* @param mixed $value The cache data value.
8586
* @param DateInterval|int|string|null $ttl The cache data TTL.
87+
*
88+
* @throws InvalidArgumentException
8689
*/
8790
public function set(string $key, mixed $value, DateInterval|int|string|null $ttl = null): bool
8891
{
@@ -126,7 +129,7 @@ public function clear(): bool
126129

127130
public function getMultiple(iterable $keys, mixed $default = null): iterable
128131
{
129-
/** @psalm-var array<array-key,array-key> */
132+
/** @psalm-var array<array-key,array-key> $keys */
130133
$keys = $this->iterableToArray($keys);
131134
$this->validateKeys($keys);
132135
$values = array_fill_keys($keys, $default);
@@ -137,7 +140,7 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable
137140
$value['data'] = stream_get_contents($value['data']);
138141
}
139142

140-
/** @var string */
143+
/** @psalm-var string */
141144
$values[$value['id']] = unserialize((string) $value['data']);
142145
}
143146

@@ -148,14 +151,16 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable
148151
/**
149152
* @param iterable $values A list of key => value pairs for a multiple-set operation.
150153
* @param DateInterval|int|string|null $ttl The cache data TTL.
154+
*
155+
* @throws InvalidArgumentException
151156
*/
152157
public function setMultiple(iterable $values, DateInterval|int|string|null $ttl = null): bool
153158
{
154159
$ttl = $this->normalizeTtl($ttl);
155160
$values = $this->iterableToArray($values);
156161
$rows = $keys = [];
157162

158-
/** @var mixed $value */
163+
/** @psalm-var mixed $value */
159164
foreach ($values as $key => $value) {
160165
$key = (string) $key;
161166
$this->validateKey($key);
@@ -224,7 +229,7 @@ public function setLoggerMessageUpdate(string $value): void
224229
*
225230
* @param array|string $id One or more IDs for deleting data.
226231
* @param array $fields Selectable fields.
227-
* @param string $method Method of the returned data ( "all", "scalar", "exists").
232+
* @param string $method Method of the returned data ("all", "scalar", "exists").
228233
*
229234
* @return mixed The cache data.
230235
*/
@@ -243,7 +248,7 @@ private function getData(array|string $id, array $fields, string $method): mixed
243248
}
244249

245250
/**
246-
* Deletes a cache data from the database.
251+
* Deletes cache data from the database.
247252
*
248253
* @param array|bool|string $id One or more IDs for deleting data.
249254
*
@@ -336,24 +341,30 @@ private function isInfinityTtl(?int $ttl): bool
336341
}
337342

338343
/**
339-
* Converts iterable to array. If provided value is not iterable it throws an InvalidArgumentException.
344+
* Converts iterable to array. If provided value isn't iterable, it throws an InvalidArgumentException.
340345
*/
341346
private function iterableToArray(iterable $iterable): array
342347
{
343348
/** @psalm-suppress RedundantCast */
344349
return $iterable instanceof Traversable ? iterator_to_array($iterable) : (array) $iterable;
345350
}
346351

352+
/**
353+
* @throws InvalidArgumentException
354+
*/
347355
private function validateKey(mixed $key): void
348356
{
349357
if (!is_string($key) || $key === '' || strpbrk($key, '{}()/\@:')) {
350-
throw new InvalidArgumentException('Invalid key value.');
358+
throw new \Yiisoft\Cache\Db\InvalidArgumentException('Invalid key value.');
351359
}
352360
}
353361

362+
/**
363+
* @throws InvalidArgumentException
364+
*/
354365
private function validateKeys(array $keys): void
355366
{
356-
/** @var mixed $key */
367+
/** @psalm-var mixed $key */
357368
foreach ($keys as $key) {
358369
$this->validateKey($key);
359370
}

src/InvalidArgumentException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Yiisoft\Cache\Db;
66

7-
final class InvalidArgumentException extends \RuntimeException implements \Psr\SimpleCache\InvalidArgumentException
7+
use RuntimeException;
8+
9+
final class InvalidArgumentException extends RuntimeException implements \Psr\SimpleCache\InvalidArgumentException
810
{
911
}

src/Migration/M202101140204CreateCache.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Yiisoft\Cache\Db\Migration;
66

77
use Yiisoft\Cache\Db\DbCache;
8+
use Yiisoft\Db\Exception\InvalidConfigException;
9+
use Yiisoft\Db\Exception\NotSupportedException;
810
use Yiisoft\Yii\Db\Migration\Informer\MigrationInformerInterface;
911
use Yiisoft\Yii\Db\Migration\MigrationBuilder;
1012
use Yiisoft\Yii\Db\Migration\RevertibleMigrationInterface;
@@ -23,6 +25,10 @@ public function __construct(
2325
) {
2426
}
2527

28+
/**
29+
* @throws InvalidConfigException
30+
* @throws NotSupportedException
31+
*/
2632
public function up(MigrationBuilder $b): void
2733
{
2834
$builder = new MigrationBuilder($this->cache->getDb(), $this->migrationInformer);
@@ -37,6 +43,10 @@ public function up(MigrationBuilder $b): void
3743
]);
3844
}
3945

46+
/**
47+
* @throws InvalidConfigException
48+
* @throws NotSupportedException
49+
*/
4050
public function down(MigrationBuilder $b): void
4151
{
4252
$builder = new MigrationBuilder($this->cache->getDb(), $this->migrationInformer);

0 commit comments

Comments
 (0)