Skip to content

Commit 5a85523

Browse files
authored
Merge pull request #148 from bearsunday/php84
Add PHP 8.4 to CI workflow
2 parents 7e6c69f + 0f6d283 commit 5a85523

30 files changed

Lines changed: 2972 additions & 76 deletions

.github/workflows/continuous-integration.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
workflow_dispatch:
99

1010
env:
11-
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
11+
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist --no-plugins"
1212
COMPOSER_UPDATE_FLAGS: ""
1313
script: demo/run.php
1414

@@ -43,6 +43,12 @@ jobs:
4343
- php-version: 8.3
4444
dependencies: lowest
4545
os: ubuntu-latest
46+
- php-version: 8.4
47+
dependencies: highest
48+
os: ubuntu-latest
49+
- php-version: 8.4
50+
dependencies: lowest
51+
os: ubuntu-latest
4652
steps:
4753
- name: Checkout
4854
uses: actions/checkout@v3

composer.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"require": {
1212
"php": "^8.1",
13-
"bear/fastly-module": "^0.1.1",
13+
"bear/fastly-module": "^1.0",
1414
"bear/resource": "^1.16.1",
1515
"bear/sunday": "^1.5",
1616
"doctrine/annotations": "^1.8 || ^2.0",
@@ -25,22 +25,13 @@
2525
},
2626
"require-dev": {
2727
"ext-redis": "*",
28-
"doctrine/coding-standard": "^12.0",
28+
"bamarni/composer-bin-plugin": "^1.8",
2929
"koriym/attributes": "^1.0.1",
3030
"madapaja/twig-module": "^2.3",
31-
"phpmd/phpmd": "^2.13",
32-
"phpmetrics/phpmetrics": "^2.8",
33-
"phpstan/phpstan": "^1.9",
3431
"phpunit/phpunit": "^9.5.28",
35-
"psalm/plugin-phpunit": "^0.19.0",
3632
"predis/predis": "^2.2",
37-
"ray/object-visual-grapher": "^1.0",
38-
"ray/rector-ray": "^1.0",
39-
"rector/rector": "^1.2.4",
40-
"squizlabs/php_codesniffer": "^3.7",
4133
"symfony/process": "^4.3 || ^5.4 || ^6.1 || ^7.1",
42-
"twig/twig": "^2.15.3 || ^3.4.3",
43-
"vimeo/psalm": "^5.6"
34+
"twig/twig": "^2.15.3 || ^3.4.3"
4435
},
4536
"autoload": {
4637
"psr-4": {
@@ -87,5 +78,11 @@
8778
"metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
8879
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
8980
"build": ["@cs", "@sa", "@pcov", "@metrics"]
81+
},
82+
"extra": {
83+
"bamarni-bin": {
84+
"bin-links": true,
85+
"forward-command": true
86+
}
9087
}
9188
}

src/CommandInterface.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
*/
1515
interface CommandInterface
1616
{
17-
/** @return void */
17+
/**
18+
* @param MethodInvocation<object> $invocation
19+
*
20+
* @return void
21+
*/
1822
public function command(MethodInvocation $invocation, ResourceObject $ro);
1923
}

src/EtagSetter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function crc32;
1414
use function gmdate;
1515
use function is_array;
16+
use function is_string;
1617
use function serialize;
1718
use function time;
1819

