Skip to content

Commit e58674d

Browse files
committed
Upgraded codebase to php 8.4
2 parents 7ef23ff + 9407c93 commit e58674d

File tree

10 files changed

+154
-113
lines changed

10 files changed

+154
-113
lines changed

.github/workflows/build.yml

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ name: build
22
on: [push, pull_request]
33

44
jobs:
5-
full-build:
6-
name: "Coding standards & coverage tests"
5+
quality-check:
6+
name: "Coding standards & test coverage"
77
runs-on: ${{ matrix.operating-system }}
88
strategy:
99
matrix:
1010
operating-system: ['ubuntu-latest']
1111
php-versions: ['7.4']
1212
env:
1313
extensions: pcov, dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
14-
key: cache-v2
14+
key: cache-v3
1515
steps:
1616
- name: "Checkout"
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v3
1818
- name: "Setup PHP extensions cache environment"
1919
id: cache-env
2020
uses: shivammathur/cache-extensions@v1
@@ -23,7 +23,7 @@ jobs:
2323
extensions: ${{ env.extensions }}
2424
key: ${{ env.key }}
2525
- name: "Cache PHP extensions"
26-
uses: actions/cache@v2
26+
uses: actions/cache@v3
2727
with:
2828
path: ${{ steps.cache-env.outputs.dir }}
2929
key: ${{ steps.cache-env.outputs.key }}
@@ -35,49 +35,88 @@ jobs:
3535
coverage: pcov
3636
extensions: ${{ env.extensions }}
3737
ini-values: assert.exception=1, zend.assertions=1
38-
- name: "Validate composer.json"
39-
run: composer validate
40-
- name: "Setup composer cache"
41-
uses: actions/cache@v2
38+
- name: "Install Composer dependencies"
39+
uses: ramsey/composer-install@v2
4240
with:
43-
path: ~/.composer/cache
44-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
45-
restore-keys: ${{ runner.os }}-composer-
46-
- name: "Install highest dependencies"
47-
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable
41+
dependency-versions: highest
42+
composer-options: --prefer-stable
43+
custom-cache-key: composer-${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
4844
- name: "Coding standard Php-CS-Fixer checks"
4945
run: vendor/bin/php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests
5046
- name: "Coding standard CodeSniffer checks"
5147
run: |
52-
vendor/bin/phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml src
53-
vendor/bin/phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml --ignore=*/code-samples/* tests
48+
vendor/bin/phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml --colors src
49+
vendor/bin/phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml --colors --ignore=*/code-samples/* tests
5450
- name: "Package skeleton validation"
5551
run: vendor/bin/polymorphine-skeleton check
5652
- name: "Run PhpUnit tests with coverage"
5753
run: |
58-
mkdir -p build/logs
59-
vendor/bin/phpunit --coverage-clover build/logs/clover.xml
54+
mkdir -p .dev/logs
55+
vendor/bin/phpunit --coverage-clover .dev/logs/clover.xml
6056
- name: "Send coverage report to coveralls.io"
61-
run: vendor/bin/php-coveralls -v
57+
run: |
58+
composer require php-coveralls/php-coveralls
59+
vendor/bin/php-coveralls -v -o .dev/logs/coveralls-upload.json -x .dev/logs/clover.xml
6260
env:
63-
COVERALLS_RUN_LOCALLY: 1
6461
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
6562

66-
php-os-builds:
67-
name: "PHP 8 tests"
63+
platform-compatibility:
64+
name: "Operating systems"
6865
runs-on: ${{ matrix.operating-system }}
6966
strategy:
7067
matrix:
7168
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
72-
php-versions: ['8.0', '8.1']
69+
php-versions: ['8.4']
7370
env:
7471
extensions: dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
75-
key: cache-v2
72+
key: cache-v3
7673
steps:
7774
- name: "Turn off git EOL conversion"
7875
run: git config --global core.autocrlf false
7976
- name: "Checkout"
80-
uses: actions/checkout@v2
77+
uses: actions/checkout@v3
78+
- name: "Setup PHP extensions cache environment"
79+
id: cache-env
80+
uses: shivammathur/cache-extensions@v1
81+
with:
82+
php-version: ${{ matrix.php-versions }}
83+
extensions: ${{ env.extensions }}
84+
key: ${{ env.key }}
85+
- name: "Cache PHP extensions"
86+
uses: actions/cache@v3
87+
with:
88+
path: ${{ steps.cache-env.outputs.dir }}
89+
key: ${{ steps.cache-env.outputs.key }}
90+
restore-keys: ${{ steps.cache-env.outputs.key }}
91+
- name: "Install PHP with extensions"
92+
uses: shivammathur/setup-php@v2
93+
with:
94+
php-version: ${{ matrix.php-versions }}
95+
coverage: none
96+
extensions: ${{ env.extensions }}
97+
ini-values: assert.exception=1, zend.assertions=1
98+
- name: "Install Composer dependencies"
99+
uses: ramsey/composer-install@v2
100+
with:
101+
dependency-versions: highest
102+
composer-options: --prefer-stable
103+
custom-cache-key: composer-${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
104+
- name: "Run PhpUnit tests (no coverage)"
105+
run: vendor/bin/phpunit --no-coverage
106+
107+
php-versions:
108+
name: "PHP versions"
109+
runs-on: ${{ matrix.operating-system }}
110+
strategy:
111+
matrix:
112+
operating-system: ['ubuntu-latest']
113+
php-versions: ['8.0', '8.1', '8.2', '8.3']
114+
env:
115+
extensions: dom, json, libxml, mbstring, pdo_sqlite, soap, xml, xmlwriter
116+
key: cache-v3
117+
steps:
118+
- name: "Checkout"
119+
uses: actions/checkout@v3
81120
- name: "Setup PHP extensions cache environment"
82121
id: cache-env
83122
uses: shivammathur/cache-extensions@v1
@@ -86,7 +125,7 @@ jobs:
86125
extensions: ${{ env.extensions }}
87126
key: ${{ env.key }}
88127
- name: "Cache PHP extensions"
89-
uses: actions/cache@v2
128+
uses: actions/cache@v3
90129
with:
91130
path: ${{ steps.cache-env.outputs.dir }}
92131
key: ${{ steps.cache-env.outputs.key }}
@@ -98,13 +137,11 @@ jobs:
98137
coverage: none
99138
extensions: ${{ env.extensions }}
100139
ini-values: assert.exception=1, zend.assertions=1
101-
- name: "Setup composer cache"
102-
uses: actions/cache@v2
140+
- name: "Install Composer dependencies"
141+
uses: ramsey/composer-install@v2
103142
with:
104-
path: ~/.composer/cache
105-
key: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }}
106-
restore-keys: ${{ runner.os }}-php${{ matrix.php-versions }}-composer-
107-
- name: "Install highest dependencies"
108-
run: composer update --no-interaction --no-ansi --no-progress --no-suggest --prefer-stable
143+
dependency-versions: highest
144+
composer-options: --prefer-stable
145+
custom-cache-key: composer-${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
109146
- name: "Run PhpUnit tests (no coverage)"
110147
run: vendor/bin/phpunit --no-coverage

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"require": {
1515
"php": "^7.4 || ^8.0",
1616
"ext-json": "*",
17-
"psr/http-message": "^1.0",
18-
"psr/http-factory": "^1.0"
17+
"psr/http-message": "^1.1",
18+
"psr/http-factory": "^1.1"
1919
},
2020
"require-dev": {
21-
"polymorphine/dev": "0.2.*"
21+
"polymorphine/dev": "0.5.*"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -33,8 +33,8 @@
3333
"scripts": {
3434
"test-cs": [
3535
"php-cs-fixer --dry-run -v --config=cs-fixer.php.dist --path-mode=intersection fix src tests",
36-
"phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml src",
37-
"phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml --ignore=*/code-samples/* tests"
36+
"phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml --colors src",
37+
"phpcs --extensions=php --standard=vendor/polymorphine/dev/phpcs.xml --colors --ignore=*/code-samples/* tests"
3838
],
3939
"test-php": "phpunit",
4040
"test-skeleton": "polymorphine-skeleton check"

cs-fixer.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
use Polymorphine\Dev\FixerFactory;
1313

14-
return FixerFactory::createFor('Polymorphine/Message', __DIR__);
14+
return FixerFactory::createFor(__FILE__);

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
5-
cacheResultFile=".dev/temp/.phpunit.result.cache"
5+
cacheResultFile=".dev/cache/.phpunit.result.cache"
66
colors="true"
77
bootstrap="vendor/autoload.php"
88
>
99
<php>
1010
<ini name="error_reporting" value="-1" />
11+
<env name="DEV_TESTS_DIRECTORY" value=".dev/tests" force="true" />
1112
</php>
1213
<testsuites>
1314
<testsuite name="Polymorphine/Message tests">

src/Factory/UploadedFileFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public function __construct(string $serverAPI = 'server')
3434

3535
public function createUploadedFile(
3636
StreamInterface $stream,
37-
int $size = null,
37+
?int $size = null,
3838
int $error = UPLOAD_ERR_OK,
39-
string $clientFilename = null,
40-
string $clientMediaType = null
39+
?string $clientFilename = null,
40+
?string $clientMediaType = null
4141
): UploadedFileInterface {
4242
return $this->isWebServerAPI()
4343
? new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType)

src/Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ public static function redirect($uri, int $status = 303): self
9292
return new self($status, null, ['Location' => (string) $uri]);
9393
}
9494

95-
public static function badRequest(StreamInterface $body = null): self
95+
public static function badRequest(?StreamInterface $body = null): self
9696
{
9797
return new self(400, $body);
9898
}
9999

100-
public static function unauthorized(StreamInterface $body = null): self
100+
public static function unauthorized(?StreamInterface $body = null): self
101101
{
102102
return new self(401, $body);
103103
}
104104

105-
public static function notFound(StreamInterface $body = null): self
105+
public static function notFound(?StreamInterface $body = null): self
106106
{
107107
return new self(404, $body);
108108
}

src/UploadedFile.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class UploadedFile implements UploadedFileInterface
3636
*/
3737
public function __construct(
3838
StreamInterface $stream,
39-
int $size = null,
39+
?int $size = null,
4040
int $error = UPLOAD_ERR_OK,
41-
string $clientFilename = null,
42-
string $clientMediaType = null
41+
?string $clientFilename = null,
42+
?string $clientMediaType = null
4343
) {
4444
if (!$stream->isReadable()) {
4545
throw new InvalidArgumentException('Stream is not readable');

tests/RequestTest.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Polymorphine\Message\Request;
1616
use Polymorphine\Message\Uri;
1717
use Psr\Http\Message\RequestInterface;
18+
use Psr\Http\Message\UriInterface;
1819
use InvalidArgumentException;
1920

2021

@@ -26,27 +27,26 @@ public function testRequestInstantiation()
2627
}
2728

2829
/**
29-
* @dataProvider mutatorMethods
30+
* @param callable $mutate fn(Request) => Request
3031
*
31-
* @param $method
32-
* @param $param
32+
* @dataProvider mutatorMethods
3333
*/
34-
public function testMutatorMethod_ReturnsNewInstance($method, $param)
34+
public function testMutatorMethod_ReturnsNewInstance(callable $mutate)
3535
{
3636
$original = $this->request();
37-
$clone1 = $original->{$method}($param);
38-
$clone2 = $original->{$method}($param);
39-
$this->assertNotSame($clone1, $clone2);
40-
$this->assertEquals($clone1, $clone2);
41-
$this->assertNotEquals($original, $clone1);
37+
$cloneA = $mutate($original);
38+
$cloneB = $mutate($original);
39+
$this->assertNotSame($cloneA, $cloneB);
40+
$this->assertEquals($cloneA, $cloneB);
41+
$this->assertNotEquals($original, $cloneA);
4242
}
4343

4444
public function mutatorMethods(): array
4545
{
4646
return [
47-
'withRequestTarget' => ['withRequestTarget', '*'],
48-
'withUri' => ['withUri', Uri::fromString('/some/path')],
49-
'withMethod' => ['withMethod', 'POST']
47+
'withRequestTarget' => [fn (Request $original) => $original->withRequestTarget('*')],
48+
'withUri' => [fn (Request $original) => $original->withUri(Uri::fromString('/some/path'))],
49+
'withMethod' => [fn (Request $original) => $original->withMethod('POST')]
5050
];
5151
}
5252

@@ -135,15 +135,14 @@ public function testWithUriResolvesHostHeader()
135135
$this->assertSame('uri-example.com', $request->withUri($uri, false)->getHeaderLine('host'), $fail);
136136
}
137137

138-
private function request($method = 'GET', array $headers = [], $uri = null, $target = null): Request
139-
{
140-
if (!isset($uri)) {
141-
$uri = Uri::fromString();
142-
}
143-
if (!$target) {
144-
return new Request($method, $uri, null, $headers, []);
145-
}
146-
147-
return new Request($method, $uri, null, $headers, ['target' => $target]);
138+
private function request(
139+
string $method = 'GET',
140+
array $headers = [],
141+
?UriInterface $uri = null,
142+
?string $target = null
143+
): Request {
144+
return $target
145+
? new Request($method, $uri ?? Uri::fromString(), null, $headers, ['target' => $target])
146+
: new Request($method, $uri ?? Uri::fromString(), null, $headers, []);
148147
}
149148
}

0 commit comments

Comments
 (0)