diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml
index e409cdb..fa40028 100644
--- a/.github/workflows/bc.yml
+++ b/.github/workflows/bc.yml
@@ -29,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
- ['8.0']
+ ['8.1']
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e96052e..05e7b40 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -31,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
- ['8.0', '8.1', '8.2', '8.3']
+ ['8.1', '8.2', '8.3']
diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml
index 5473ec9..a857bce 100644
--- a/.github/workflows/composer-require-checker.yml
+++ b/.github/workflows/composer-require-checker.yml
@@ -31,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
- ['8.0', '8.1', '8.2', '8.3']
+ ['8.1', '8.2', '8.3']
diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml
index e34190e..e33eca8 100644
--- a/.github/workflows/static.yml
+++ b/.github/workflows/static.yml
@@ -30,11 +30,3 @@ jobs:
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3']
- psalm80:
- uses: yiisoft/actions/.github/workflows/psalm.yml@master
- with:
- psalm-config: psalm80.xml
- os: >-
- ['ubuntu-latest']
- php: >-
- ['8.0']
diff --git a/.gitignore b/.gitignore
index 4881919..04a6faa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,12 +23,10 @@ composer.phar
# Mac DS_Store Files
.DS_Store
-# phpunit itself is not needed
-phpunit.phar
-# local phpunit config
+# PHPUnit
+/phpunit.phar
/phpunit.xml
-# phpunit cache
-.phpunit.result.cache
+/.phpunit.cache
# Phan
analysis.txt
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a42ccaa..d2870f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
## 3.2.1 under development
-- no changes in this release.
+- Сhg #90: Bump minimal required PHP version to 8.1 and minor refactoring (@vjik)
## 3.2.0 January 13, 2025
diff --git a/composer.json b/composer.json
index 31e6c08..26001dc 100644
--- a/composer.json
+++ b/composer.json
@@ -30,19 +30,19 @@
}
],
"require": {
- "php": "^8.0",
+ "php": "^8.1",
"psr/simple-cache": "^2.0|^3.0"
},
"require-dev": {
- "maglnet/composer-require-checker": "^4.4",
- "php-mock/php-mock-phpunit": "^2.6",
- "phpunit/phpunit": "^9.5",
- "rector/rector": "^2.0",
- "roave/infection-static-analysis-plugin": "^1.16",
- "spatie/phpunit-watcher": "^1.23",
- "vimeo/psalm": "^4.30|^5.21",
+ "maglnet/composer-require-checker": "^4.7.1",
+ "php-mock/php-mock-phpunit": "^2.10",
+ "phpunit/phpunit": "^10.5.45",
+ "rector/rector": "^2.0.9",
+ "roave/infection-static-analysis-plugin": "^1.35",
+ "spatie/phpunit-watcher": "^1.24",
+ "vimeo/psalm": "^5.26.1",
"yiisoft/aliases": "^3.0",
- "yiisoft/di": "^1.2"
+ "yiisoft/di": "^1.3"
},
"autoload": {
"psr-4": {
@@ -68,6 +68,7 @@
},
"config": {
"sort-packages": true,
+ "bump-after-update": "dev",
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 6f414fe..56c156e 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,30 +1,31 @@
-
-
-
+ colors="true"
+ displayDetailsOnPhpunitDeprecations="true"
+>
-
+
./tests
-
+
- ./src
+ ./src
-
+
diff --git a/psalm80.xml b/psalm80.xml
deleted file mode 100644
index d091d59..0000000
--- a/psalm80.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/rector.php b/rector.php
index 63713ce..1f8a952 100644
--- a/rector.php
+++ b/rector.php
@@ -4,19 +4,19 @@
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
-use Rector\Set\ValueObject\LevelSetList;
+use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
+use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
-return static function (RectorConfig $rectorConfig): void {
- $rectorConfig->paths([
+return RectorConfig::configure()
+ ->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
+ ])
+ ->withPhpSets(php81: true)
+ ->withRules([
+ InlineConstructorDefaultToPropertyRector::class,
+ ])
+ ->withSkip([
+ ClosureToArrowFunctionRector::class,
+ NullToStrictStringFuncCallArgRector::class,
]);
-
- // register a single rule
- $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
-
- // define sets of rules
- $rectorConfig->sets([
- LevelSetList::UP_TO_PHP_80,
- ]);
-};
diff --git a/tests/FileCacheTest.php b/tests/FileCacheTest.php
index a91ab1e..9d4e853 100644
--- a/tests/FileCacheTest.php
+++ b/tests/FileCacheTest.php
@@ -8,11 +8,10 @@
use ArrayIterator;
use DateInterval;
-use Exception;
use IteratorAggregate;
use phpmock\phpunit\PHPMock;
+use PHPUnit\Framework\Attributes\DataProvider;
use Psr\SimpleCache\InvalidArgumentException;
-use ReflectionException;
use Yiisoft\Cache\File\CacheException;
use Yiisoft\Cache\File\FileCache;
use Yiisoft\Cache\File\MockHelper;
@@ -58,14 +57,7 @@ protected function tearDown(): void
$this->removeDirectory(self::RUNTIME_DIRECTORY);
}
- /**
- * @dataProvider dataProvider
- *
- * @param $key
- * @param $value
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProvider')]
public function testSet($key, $value): void
{
for ($i = 0; $i < 2; $i++) {
@@ -73,14 +65,7 @@ public function testSet($key, $value): void
}
}
- /**
- * @dataProvider dataProvider
- *
- * @param $key
- * @param $value
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProvider')]
public function testGet($key, $value): void
{
$this->cache->set($key, $value);
@@ -89,14 +74,7 @@ public function testGet($key, $value): void
$this->assertSameExceptObject($value, $valueFromCache);
}
- /**
- * @dataProvider dataProvider
- *
- * @param $key
- * @param $value
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProvider')]
public function testValueInCacheCannotBeChanged($key, $value): void
{
$this->cache->set($key, $value);
@@ -113,14 +91,7 @@ public function testValueInCacheCannotBeChanged($key, $value): void
}
}
- /**
- * @dataProvider dataProvider
- *
- * @param $key
- * @param $value
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProvider')]
public function testHas($key, $value): void
{
$this->cache->set($key, $value);
@@ -138,14 +109,7 @@ public function testGetNonExistent(): void
$this->assertNull($this->cache->get('non_existent_key'));
}
- /**
- * @dataProvider dataProvider
- *
- * @param $key
- * @param $value
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProvider')]
public function testDelete($key, $value): void
{
$this->cache->set($key, $value);
@@ -155,14 +119,7 @@ public function testDelete($key, $value): void
$this->assertNull($this->cache->get($key));
}
- /**
- * @dataProvider dataProvider
- *
- * @param $key
- * @param $value
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProvider')]
public function testClear($key, $value): void
{
$cache = $this->prepare($this->cache);
@@ -171,11 +128,7 @@ public function testClear($key, $value): void
$this->assertNull($cache->get($key));
}
- /**
- * @dataProvider dataProviderSetMultiple
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('dataProviderSetMultiple')]
public function testSetMultiple(?int $ttl): void
{
$data = $this->getDataProviderData();
@@ -189,7 +142,7 @@ public function testSetMultiple(?int $ttl): void
/**
* @return array testing multiSet with and without expiry
*/
- public function dataProviderSetMultiple(): array
+ public static function dataProviderSetMultiple(): array
{
return [
[null],
@@ -234,11 +187,7 @@ public function testZeroAndNegativeTtl(): void
$this->assertFalse($this->cache->has('b'));
}
- /**
- * @dataProvider dataProviderNormalizeTtl
- *
- * @throws ReflectionException
- */
+ #[DataProvider('dataProviderNormalizeTtl')]
public function testNormalizeTtl(mixed $ttl, mixed $expectedResult): void
{
$this->assertSameExceptObject($expectedResult, $this->invokeMethod($this->cache, 'normalizeTtl', [$ttl]));
@@ -247,11 +196,9 @@ public function testNormalizeTtl(mixed $ttl, mixed $expectedResult): void
/**
* Data provider for {@see testNormalizeTtl()}
*
- * @throws Exception
- *
* @return array test data
*/
- public function dataProviderNormalizeTtl(): array
+ public static function dataProviderNormalizeTtl(): array
{
return [
[123, 123],
@@ -263,11 +210,7 @@ public function dataProviderNormalizeTtl(): array
];
}
- /**
- * @dataProvider ttlToExpirationProvider
- *
- * @throws ReflectionException
- */
+ #[DataProvider('ttlToExpirationProvider')]
public function testTtlToExpiration(mixed $ttl, mixed $expected): void
{
if ($expected === 'calculate_expiration') {
@@ -283,7 +226,7 @@ public function testTtlToExpiration(mixed $ttl, mixed $expected): void
$this->assertSameExceptObject($expected, $this->invokeMethod($this->cache, 'ttlToExpiration', [$ttl]));
}
- public function ttlToExpirationProvider(): array
+ public static function ttlToExpirationProvider(): array
{
return [
[3, 'calculate_expiration'],
@@ -294,11 +237,7 @@ public function ttlToExpirationProvider(): array
];
}
- /**
- * @dataProvider iterableProvider
- *
- * @throws InvalidArgumentException
- */
+ #[DataProvider('iterableProvider')]
public function testValuesAsIterable(array $array, iterable $iterable): void
{
$this->cache->setMultiple($iterable);
@@ -306,7 +245,7 @@ public function testValuesAsIterable(array $array, iterable $iterable): void
$this->assertSameExceptObject($array, $this->cache->getMultiple(array_keys($array)));
}
- public function iterableProvider(): array
+ public static function iterableProvider(): array
{
return [
'array' => [
@@ -350,7 +289,7 @@ public function testExpire(): void
* We have to on separate process because of PHPMock not being able to mock a function that
* was already called.
*
- * @runInSeparateProcess
+ * runInSeparateProcess
*/
public function testCacheRenewalOnDifferentOwnership(): void
{
@@ -479,9 +418,7 @@ public function testDirectoryLevel(): void
$this->assertPathEquals(__DIR__ . '/runtime/cache/a.bin', $cacheFile);
}
- /**
- * @dataProvider nestedDirectoriesDataProvider
- */
+ #[DataProvider('nestedDirectoriesDataProvider')]
public function testDirectoryLevelWithSubdirs(int $directoryLevel, string $key, string $expectedPath): void
{
$cache = $this->cache->withDirectoryLevel($directoryLevel);
@@ -492,7 +429,7 @@ public function testDirectoryLevelWithSubdirs(int $directoryLevel, string $key,
$this->assertPathEquals(__DIR__ . "/runtime/cache/$expectedPath.bin", $cacheFile);
}
- public function nestedDirectoriesDataProvider(): array
+ public static function nestedDirectoriesDataProvider(): array
{
return [
'single level' => [1, '0123456789', '01/0123456789'],
@@ -545,7 +482,7 @@ public function testSetThrowExceptionForInvalidCacheDirectory(): void
$cache->set('key', 'value');
}
- public function invalidKeyProvider(): array
+ public static function invalidKeyProvider(): array
{
return [
'psr-reserved' => ['{}()/\@:'],
@@ -553,54 +490,42 @@ public function invalidKeyProvider(): array
];
}
- /**
- * @dataProvider invalidKeyProvider
- */
+ #[DataProvider('invalidKeyProvider')]
public function testGetThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->get($key);
}
- /**
- * @dataProvider invalidKeyProvider
- */
+ #[DataProvider('invalidKeyProvider')]
public function testSetThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->set($key, 'value');
}
- /**
- * @dataProvider invalidKeyProvider
- */
+ #[DataProvider('invalidKeyProvider')]
public function testDeleteThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->delete($key);
}
- /**
- * @dataProvider invalidKeyProvider
- */
+ #[DataProvider('invalidKeyProvider')]
public function testGetMultipleThrowExceptionForInvalidKeys(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->getMultiple([$key]);
}
- /**
- * @dataProvider invalidKeyProvider
- */
+ #[DataProvider('invalidKeyProvider')]
public function testDeleteMultipleThrowExceptionForInvalidKeys(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->deleteMultiple([$key]);
}
- /**
- * @dataProvider invalidKeyProvider
- */
+ #[DataProvider('invalidKeyProvider')]
public function testHasThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
diff --git a/tests/TestCase.php b/tests/TestCase.php
index f99a6fd..affe4b7 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -5,7 +5,6 @@
namespace Yiisoft\Cache\File\Tests;
use Psr\SimpleCache\CacheInterface;
-use Psr\SimpleCache\InvalidArgumentException;
use ReflectionClass;
use ReflectionException;
use ReflectionObject;
@@ -87,7 +86,7 @@ protected function getInaccessibleProperty(object $object, string $propertyName,
return $result;
}
- public function dataProvider(): array
+ public static function dataProvider(): array
{
$object = new stdClass();
$object->test_field = 'test_value';
@@ -121,19 +120,13 @@ public function getDataProviderData(string $keyPrefix = ''): array
/**
* This function configures given cache to match some expectations
- *
- * @throws InvalidArgumentException
- *
- * @return CacheInterface
*/
public function prepare(CacheInterface $cache): CacheInterface
{
$cache->clear();
- $data = $this->dataProvider();
-
- foreach ($data as $datum) {
- $cache->set($datum[0], $datum[1]);
+ foreach (self::dataProvider() as $data) {
+ $cache->set($data[0], $data[1]);
}
return $cache;