Skip to content

Supports serializable TagAwareAdapter #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- highest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
Expand All @@ -50,7 +50,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?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="tests/bootstrap.php">
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd">
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
Expand Down
5 changes: 3 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/tools/vendor/vimeo/psalm/config.xsd"
phpVersion="8.2"
findUnusedBaselineEntry="false"
findUnusedCode="false"
Expand All @@ -13,10 +12,12 @@
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/Php73BcSerializableTrait.php" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MethodSignatureMismatch errorLevel="suppress" />
<UnimplementedAbstractMethod errorLevel="suppress" />
<MissingOverrideAttribute errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function func_get_args;

/** @psalm-suppress PropertyNotSetInConstructor */
class ApcuAdapter extends OriginAdapter implements Serializable
final class ApcuAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/LogicException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace Ray\PsrCacheModule\Exception;

class LogicException extends \LogicException
final class LogicException extends \LogicException
{
}
2 changes: 1 addition & 1 deletion src/Exception/RedisConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use RuntimeException;

class RedisConnectionException extends RuntimeException
final class RedisConnectionException extends RuntimeException
{
}
2 changes: 1 addition & 1 deletion src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace Ray\PsrCacheModule\Exception;

class RuntimeException extends \RuntimeException
final class RuntimeException extends \RuntimeException
{
}
2 changes: 1 addition & 1 deletion src/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use function func_get_args;

/** @psalm-suppress PropertyNotSetInConstructor */
class FilesystemAdapter extends OriginAdapter implements Serializable
final class FilesystemAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function func_get_args;

/** @psalm-suppress PropertyNotSetInConstructor */
class MemcachedAdapter extends OriginAdapter implements Serializable
final class MemcachedAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

Expand Down
6 changes: 2 additions & 4 deletions src/MemcachedProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Ray\PsrCacheModule\Annotation\MemcacheConfig;

/** @implements ProviderInterface<Memcached> */
class MemcachedProvider implements ProviderInterface
final class MemcachedProvider implements ProviderInterface
{
/**
* @param array<array<string>> $servers
Expand All @@ -26,9 +26,7 @@ public function __construct(
) {
}

/**
* {@inheritdoc}
*/
/** {@inheritDoc}*/
public function get(): Memcached
{
$memcache = new Memcached();
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function func_get_args;

/** @psalm-suppress PropertyNotSetInConstructor */
class PhpFileAdapter extends OriginAdapter implements Serializable
final class PhpFileAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use function func_get_args;

/** @psalm-suppress PropertyNotSetInConstructor */
class RedisAdapter extends OriginAdapter implements Serializable
final class RedisAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

Expand Down
6 changes: 2 additions & 4 deletions src/RedisProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function sprintf;

/** @implements ProviderInterface<Redis> */
class RedisProvider implements ProviderInterface
final class RedisProvider implements ProviderInterface
{
/**
* @param list<string> $server
Expand All @@ -24,9 +24,7 @@ public function __construct(private array $server)
{
}

/**
* {@inheritdoc}
*/
/** {@inheritDoc}*/
public function get(): Redis
{
$redis = new Redis();
Expand Down
27 changes: 27 additions & 0 deletions src/TagAwareAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Ray\PsrCacheModule;

use Serializable;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\TagAwareAdapter as OriginAdapter;

use function func_get_args;

/** @psalm-suppress PropertyNotSetInConstructor */
final class TagAwareAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

public function __construct(
AdapterInterface $itemsPool,
AdapterInterface|null $tagsPool = null,
float $knownTagVersionsTtl = 0.15,
) {
$this->args = func_get_args();

parent::__construct($itemsPool, $tagsPool, $knownTagVersionsTtl);
}
}
10 changes: 2 additions & 8 deletions tests/ApcuAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

class ApcuAdapterTest extends TestCase
{
public function testSerialize(): string
public function testSerialize(): void
{
$string = serialize(new ApcuAdapter());
$this->assertIsString($string);
$this->assertNotEmpty($string);

return $string;
}

/** @depends testSerialize */
public function testUnserialize(string $string): void
{
$this->assertInstanceOf(ApcuAdapter::class, unserialize($string));
}
}
10 changes: 2 additions & 8 deletions tests/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@

class FilesystemAdapterTest extends TestCase
{
public function testSerialize(): string
public function testSerialize(): void
{
$string = serialize(new FilesystemAdapter());
$this->assertIsString($string);
$this->assertNotEmpty($string);

return $string;
}

/** @depends testSerialize */
public function testUnserialize(string $string): void
{
$this->assertInstanceOf(FilesystemAdapter::class, unserialize($string));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/MemcachedAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testSerialize(): array
$foo = $adapter->get('foo', static fn (ItemInterface $item) => '_no_serve_');
$this->assertSame('foobar', $foo);
$string = serialize($adapter);
$this->assertIsString($string);
$this->assertNotEmpty($string);

return [$string, $adapter];
}
Expand Down
10 changes: 2 additions & 8 deletions tests/PhpFileAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

class PhpFileAdapterTest extends TestCase
{
public function testSerialize(): string
public function testSerialize(): void
{
$string = serialize(new PhpFileAdapter());
$this->assertIsString($string);
$this->assertNotEmpty($string);

return $string;
}

/** @depends testSerialize */
public function testUnserialize(string $string): void
{
$this->assertInstanceOf(PhpFileAdapter::class, unserialize($string));
}
}
2 changes: 1 addition & 1 deletion tests/RedisAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testSerialize(): array
$foo = $adapter->get('foo', static fn (ItemInterface $item) => '_no_serve_');
$this->assertSame('foobar', $foo);
$string = serialize($adapter);
$this->assertIsString($string);
$this->assertNotEmpty($string);

return [$string, $adapter];
}
Expand Down
25 changes: 25 additions & 0 deletions tests/TagAwareAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Ray\PsrCacheModule;

use PHPUnit\Framework\TestCase;

use function serialize;
use function unserialize;

class TagAwareAdapterTest extends TestCase
{
public function testSerialize(): string
{
$adapter = new ApcuAdapter();
$string = serialize(new TagAwareAdapter($adapter, $adapter));
$this->assertNotSame('', $string, 'Serialize result should not be empty');

$unserialized = unserialize($string);
$this->assertInstanceOf(TagAwareAdapter::class, $unserialized);

return $string;
}
}
10 changes: 0 additions & 10 deletions tests/bootstrap.php

This file was deleted.

16 changes: 7 additions & 9 deletions vendor-bin/tools/composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"bamarni/composer-bin-plugin": true
}
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"require-dev": {
"vimeo/psalm": "^5.6 || dev-master",
"psalm/plugin-phpunit": "^0.18.4",
"phpstan/phpstan": "^1.9",
"squizlabs/php_codesniffer": "^3.7",
"doctrine/coding-standard": "^11.1",
"phpmd/phpmd": "^2.13"
"doctrine/coding-standard": "^12.0",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^2.0",
"vimeo/psalm": "^5.26 || dev-master"
}
}
Loading
Loading