Skip to content

Commit

Permalink
Merge pull request #13 from ray-di/fix-ci
Browse files Browse the repository at this point in the history
Improvement of cache adapter
  • Loading branch information
koriym authored Oct 7, 2022
2 parents 63a6d8a + 02824c1 commit b2717a3
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 12 deletions.
73 changes: 67 additions & 6 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand All @@ -24,7 +25,7 @@
},
"autoload": {
"psr-4": {
"Ray\\PsrCacheModule\\": ["src/"]
"Ray\\PsrCacheModule\\": ["src/", "src-deprecated"]
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
bootstrap="tests/bootstrap.php">
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Annotation/CacheDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute, Qualifier]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD), Qualifier]
final class CacheDir
{
/** @var string */
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/CacheNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute, Qualifier]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD), Qualifier]
final class CacheNamespace
{
/** @var string */
Expand Down
8 changes: 8 additions & 0 deletions src/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Ray\PsrCacheModule;

use Ray\PsrCacheModule\Annotation\CacheDir;
use Ray\PsrCacheModule\Annotation\CacheNamespace;
use Serializable;
use Symfony\Component\Cache\Adapter\FilesystemAdapter as OriginAdapter;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
Expand All @@ -14,6 +16,12 @@ class FilesystemAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

/**
* @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();
Expand Down
5 changes: 5 additions & 0 deletions src/PhpFileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Ray\PsrCacheModule;

use Ray\PsrCacheModule\Annotation\CacheNamespace;
use Serializable;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter as OriginAdapter;

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Psr6RedisModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 17 additions & 0 deletions tests/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
10 changes: 10 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Koriym\Attributes\AttributeReader;
use Ray\ServiceLocator\ServiceLocator;

if (PHP_MAJOR_VERSION >= 8) {
ServiceLocator::setReader(new AttributeReader());
}

0 comments on commit b2717a3

Please sign in to comment.