Skip to content

Commit

Permalink
Merge pull request #148 from bearsunday/php84
Browse files Browse the repository at this point in the history
Add PHP 8.4 to CI workflow
  • Loading branch information
koriym authored Nov 24, 2024
2 parents 7e6c69f + 0f6d283 commit 5a85523
Show file tree
Hide file tree
Showing 30 changed files with 2,972 additions and 76 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist --no-plugins"
COMPOSER_UPDATE_FLAGS: ""
script: demo/run.php

Expand Down Expand Up @@ -43,6 +43,12 @@ jobs:
- php-version: 8.3
dependencies: lowest
os: ubuntu-latest
- php-version: 8.4
dependencies: highest
os: ubuntu-latest
- php-version: 8.4
dependencies: lowest
os: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
21 changes: 9 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"php": "^8.1",
"bear/fastly-module": "^0.1.1",
"bear/fastly-module": "^1.0",
"bear/resource": "^1.16.1",
"bear/sunday": "^1.5",
"doctrine/annotations": "^1.8 || ^2.0",
Expand All @@ -25,22 +25,13 @@
},
"require-dev": {
"ext-redis": "*",
"doctrine/coding-standard": "^12.0",
"bamarni/composer-bin-plugin": "^1.8",
"koriym/attributes": "^1.0.1",
"madapaja/twig-module": "^2.3",
"phpmd/phpmd": "^2.13",
"phpmetrics/phpmetrics": "^2.8",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5.28",
"psalm/plugin-phpunit": "^0.19.0",
"predis/predis": "^2.2",
"ray/object-visual-grapher": "^1.0",
"ray/rector-ray": "^1.0",
"rector/rector": "^1.2.4",
"squizlabs/php_codesniffer": "^3.7",
"symfony/process": "^4.3 || ^5.4 || ^6.1 || ^7.1",
"twig/twig": "^2.15.3 || ^3.4.3",
"vimeo/psalm": "^5.6"
"twig/twig": "^2.15.3 || ^3.4.3"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -87,5 +78,11 @@
"metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"]
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
}
}
}
6 changes: 5 additions & 1 deletion src/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
interface CommandInterface
{
/** @return void */
/**
* @param MethodInvocation<object> $invocation
*
* @return void
*/
public function command(MethodInvocation $invocation, ResourceObject $ro);
}
5 changes: 3 additions & 2 deletions src/EtagSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function crc32;
use function gmdate;
use function is_array;
use function is_string;
use function serialize;
use function time;

