From f6158997d2210db3f61ad496b6dd60b3feeca727 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 27 Jul 2022 18:53:25 +0900 Subject: [PATCH 1/8] Revert continuous-integration.yml --- .github/workflows/continuous-integration.yml | 73 ++++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 6f7dfeb..25c3a17 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -6,9 +6,70 @@ on: workflow_dispatch: jobs: - ci: - uses: ray-di/.github/.github/workflows/continuous-integration.yml@next_stable - with: - old_stable: '["7.3", "7.4", "8.0"]' - current_stable: 8.1 - next_stable: 8.2 + phpunit: + name: PHPUnit + runs-on: ubuntu-latest + services: + memcached: + image: memcached + ports: + - 11211:11211 + options: --health-cmd "timeout 5 bash -c 'cat < /dev/null > /dev/udp/127.0.0.1/11211'" --health-interval=10s --health-timeout=5s --health-retries=3 + redis: + image: redis + ports: + - 6379:6379 + options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3 + strategy: + matrix: + operating-system: + - ubuntu-latest + - windows-latest + php-version: + - '7.3' + - '7.4' + - '8.0' + - '8.1' + dependencies: + - lowest + - highest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: memcache, memcached, redis + coverage: pcov + ini-values: zend.assertions=1 + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install lowest dependencies + if: ${{ matrix.dependencies == 'lowest' }} + run: >- + composer update --prefer-lowest --no-interaction --no-progress + --no-suggest + + - name: Install highest dependencies + if: ${{ matrix.dependencies == 'highest' }} + run: composer update --no-interaction --no-progress --no-suggest + + - name: Run test suite + run: ./vendor/bin/phpunit --coverage-clover=coverage.xml + + - name: Upload coverage report + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml From bc9f89d6151851f81bda1ae26ce8739d4a1d4e42 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 27 Jul 2022 21:45:32 +0900 Subject: [PATCH 2/8] Test with attribute reader in php8 --- phpunit.xml.dist | 2 +- tests/bootstrap.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d87ac03..cc4d590 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ + bootstrap="tests/bootstrap.php"> diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..9d90486 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,10 @@ += 8) { + ServiceLocator::setReader(new AttributeReader()); +} From 02a8fee8c7520a5918ca9e508df6d8489f2b1fa2 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 27 Jul 2022 21:46:02 +0900 Subject: [PATCH 3/8] Add namespace --- src/FilesystemAdapter.php | 5 +++++ src/PhpFileAdapter.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/FilesystemAdapter.php b/src/FilesystemAdapter.php index 1bf8482..4083b03 100644 --- a/src/FilesystemAdapter.php +++ b/src/FilesystemAdapter.php @@ -4,6 +4,7 @@ namespace Ray\PsrCacheModule; +use Ray\PsrCacheModule\Annotation\CacheNamespace; use Serializable; use Symfony\Component\Cache\Adapter\FilesystemAdapter as OriginAdapter; use Symfony\Component\Cache\Marshaller\MarshallerInterface; @@ -14,6 +15,10 @@ class FilesystemAdapter extends OriginAdapter implements Serializable { use SerializableTrait; + /** + * @CacheNamespace("namespace") + */ + #[CacheNamespace('namespace')] public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, ?MarshallerInterface $marshaller = null) { $this->args = func_get_args(); diff --git a/src/PhpFileAdapter.php b/src/PhpFileAdapter.php index 76525c7..afcbc56 100644 --- a/src/PhpFileAdapter.php +++ b/src/PhpFileAdapter.php @@ -4,6 +4,7 @@ namespace Ray\PsrCacheModule; +use Ray\PsrCacheModule\Annotation\CacheNamespace; use Serializable; use Symfony\Component\Cache\Adapter\PhpFilesAdapter as OriginAdapter; @@ -13,6 +14,10 @@ class PhpFileAdapter extends OriginAdapter implements Serializable { use SerializableTrait; + /** + * @CacheNamespace("namespace") + */ + #[CacheNamespace('namespace')] public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, bool $appendOnly = false) { $this->args = func_get_args(); From 6433d93704b3e106e3b03c5dee631a1555aa795e Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 27 Jul 2022 21:46:29 +0900 Subject: [PATCH 4/8] Move to src-deprecated --- composer.json | 2 +- {src => src-deprecated}/LocalCacheProvider.php | 0 {src => src-deprecated}/Php73BcSerializableTrait.php | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) rename {src => src-deprecated}/LocalCacheProvider.php (100%) rename {src => src-deprecated}/Php73BcSerializableTrait.php (95%) diff --git a/composer.json b/composer.json index 2005962..2623870 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "autoload": { "psr-4": { - "Ray\\PsrCacheModule\\": ["src/"] + "Ray\\PsrCacheModule\\": ["src/", "src-deprecated"] } }, "autoload-dev": { diff --git a/src/LocalCacheProvider.php b/src-deprecated/LocalCacheProvider.php similarity index 100% rename from src/LocalCacheProvider.php rename to src-deprecated/LocalCacheProvider.php diff --git a/src/Php73BcSerializableTrait.php b/src-deprecated/Php73BcSerializableTrait.php similarity index 95% rename from src/Php73BcSerializableTrait.php rename to src-deprecated/Php73BcSerializableTrait.php index 29195f9..6018e54 100644 --- a/src/Php73BcSerializableTrait.php +++ b/src-deprecated/Php73BcSerializableTrait.php @@ -7,6 +7,9 @@ use function serialize; use function unserialize; +/** + * @deprecated + */ trait Php73BcSerializableTrait { /** From 247fc8f6c464054967a455ce023ff7243392db92 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 27 Jul 2022 21:46:41 +0900 Subject: [PATCH 5/8] Prefer ::class --- src/Psr6RedisModule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psr6RedisModule.php b/src/Psr6RedisModule.php index c50e5a7..48152e9 100644 --- a/src/Psr6RedisModule.php +++ b/src/Psr6RedisModule.php @@ -35,6 +35,6 @@ protected function configure(): void 'namespace' => CacheNamespace::class, ]); $this->bind()->annotatedWith(RedisConfig::class)->toInstance($this->server); - $this->bind('')->annotatedWith('Ray\PsrCacheModule\Annotation\RedisInstance')->toProvider(RedisProvider::class); + $this->bind('')->annotatedWith(RedisInstance::class)->toProvider(RedisProvider::class); } } From a58c6bff7e6eeccfd3ca9d81d133014726879685 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 28 Jul 2022 02:20:17 +0900 Subject: [PATCH 6/8] Require ray/aop to ensure SL works --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2623870..9cf5d42 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "ray/di": "^2.13.2", "symfony/cache": "^5.3.4", "doctrine/annotations": "^1.13", - "psr/simple-cache": "^1.0" + "psr/simple-cache": "^1.0", + "ray/aop": "^2.10.4" }, "require-dev": { "ext-redis": "*", From 07c029d338c22f7f084a190c1aba61ddecb5a3bd Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 28 Jul 2022 08:34:00 +0900 Subject: [PATCH 7/8] Create cachenamespace and cachrDir test for FileSystemAdapter --- src/Annotation/CacheDir.php | 2 +- src/Annotation/CacheNamespace.php | 2 +- src/FilesystemAdapter.php | 3 +++ tests/FilesystemAdapterTest.php | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Annotation/CacheDir.php b/src/Annotation/CacheDir.php index 94bc84c..325134c 100644 --- a/src/Annotation/CacheDir.php +++ b/src/Annotation/CacheDir.php @@ -13,7 +13,7 @@ * @Qualifier * @NamedArgumentConstructor */ -#[Attribute, Qualifier] +#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD), Qualifier] final class CacheDir { /** @var string */ diff --git a/src/Annotation/CacheNamespace.php b/src/Annotation/CacheNamespace.php index 2f72e40..d9943d8 100644 --- a/src/Annotation/CacheNamespace.php +++ b/src/Annotation/CacheNamespace.php @@ -13,7 +13,7 @@ * @Qualifier * @NamedArgumentConstructor */ -#[Attribute, Qualifier] +#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD), Qualifier] final class CacheNamespace { /** @var string */ diff --git a/src/FilesystemAdapter.php b/src/FilesystemAdapter.php index 4083b03..65138d0 100644 --- a/src/FilesystemAdapter.php +++ b/src/FilesystemAdapter.php @@ -4,6 +4,7 @@ namespace Ray\PsrCacheModule; +use Ray\PsrCacheModule\Annotation\CacheDir; use Ray\PsrCacheModule\Annotation\CacheNamespace; use Serializable; use Symfony\Component\Cache\Adapter\FilesystemAdapter as OriginAdapter; @@ -17,8 +18,10 @@ class FilesystemAdapter extends OriginAdapter implements Serializable /** * @CacheNamespace("namespace") + * @CacheDir("directory") */ #[CacheNamespace('namespace')] + #[CacheDir('directory')] public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, ?MarshallerInterface $marshaller = null) { $this->args = func_get_args(); diff --git a/tests/FilesystemAdapterTest.php b/tests/FilesystemAdapterTest.php index 1a74289..5ee1482 100644 --- a/tests/FilesystemAdapterTest.php +++ b/tests/FilesystemAdapterTest.php @@ -5,6 +5,9 @@ namespace Ray\PsrCacheModule; use PHPUnit\Framework\TestCase; +use Ray\Di\AbstractModule; +use Ray\Di\Injector; +use Symfony\Component\Cache\Adapter\AbstractAdapter; use function serialize; use function unserialize; @@ -26,4 +29,18 @@ public function testUnserialize(string $string): void { $this->assertInstanceOf(FilesystemAdapter::class, unserialize($string)); } + + public function testCacheNamespaceModule(): void + { + $injector = new Injector(new class extends AbstractModule{ + protected function configure(): void + { + $this->install(new CacheNamespaceModule('a')); + $this->install(new CacheDirModule('/tmp/a')); + $this->bind(AbstractAdapter::class)->to(FilesystemAdapter::class); + } + }); + $adapter = $injector->getInstance(AbstractAdapter::class); + $this->assertInstanceOf(FilesystemAdapter::class, $adapter); + } } From 02824c161b37a82fbe580c45c3b02cb1faf2c0c3 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 28 Jul 2022 08:49:41 +0900 Subject: [PATCH 8/8] Remove @deprecated from Php73BcSerializableTrait --- {src-deprecated => src}/Php73BcSerializableTrait.php | 3 --- 1 file changed, 3 deletions(-) rename {src-deprecated => src}/Php73BcSerializableTrait.php (95%) diff --git a/src-deprecated/Php73BcSerializableTrait.php b/src/Php73BcSerializableTrait.php similarity index 95% rename from src-deprecated/Php73BcSerializableTrait.php rename to src/Php73BcSerializableTrait.php index 6018e54..29195f9 100644 --- a/src-deprecated/Php73BcSerializableTrait.php +++ b/src/Php73BcSerializableTrait.php @@ -7,9 +7,6 @@ use function serialize; use function unserialize; -/** - * @deprecated - */ trait Php73BcSerializableTrait { /**