Skip to content

Commit

Permalink
Remove support for PHP 8.0 (#44)
Browse files Browse the repository at this point in the history
- Remove support for PHP 8.0
- Use Symfony 6.4 components for development
- Update PHPUnit to 10.5
- Fix tests
- Update documentation
- Update ramsey/composer-install github action
  • Loading branch information
hugo-goncalves-kununu authored Apr 8, 2024
1 parent c9d36ed commit d78fbcd
Show file tree
Hide file tree
Showing 41 changed files with 315 additions and 234 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto_assign_owner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Auto assign owner
uses: danielswensson/auto-assign-owner-action@v1.0.2
uses: danielswensson/auto-assign-owner-action@v1.0.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-version:
- 8.0
- 8.1
dependencies:
- highest

Expand All @@ -32,7 +32,7 @@ jobs:
coverage: xdebug

- name: Install Composer Dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: "--prefer-stable"
Expand All @@ -57,7 +57,7 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: build-8-highest-coverage
name: build-8.1-highest-coverage
path: tests/.results/

- name: Fix Code Coverage Paths
Expand Down
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
tests/.results
vendor
composer.lock
.idea/
.php_cs.cache
composer.lock
.phpunit.result.cache
.phpunit.cache
vendor/
tests/.results/
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
}
],
"require": {
"php": ">=8.0"
"php": ">=8.1"
},
"require-dev": {
"ext-json": "*",
"ext-igbinary": "*",
"ext-zlib": "*",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.5",
"kununu/scripts": ">=4.0",
"symfony/yaml": "^5.4",
"symfony/cache": "^5.4",
"symfony/yaml": "^6.4",
"symfony/cache": "^6.4",
"jms/serializer": "^3.28",
"symfony/serializer": "^5.4",
"symfony/property-access": "^5.4"
"symfony/serializer": "^6.4",
"symfony/property-access": "^6.4"
},
"suggest": {
"ext-igbinary": "To use IgBinary cache serializers",
Expand All @@ -53,8 +53,8 @@
}
},
"scripts": {
"test": "phpunit --no-coverage tests",
"test-coverage": "XDEBUG_MODE=coverage phpunit --coverage-clover tests/.results/coverage.xml --coverage-html tests/.results/html/ tests"
"test": "phpunit --no-coverage --no-logging --no-progress",
"test-coverage": "XDEBUG_MODE=coverage phpunit"
},
"scripts-descriptions": {
"test": "Run all tests",
Expand Down
34 changes: 28 additions & 6 deletions docs/cache-cleaner.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ So your cache cleaner class by tags should be instantiated with a `ProjectionRep

```php
public function __construct(
private ProjectionRepositoryInterface $projectionRepository,
private LoggerInterface $logger,
private string $logLevel = LogLevel::INFO
private readonly ProjectionRepositoryInterface $projectionRepository,
private readonly LoggerInterface $logger,
private readonly string $logLevel = LogLevel::INFO
);

abstract protected function getTags(): Tags;
Expand All @@ -38,6 +38,11 @@ abstract protected function getTags(): Tags;
Example:

```php
<?php
declare(strict_types=1);

namespace Kununu\Example;

use Kununu\Projections\CacheCleaner\CacheCleanerInterface;
use Kununu\Projections\CacheCleaner\AbstractCacheCleanerByTags;

Expand All @@ -54,7 +59,7 @@ final class MyCacheCleaner extends AbstractCacheCleanerByTags

final class MyClass
{
public function __construct(private CacheCleanerInterface $cacheCleaner)
public function __construct(private readonly CacheCleanerInterface $cacheCleaner)
{
}

Expand All @@ -81,14 +86,20 @@ Just make you test class extend it and override the `TAGS` constant and implemen
Example:

```php
<?php
declare(strict_types=1);

namespace Kununu\Example;

use Kununu\Projections\ProjectionRepositoryInterface;
use Kununu\Projections\TestCase\CacheCleaner\AbstractCacheCleanerTestCase;
use Psr\Log\LoggerInterface;

final class MyCacheCleanerTest extends AbstractCacheCleanerTestCase
{
protected const TAGS = ['my-tag1', 'my-tag2'];

abstract protected function getCacheCleaner(
protected function getCacheCleaner(
ProjectionRepositoryInterface $projectionRepository,
LoggerInterface $logger
): CacheCleanerInterface {
Expand All @@ -103,6 +114,13 @@ The `TAGS` constant must be the tags that you expect that your cache cleaner cla
For the example above we are expecting that `MyCacheCleaner::getTags` will return a `Tags` collection with the same tags defined in the constant, e.g.:

```php
<?php
declare(strict_types=1);

namespace Kununu\Example

use Kununu\Projections\CacheCleaner\AbstractCacheCleanerByTags;

final class MyCacheCleaner extends AbstractCacheCleanerByTags
{
protected function getTags(): Tags
Expand All @@ -121,11 +139,15 @@ This class is constructed by passing the desired instances of your classes that
Example:

```php
<?php
declare(strict_types=1);

namespace Kununu\Example

use Kununu\Projections\CacheCleaner\CacheCleanerInterface;
use Kununu\Projections\CacheCleaner\AbstractCacheCleanerByTags;

// Continuing our example, let's add more cache cleaners...

final class MySecondCacheCleaner extends AbstractCacheCleanerByTags
{
protected function getTags(): Tags
Expand Down
5 changes: 4 additions & 1 deletion docs/projection-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface ProjectionItemInterface
Here's an example of projection item:

```php
<?php
declare(strict_types=1);

namespace Kununu\Example;

use Kununu\Projections\ProjectionItemInterface;
Expand All @@ -25,7 +28,7 @@ final class ExampleProjectionItem implements ProjectionItemInterface
{
use ProjectionTagGenerator;

public function __construct(private string $id, private string $someValue)
public function __construct(private readonly string $id, private readonly string $someValue)
{
}

Expand Down
5 changes: 5 additions & 0 deletions docs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ protected function getAndCacheData(
An example:

```php
<?php
declare(strict_types=1);

namespace Kununu\Example;

use Kununu\Projections\ProjectionRepositoryInterface;
use Kununu\Projections\ProjectionItemIterableInterface;

Expand Down
5 changes: 4 additions & 1 deletion docs/symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Kununu\Example\MyProvider:
And inside the respective class we should depend only on the `ProjectionRepositoryInterface` interface instance to project/get/delete data from the cache.

```php
<?php
declare(strict_types=1);
namespace Kununu\Example;
use Kununu\Projections\ProjectionRepositoryInterface;
Expand All @@ -119,7 +122,7 @@ use Kununu\Projections\Tag\Tags;
final class MyProvider
{
public function __construct(private ProjectionRepositoryInterface $projectionRepository)
public function __construct(private readonly ProjectionRepositoryInterface $projectionRepository)
{
}
Expand Down
16 changes: 9 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/9.6/ -->
<!-- https://docs.phpunit.de/en/10.5/ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd" bootstrap="vendor/autoload.php"
colors="true" beStrictAboutChangesToGlobalState="true" testdox="true">
<coverage processUncoveredFiles="true">
<include>
<directory>src</directory>
</include>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php"
colors="true" beStrictAboutChangesToGlobalState="true" cacheDirectory=".phpunit.cache" testdox="true">
<coverage>
<report>
<clover outputFile="tests/.results/tests-clover.xml"/>
<html outputDirectory="tests/.results/html/"/>
Expand All @@ -20,4 +17,9 @@
<logging>
<junit outputFile="tests/.results/tests-junit.xml"/>
</logging>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
6 changes: 3 additions & 3 deletions src/CacheCleaner/AbstractCacheCleanerByTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
abstract class AbstractCacheCleanerByTags implements CacheCleanerInterface
{
public function __construct(
private ProjectionRepositoryInterface $projectionRepository,
private LoggerInterface $logger,
private string $logLevel = LogLevel::INFO
private readonly ProjectionRepositoryInterface $projectionRepository,
private readonly LoggerInterface $logger,
private readonly string $logLevel = LogLevel::INFO
) {
}

Expand Down
3 changes: 2 additions & 1 deletion src/CacheCleaner/CacheCleanerChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

final class CacheCleanerChain implements CacheCleanerInterface
{
private array $cacheCleaners;
/** @var CacheCleanerInterface[] */
private readonly array $cacheCleaners;

public function __construct(CacheCleanerInterface ...$cacheCleaners)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Provider/AbstractCachedProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ abstract class AbstractCachedProvider
private const DATA_KEY = 'data';

public function __construct(
private ProjectionRepositoryInterface $projectionRepository,
private LoggerInterface $logger,
private string $logLevel = LogLevel::INFO
private readonly ProjectionRepositoryInterface $projectionRepository,
private readonly LoggerInterface $logger,
private readonly string $logLevel = LogLevel::INFO
) {
}

Expand Down Expand Up @@ -83,7 +83,7 @@ protected function invalidateCacheItemByKey(ProjectionItemIterableInterface $pro

private function log(string $message, string $cacheKey, mixed $data = null): void
{
$this->logger()
$this->logger
->log(
$this->logLevel,
$message,
Expand Down
10 changes: 5 additions & 5 deletions src/Repository/AbstractProjectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
abstract class AbstractProjectionRepository implements ProjectionRepositoryInterface
{
public function __construct(
protected CacheItemPoolInterface $cachePool,
protected CacheSerializerInterface $serializer
protected readonly CacheItemPoolInterface $cachePool,
protected readonly CacheSerializerInterface $serializer
) {
}

Expand Down Expand Up @@ -48,11 +48,11 @@ public function get(ProjectionItemInterface $item): ?ProjectionItemInterface
{
$cacheItem = $this->cachePool->getItem($item->getKey());

if (!$cacheItem->isHit()) {
return null;
if ($cacheItem->isHit()) {
return $this->serializer->deserialize($cacheItem->get(), $item::class);
}

return $this->serializer->deserialize($cacheItem->get(), $item::class);
return null;
}

public function delete(ProjectionItemInterface $item): void
Expand Down
9 changes: 8 additions & 1 deletion src/Repository/SymfonyCacheProjectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(TagAwareAdapterInterface $cachePool, CacheSerializer

public function deleteByTags(Tags $tags): void
{
if (!$this->cachePool->invalidateTags($tags->raw())) {
if (!$this->getCachePool()->invalidateTags($tags->raw())) {
throw new ProjectionException('Not possible to delete projection items on cache pool based on tag');
}
}
Expand All @@ -31,4 +31,11 @@ protected function createCacheItem(ProjectionItemInterface $item): CacheItemInte

return $cacheItem;
}

private function getCachePool(): TagAwareAdapterInterface
{
assert($this->cachePool instanceof TagAwareAdapterInterface);

return $this->cachePool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

abstract class AbstractDeflateCacheDecoratorSerializer implements CacheSerializerInterface
{
public function __construct(private CacheSerializerInterface $serializer)
public function __construct(private readonly CacheSerializerInterface $serializer)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/Provider/JMSCacheSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class JMSCacheSerializer implements CacheSerializerInterface
{
private const SERIALIZER_FORMAT = 'json';

public function __construct(private SerializerInterface $serializer)
public function __construct(private readonly SerializerInterface $serializer)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/Provider/SymfonyCacheSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class SymfonyCacheSerializer implements CacheSerializerInterface
{
private const SERIALIZER_FORMAT = 'json';

public function __construct(private SerializerInterface $serializer)
public function __construct(private readonly SerializerInterface $serializer)
{
}

Expand Down
9 changes: 2 additions & 7 deletions src/Tag/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@

final class Tag implements Stringable
{
public function __construct(private string $tag)
public function __construct(public readonly string $tag)
{
}

public function __toString(): string
{
return $this->value();
}

public function value(): string
{
return $this->tag;
}

public function equals(Tag $other): bool
{
return $other->value() === $this->value();
return $other->tag === $this->tag;
}
}
Loading

0 comments on commit d78fbcd

Please sign in to comment.