Expand Down Expand Up @@ -44,8 +45,8 @@ public function getEtagByPartialBody(HttpCache $httpCacche, ResourceObject $ro):
$etag = '';
assert(is_array($ro->body));
foreach ($httpCacche->etag as $bodyEtag) {
if (isset($ro->body[$bodyEtag])) {
$etag .= (string) $ro->body[$bodyEtag];
if (isset($ro->body[$bodyEtag]) && is_string($ro->body[$bodyEtag])) {
$etag .= $ro->body[$bodyEtag];
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/HttpCacheInject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
use Ray\Di\Di\Inject;

trait HttpCacheInject
/** @deprecated Use constructor injection instead */
trait HttpCacheInject // @phpstan-ignore-line
{
/** @var HttpCacheInterface */
public $httpCache;
Expand Down
5 changes: 1 addition & 4 deletions src/ResourceStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Ray\Di\Di\Set;
use Ray\Di\ProviderInterface;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
use Symfony\Contracts\Cache\ItemInterface;

use function array_merge;
use function array_unique;
Expand Down Expand Up @@ -90,7 +89,6 @@ private function initializePools(ProviderInterface $roPoolProvider, ProviderInte
public function get(AbstractUri $uri): ResourceState|null
{
$item = $this->roPool->getItem($this->getUriKey($uri, self::KEY_RO));
assert($item instanceof ItemInterface);
$state = $item->get();
assert($state instanceof ResourceState || $state === null);

Expand All @@ -101,7 +99,6 @@ public function getDonut(AbstractUri $uri): ResourceDonut|null
{
$key = $this->getUriKey($uri, self::KEY_DONUT);
$item = $this->roPool->getItem($key);
assert($item instanceof ItemInterface);
$donut = $item->get();
assert($donut instanceof ResourceDonut || $donut === null);

Expand Down Expand Up @@ -238,7 +235,7 @@ private function getUriKey(AbstractUri $uri, string $type): string
private function getVary(): string
{
$xvary = $_SERVER['X_VARY'];
$varys = explode(',', $xvary);
$varys = explode(',', $xvary); // @phpstan-ignore-line
$varyString = '';
foreach ($varys as $vary) {
$phpVaryKey = sprintf('X_%s', strtoupper($vary));
Expand Down
5 changes: 1 addition & 4 deletions tests/BehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BEAR\QueryRepository\Exception\ReturnValueIsNotResourceObjectException;
use BEAR\QueryRepository\Exception\UnmatchedQuery;
use BEAR\Resource\ResourceInterface;
use BEAR\Resource\ResourceObject;
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
use FakeVendor\HelloWorld\Resource\App\Code;
use FakeVendor\HelloWorld\Resource\App\RefreshDest;
Expand All @@ -26,7 +25,7 @@ class BehaviorTest extends TestCase
protected function setUp(): void
{
$namespace = 'FakeVendor\HelloWorld';
$injector = new Injector(ModuleFactory::getInstance($namespace), $_ENV['TMP_DIR']);
$injector = new Injector(ModuleFactory::getInstance($namespace), __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->httpCache = $injector->getInstance(HttpCacheInterface::class);

Expand All @@ -36,7 +35,6 @@ protected function setUp(): void
public function testPurgeSameResourceObjectByPatch(): void
{
$user = $this->resource->get('app://self/user', ['id' => 1]);
assert($user instanceof ResourceObject);
$etag = $user->headers[Header::ETAG];
// reload (purge repository entry and re-generate by onGet)
$this->resource->patch('app://self/user', ['id' => 1, 'name' => 'kuma']);
Expand All @@ -55,7 +53,6 @@ public function testPurgeSameResourceObjectByPatch(): void
public function testPurgeSameResourceObjectByDelete(): void
{
$user = $this->resource->get('app://self/user', ['id' => 1]);
assert($user instanceof ResourceObject);
$etag = $user->headers[Header::ETAG];
$server = [
'REQUEST_METHOD' => 'GET',
Expand Down
5 changes: 1 addition & 4 deletions tests/CacheDependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;

use function assert;
use function explode;

class CacheDependencyTest extends TestCase
Expand All @@ -21,7 +20,7 @@ class CacheDependencyTest extends TestCase
protected function setUp(): void
{
$namespace = 'FakeVendor\HelloWorld';
$injector = new Injector(new FakeEtagPoolModule(ModuleFactory::getInstance($namespace)), $_ENV['TMP_DIR']);
$injector = new Injector(new FakeEtagPoolModule(ModuleFactory::getInstance($namespace)), __DIR__ . '/tmp');
$this->repository = $injector->getInstance(QueryRepositoryInterface::class);
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->storage = $injector->getInstance(ResourceStorageInterface::class);
Expand All @@ -34,7 +33,6 @@ public function testDestroyByChild(): void
$this->resource->get('page://self/dep/level-one');
$one1 = $this->repository->get(new Uri('page://self/dep/level-one'));
$this->assertInstanceOf(ResourceState::class, $one1);
assert($one1 instanceof ResourceState);
$etag1 = $one1->headers[Header::ETAG];
// destroy by child
$this->repository->purge(new Uri('page://self/dep/level-two'));
Expand All @@ -51,7 +49,6 @@ public function testDestroyByGrandChild(): void
$this->repository->purge(new Uri('page://self/dep/level-three'));
$one2 = $this->repository->get(new Uri('page://self/dep/level-one'));
$this->assertNull($one2);
assert($one1 instanceof ResourceState);
$etag1 = $one1->headers[Header::ETAG];
$surrogateKeys = explode(' ', $one1->headers['Surrogate-Key']);
$etag2 = $surrogateKeys[0];
Expand Down
13 changes: 10 additions & 3 deletions tests/CacheTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;

use function assert;
use function is_string;

class CacheTypeTest extends TestCase
{
private ResourceInterface $resource;

protected function setUp(): void
{
$this->resource = (new Injector(ModuleFactory::getInstance('FakeVendor\HelloWorld'), $_ENV['TMP_DIR']))->getInstance(ResourceInterface::class);
$this->resource = (new Injector(ModuleFactory::getInstance('FakeVendor\HelloWorld'), __DIR__ . '/tmp'))->getInstance(ResourceInterface::class);

parent::setUp();
}
Expand All @@ -41,11 +44,14 @@ public function testValue(): void
$uri = 'app://self/value';
// put
$ro = $this->resource->get($uri);
(string) $ro; /* @phpstan-ignore-line */
(string) $ro;
$time = $ro['time'];
assert(is_string($time));
$this->assertSame('1' . $time, $ro->view);
$ro = $this->resource->get($uri);
(string) $ro; /* @phpstan-ignore-line */
(string) $ro;
$result = (string) $ro;
$this->assertNotEmpty($result);
$this->assertSame('2' . $time, $ro->view);
}

Expand All @@ -55,6 +61,7 @@ public function testView(): void
// put
$ro = $this->resource->get($uri);
$time = $ro['time'];
assert(is_string($time));
$this->assertSame('1' . $time, $ro->view);
$ro = $this->resource->get($uri);
$this->assertTrue((bool) $ro->view);
Expand Down
2 changes: 1 addition & 1 deletion tests/CacheVersionModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testNew(): void
{
$version = '1';
$module = new CacheVersionModule($version);
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$ns = $injector->getInstance('', CacheNamespace::class); // @phpstan-ignore-line
$this->assertSame($version, $ns);
}
Expand Down
13 changes: 4 additions & 9 deletions tests/CdnCacheControlHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BEAR\QueryRepository\Cdn\AkamaiModule;
use BEAR\QueryRepository\Cdn\FastlyModule;
use BEAR\Resource\ResourceInterface;
use BEAR\Resource\ResourceObject;
use BEAR\Resource\Uri;
use Madapaja\TwigModule\TwigModule;
use PHPUnit\Framework\TestCase;
Expand All @@ -22,11 +21,10 @@ class CdnCacheControlHeaderTest extends TestCase
public function testCdnCacheControl(): void
{
$module = $this->getModule();
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
/** @var ResourceInterface $resource */
$resource = $injector->getInstance(ResourceInterface::class);
$ro = $resource->get('page://self/html/blog-posting');
assert($ro instanceof ResourceObject);
$this->assertArrayHasKey(Header::CDN_CACHE_CONTROL, $ro->headers);
$this->assertSame($ro->headers[Header::CDN_CACHE_CONTROL], 'max-age=10 stale-while-revalidate=10');
$repository = $injector->getInstance(QueryRepositoryInterface::class);
Expand All @@ -42,10 +40,9 @@ public function testFastlyModule(): void
$module = $this->getModule();
$module->override(new FastlyModule('apiKey', 'serviceId'));
$module->override(new FakeFastlyPurgeModule());
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$resource = $injector->getInstance(ResourceInterface::class);
$ro = $resource->get('page://self/html/blog-posting');
assert($ro instanceof ResourceObject);
$this->assertArrayHasKey('Surrogate-Control', $ro->headers);
$this->assertSame($ro->headers['Surrogate-Control'], 'max-age=31536000');
$this->assertArrayHasKey('Surrogate-Key', $ro->headers);
Expand All @@ -55,10 +52,9 @@ public function testAkamaiModule(): void
{
$module = $this->getModule();
$module->override(new AkamaiModule());
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$resource = $injector->getInstance(ResourceInterface::class);
$ro = $resource->get('page://self/html/blog-posting');
assert($ro instanceof ResourceObject);
$this->assertArrayHasKey('Akamai-Cache-Control', $ro->headers);
$this->assertArrayHasKey('Edge-Cache-Tag', $ro->headers);
$this->assertSame($ro->headers['Akamai-Cache-Control'], 'max-age=31536000');
Expand All @@ -68,10 +64,9 @@ public function testNullCdnCacheControlModule(): void
{
$module = $this->getModule();
$module->override(new NullCdnCacheControlModule());
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$resource = $injector->getInstance(ResourceInterface::class);
$ro = $resource->get('page://self/html/blog-posting');
assert($ro instanceof ResourceObject);
$this->assertArrayNotHasKey('Surrogate-Control', $ro->headers);
$this->assertArrayNotHasKey('Header::CDN_CACHE_CONTROL_HEADER', $ro->headers);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/DonutCacheInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ protected function setUp(): void
$module = new DevEtagModule((new FakeEtagPoolModule(ModuleFactory::getInstance($namespace))));
$module->override(new TwigModule([dirname(__DIR__) . '/tests/Fake/fake-app/var/templates']));
if (! $injector) {
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
}

assert($injector instanceof Injector);
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->logger = $injector->getInstance(RepositoryLoggerInterface::class);

Expand Down
2 changes: 1 addition & 1 deletion tests/DonutCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
$module = new FakeEtagPoolModule(ModuleFactory::getInstance($namespace));
$path = dirname(__DIR__) . '/tests/Fake/fake-app/var/templates';
$module->override(new TwigModule([$path]));
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);

parent::setUp();
Expand Down
6 changes: 5 additions & 1 deletion tests/DonutCommandInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function array_map;
use function assert;
use function dirname;
use function is_array;
use function property_exists;

class DonutCommandInterceptorTest extends TestCase
Expand All @@ -27,7 +28,7 @@ protected function setUp(): void
$namespace = 'FakeVendor\HelloWorld';
$module = new FakeEtagPoolModule(ModuleFactory::getInstance($namespace));
$module->override(new TwigModule([dirname(__DIR__) . '/tests/Fake/fake-app/var/templates']));
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->logger = $injector->getInstance(RepositoryLoggerInterface::class);
$this->httpCache = $injector->getInstance(HttpCacheInterfaceAlias::class);
Expand Down Expand Up @@ -84,6 +85,9 @@ public function testCacheableResponse(): void
$interceptors = array_map(static fn (object $object): string => $object::class, $ro->bindings['onGet']); // @phpstan-ignore-line
$this->assertContains(DonutCacheInterceptor::class, $interceptors);
assert(property_exists($ro, 'bindings'));
assert(is_array($ro->bindings));
assert(is_array($ro->bindings['onGet']));
assert(is_array($ro->bindings['onDelete']));
assert(isset($ro->bindings['onGet'][0]));
assert(isset($ro->bindings['onDelete'][0]));
$this->assertInstanceOf(DonutCacheInterceptor::class, $ro->bindings['onDelete'][0]);
Expand Down
2 changes: 1 addition & 1 deletion tests/DonutCommandRedisCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
$module = new FakeEtagPoolModule(ModuleFactory::getInstance($namespace));
$module->override(new TwigModule([dirname(__DIR__) . '/tests/Fake/fake-app/var/templates']));
$module->override(new StorageRedisModule('127.0.0.1:6379'));
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->logger = $injector->getInstance(RepositoryLoggerInterface::class);
$httpCache = $injector->getInstance(HttpCacheInterfaceAlias::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/DonutQueryInterceptorPurgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ protected function setUp(): void
$module = new FakeEtagPoolModule(ModuleFactory::getInstance($namespace));
$module->override(new TwigModule([dirname(__DIR__) . '/tests/Fake/fake-app/var/templates']));
if (! $injector) {
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
}

assert($injector instanceof Injector);
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->repository = $injector->getInstance(QueryRepository::class);
$this->logger = $injector->getInstance(RepositoryLoggerInterface::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/DonutQueryInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ protected function setUp(): void
$module = new DevEtagModule((new FakeEtagPoolModule(ModuleFactory::getInstance($namespace))));
$module->override(new TwigModule([dirname(__DIR__) . '/tests/Fake/fake-app/var/templates']));
if (! $injector) {
$injector = new Injector($module, $_ENV['TMP_DIR']);
$injector = new Injector($module, __DIR__ . '/tmp');
}

assert($injector instanceof Injector);
$this->resource = $injector->getInstance(ResourceInterface::class);
$this->logger = $injector->getInstance(RepositoryLoggerInterface::class);

Expand Down
Loading

0 comments on commit 5a85523

Please sign in to comment.