@@ -44,8 +45,8 @@ public function getEtagByPartialBody(HttpCache $httpCacche, ResourceObject $ro):
4445
$etag = '';
4546
assert(is_array($ro->body));
4647
foreach ($httpCacche->etag as $bodyEtag) {
47-
if (isset($ro->body[$bodyEtag])) {
48-
$etag .= (string) $ro->body[$bodyEtag];
48+
if (isset($ro->body[$bodyEtag]) && is_string($ro->body[$bodyEtag])) {
49+
$etag .= $ro->body[$bodyEtag];
4950
}
5051
}
5152

src/HttpCacheInject.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
88
use Ray\Di\Di\Inject;
99

10-
trait HttpCacheInject
10+
/** @deprecated Use constructor injection instead */
11+
trait HttpCacheInject // @phpstan-ignore-line
1112
{
1213
/** @var HttpCacheInterface */
1314
public $httpCache;

src/ResourceStorage.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Ray\Di\Di\Set;
1313
use Ray\Di\ProviderInterface;
1414
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
15-
use Symfony\Contracts\Cache\ItemInterface;
1615

1716
use function array_merge;
1817
use function array_unique;
@@ -90,7 +89,6 @@ private function initializePools(ProviderInterface $roPoolProvider, ProviderInte
9089
public function get(AbstractUri $uri): ResourceState|null
9190
{
9291
$item = $this->roPool->getItem($this->getUriKey($uri, self::KEY_RO));
93-
assert($item instanceof ItemInterface);
9492
$state = $item->get();
9593
assert($state instanceof ResourceState || $state === null);
9694

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

@@ -238,7 +235,7 @@ private function getUriKey(AbstractUri $uri, string $type): string
238235
private function getVary(): string
239236
{
240237
$xvary = $_SERVER['X_VARY'];
241-
$varys = explode(',', $xvary);
238+
$varys = explode(',', $xvary); // @phpstan-ignore-line
242239
$varyString = '';
243240
foreach ($varys as $vary) {
244241
$phpVaryKey = sprintf('X_%s', strtoupper($vary));

tests/BehaviorTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use BEAR\QueryRepository\Exception\ReturnValueIsNotResourceObjectException;
88
use BEAR\QueryRepository\Exception\UnmatchedQuery;
99
use BEAR\Resource\ResourceInterface;
10-
use BEAR\Resource\ResourceObject;
1110
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
1211
use FakeVendor\HelloWorld\Resource\App\Code;
1312
use FakeVendor\HelloWorld\Resource\App\RefreshDest;
@@ -26,7 +25,7 @@ class BehaviorTest extends TestCase
2625
protected function setUp(): void
2726
{
2827
$namespace = 'FakeVendor\HelloWorld';
29-
$injector = new Injector(ModuleFactory::getInstance($namespace), $_ENV['TMP_DIR']);
28+
$injector = new Injector(ModuleFactory::getInstance($namespace), __DIR__ . '/tmp');
3029
$this->resource = $injector->getInstance(ResourceInterface::class);
3130
$this->httpCache = $injector->getInstance(HttpCacheInterface::class);
3231

@@ -36,7 +35,6 @@ protected function setUp(): void
3635
public function testPurgeSameResourceObjectByPatch(): void
3736
{
3837
$user = $this->resource->get('app://self/user', ['id' => 1]);
39-
assert($user instanceof ResourceObject);
4038
$etag = $user->headers[Header::ETAG];
4139
// reload (purge repository entry and re-generate by onGet)
4240
$this->resource->patch('app://self/user', ['id' => 1, 'name' => 'kuma']);
@@ -55,7 +53,6 @@ public function testPurgeSameResourceObjectByPatch(): void
5553
public function testPurgeSameResourceObjectByDelete(): void
5654
{
5755
$user = $this->resource->get('app://self/user', ['id' => 1]);
58-
assert($user instanceof ResourceObject);
5956
$etag = $user->headers[Header::ETAG];
6057
$server = [
6158
'REQUEST_METHOD' => 'GET',

tests/CacheDependencyTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPUnit\Framework\TestCase;
1010
use Ray\Di\Injector;
1111

12-
use function assert;
1312
use function explode;
1413

1514
class CacheDependencyTest extends TestCase
@@ -21,7 +20,7 @@ class CacheDependencyTest extends TestCase
2120
protected function setUp(): void
2221
{
2322
$namespace = 'FakeVendor\HelloWorld';
24-
$injector = new Injector(new FakeEtagPoolModule(ModuleFactory::getInstance($namespace)), $_ENV['TMP_DIR']);
23+
$injector = new Injector(new FakeEtagPoolModule(ModuleFactory::getInstance($namespace)), __DIR__ . '/tmp');
2524
$this->repository = $injector->getInstance(QueryRepositoryInterface::class);
2625
$this->resource = $injector->getInstance(ResourceInterface::class);
2726
$this->storage = $injector->getInstance(ResourceStorageInterface::class);
@@ -34,7 +33,6 @@ public function testDestroyByChild(): void
3433
$this->resource->get('page://self/dep/level-one');
3534
$one1 = $this->repository->get(new Uri('page://self/dep/level-one'));
3635
$this->assertInstanceOf(ResourceState::class, $one1);
37-
assert($one1 instanceof ResourceState);
3836
$etag1 = $one1->headers[Header::ETAG];
3937
// destroy by child
4038
$this->repository->purge(new Uri('page://self/dep/level-two'));
@@ -51,7 +49,6 @@ public function testDestroyByGrandChild(): void
5149
$this->repository->purge(new Uri('page://self/dep/level-three'));
5250
$one2 = $this->repository->get(new Uri('page://self/dep/level-one'));
5351
$this->assertNull($one2);
54-
assert($one1 instanceof ResourceState);
5552
$etag1 = $one1->headers[Header::ETAG];
5653
$surrogateKeys = explode(' ', $one1->headers['Surrogate-Key']);
5754
$etag2 = $surrogateKeys[0];

tests/CacheTypeTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
use PHPUnit\Framework\TestCase;
1010
use Ray\Di\Injector;
1111

12+
use function assert;
13+
use function is_string;
14+
1215
class CacheTypeTest extends TestCase
1316
{
1417
private ResourceInterface $resource;
1518

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

2023
parent::setUp();
2124
}
@@ -41,11 +44,14 @@ public function testValue(): void
4144
$uri = 'app://self/value';
4245
// put
4346
$ro = $this->resource->get($uri);
44-
(string) $ro; /* @phpstan-ignore-line */
47+
(string) $ro;
4548
$time = $ro['time'];
49+
assert(is_string($time));
4650
$this->assertSame('1' . $time, $ro->view);
4751
$ro = $this->resource->get($uri);
48-
(string) $ro; /* @phpstan-ignore-line */
52+
(string) $ro;
53+
$result = (string) $ro;
54+
$this->assertNotEmpty($result);
4955
$this->assertSame('2' . $time, $ro->view);
5056
}
5157

@@ -55,6 +61,7 @@ public function testView(): void
5561
// put
5662
$ro = $this->resource->get($uri);
5763
$time = $ro['time'];
64+
assert(is_string($time));
5865
$this->assertSame('1' . $time, $ro->view);
5966
$ro = $this->resource->get($uri);
6067
$this->assertTrue((bool) $ro->view);

tests/CacheVersionModuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testNew(): void
1414
{
1515
$version = '1';
1616
$module = new CacheVersionModule($version);
17-
$injector = new Injector($module, $_ENV['TMP_DIR']);
17+
$injector = new Injector($module, __DIR__ . '/tmp');
1818
$ns = $injector->getInstance('', CacheNamespace::class); // @phpstan-ignore-line
1919
$this->assertSame($version, $ns);
2020
}

0 commit comments

Comments
 (0)