Skip to content

Commit 5596c3e

Browse files
authored
13589 Target PHP 7.4, support PHP 8.1 (#14)
1 parent ef8c159 commit 5596c3e

File tree

12 files changed

+289
-67
lines changed

12 files changed

+289
-67
lines changed

.circleci/config.yml

+179-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,180 @@
1-
version: 2.0
1+
# PHPUnit Composer min/max test.
2+
# TODO: Make our own orb out of this.
3+
4+
version: 2.1
5+
orbs:
6+
php: circleci/[email protected]
7+
8+
commands:
9+
update-packages:
10+
description: |
11+
Update your composer packages with automated caching and best practices applied.
12+
parameters:
13+
app-dir:
14+
default: ~/project
15+
description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root.
16+
type: string
17+
cache-files-dir:
18+
default: /home/circleci/.composer/cache/files
19+
description: Absolute path to the file cache folder. This should be inline with "composer global config cache-files-dir --absolute".
20+
type: string
21+
cache-key:
22+
default: composer.lock
23+
description: If this file is updated a new cache bucket will be created. Recommended to use composer.lock. Use composer.json when composer.lock is absent.
24+
type: string
25+
cache-version:
26+
default: v1
27+
description: Change the default cache version if you need to clear the cache for any reason.
28+
type: string
29+
install-flags:
30+
default: --no-interaction --prefer-dist
31+
description: |
32+
By default, packages will be installed with "composer install --no-interaction --prefer-dist", use this to override the standard install flags.
33+
type: string
34+
vendor-dir:
35+
default: vendor
36+
description: Relative path to the vendor folder. Relative to "app-dir". This should be inline with "composer config vendor-dir".
37+
type: string
38+
with-cache:
39+
default: true
40+
description: Enable automatic caching of your dependencies for increased speed.
41+
type: boolean
42+
steps:
43+
- when:
44+
condition: << parameters.with-cache >>
45+
steps:
46+
- restore_cache:
47+
keys:
48+
- composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }}
49+
- run:
50+
command: |
51+
if [ ! -f "composer.json" ] && [ ! -f "composer.lock" ]; then
52+
echo
53+
echo "---"
54+
echo "Unable to find your composer.json and composer.lock files. Did you forget to set the app-dir parameter?"
55+
echo "---"
56+
echo
57+
echo "Current directory: $(pwd)"
58+
echo
59+
echo
60+
echo "List directory: "
61+
echo
62+
ls
63+
exit 1
64+
fi
65+
name: Verify composer.json and/or composer.lock exist
66+
working_directory: <<parameters.app-dir>>
67+
- run:
68+
command: composer update <<parameters.install-flags>>
69+
name: Updating Composer Packages
70+
working_directory: <<parameters.app-dir>>
71+
- when:
72+
condition: << parameters.with-cache >>
73+
steps:
74+
- save_cache:
75+
key: composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }}
76+
paths:
77+
- <<parameters.app-dir>>/<<parameters.vendor-dir>>
78+
- <<parameters.cache-files-dir>>
79+
install-xdebug:
80+
steps:
81+
- run:
82+
name: Install XDebug
83+
command: sudo -E install-php-extensions xdebug && sudo -E docker-php-ext-enable xdebug
84+
85+
install-cc-test-reporter:
86+
# TODO: Parameterize location.
87+
steps:
88+
- run:
89+
name: Install Codeclimate test reporter
90+
command: |
91+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
92+
chmod +x ./cc-test-reporter
93+
94+
run-phpunit-tests:
95+
description: |
96+
Run PHPUnit tests.
97+
parameters:
98+
app-dir:
99+
default: ~/project
100+
description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root.
101+
type: string
102+
install-flags:
103+
default: ""
104+
description: Arguments to `composer update`.
105+
type: string
106+
test-command:
107+
default: test
108+
description: The name of the script within your composer.json which will run your tests.
109+
type: string
110+
report-to-codeclimate:
111+
type: boolean
112+
default: false
113+
description: Report coverage info to Codeclimate.
114+
steps:
115+
- checkout
116+
- update-packages:
117+
app-dir: <<parameters.app-dir>>
118+
cache-key: composer.json
119+
install-flags: <<parameters.install-flags>>
120+
- when:
121+
condition: <<parameters.report-to-codeclimate>>
122+
steps:
123+
- install-xdebug
124+
- install-cc-test-reporter
125+
- run: |
126+
./cc-test-reporter before-build
127+
XDEBUG_MODE=coverage composer <<parameters.test-command>> -- --coverage-clover clover.xml
128+
./cc-test-reporter after-build --coverage-input-type clover --exit-code $?
129+
- when:
130+
condition:
131+
not: <<parameters.report-to-codeclimate>>
132+
steps:
133+
- run: |
134+
XDEBUG_MODE=off composer <<parameters.test-command>>
135+
2136
jobs:
3-
build:
4-
environment:
5-
CC_TEST_REPORTER_ID: d20339bfed51b1e242630efbe3f2745337794f7a856f610aad4d21897c5e0309
6-
docker:
7-
- image: circleci/php:7-cli-node-browsers-legacy
8-
working_directory: ~/repo
9-
steps:
10-
- checkout
11-
- run:
12-
name: Setup dependencies
13-
command: |
14-
sudo composer self-update
15-
composer install -n --prefer-dist
16-
- run:
17-
name: Setup Code Climate test-reporter
18-
command: |
19-
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
20-
chmod +x ./cc-test-reporter
21-
- run:
22-
name: Run tests
23-
command: |
24-
./cc-test-reporter before-build
25-
vendor/bin/phpunit --testsuite all --coverage-clover clover.xml
26-
./cc-test-reporter after-build --coverage-input-type clover --exit-code $?
137+
matrix-conditions:
138+
environment:
139+
CC_TEST_REPORTER_ID: d20339bfed51b1e242630efbe3f2745337794f7a856f610aad4d21897c5e0309
140+
description: Run tests for matrix
141+
executor:
142+
name: php/default
143+
tag: << parameters.version >>
144+
parameters:
145+
version:
146+
default: "7.4"
147+
description: The `cimg/php` Docker image version tag.
148+
type: string
149+
install-flags:
150+
default: ""
151+
description: Arguments to `composer update`.
152+
type: string
153+
steps:
154+
- when:
155+
condition:
156+
and:
157+
- equal: [ "8.1", <<parameters.version>> ]
158+
- equal: [ "", <<parameters.install-flags>> ]
159+
steps:
160+
- run-phpunit-tests:
161+
report-to-codeclimate: true
162+
install-flags: << parameters.install-flags >>
163+
- when:
164+
condition:
165+
not:
166+
and:
167+
- equal: [ "8.1", <<parameters.version>> ]
168+
- equal: [ "", <<parameters.install-flags>> ]
169+
steps:
170+
- run-phpunit-tests:
171+
install-flags: << parameters.install-flags >>
172+
173+
workflows:
174+
all-tests:
175+
jobs:
176+
- matrix-conditions:
177+
matrix:
178+
parameters:
179+
version: ["7.4", "8.0", "8.1"]
180+
install-flags: ["", "--prefer-lowest"]

.codeclimate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2
1+
version: "2"
22
plugins:
33
phpcodesniffer:
44
enabled: true

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This is the top-most .editorconfig file; do not search in parent directories.
2+
root = true
3+
4+
# All files.
5+
[*]
6+
end_of_line = LF
7+
indent_style = space
8+
indent_size = 4
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[composer.{json,lock}]
14+
indent_size = 4

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
2+
.phpunit.result.cache
23
vendor
34
composer.lock

composer.json

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
{
22
"name": "getdkan/contracts",
33
"description": "A set of interfaces.",
4+
"license": "GPL-3.0-only",
45
"type": "library",
6+
"authors": [
7+
{
8+
"name": "fmizzell",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=7.4 <9.0"
14+
},
15+
"require-dev": {
16+
"phpunit/phpunit": "^9.6",
17+
"rector/rector": "^0.15.17",
18+
"squizlabs/php_codesniffer": "^3.7"
19+
},
520
"autoload": {
621
"psr-4": {
7-
"Contracts\\": "src/",
22+
"Contracts\\": "src/"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
827
"ContractsTest\\": "test/"
928
}
1029
},
11-
"require-dev": {
12-
"phpunit/phpunit": "~7.5.0"
30+
"config": {
31+
"sort-packages": true
1332
},
14-
"license": "GPL-3.0-only",
15-
"authors": [
16-
{
17-
"name": "fmizzell",
18-
"email": "[email protected]"
19-
}
20-
]
33+
"scripts": {
34+
"phpcbf": "./vendor/bin/phpcbf",
35+
"phpcs": "./vendor/bin/phpcs",
36+
"rector": "./vendor/bin/rector process",
37+
"rector-dry-run": "./vendor/bin/rector process --dry-run",
38+
"test": "./vendor/bin/phpunit --testsuite all"
39+
}
2140
}

phpcs.xml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="getdkan">
3+
4+
<arg name="extensions" value="inc,install,module,php,profile,test,theme,yml"/>
5+
<description>PHP CodeSniffer configuration for GetDKAN.</description>
6+
7+
<file>src</file>
8+
<file>test</file>
9+
<file>rector.php</file>
10+
11+
<rule ref="PSR1"/>
12+
<rule ref="PSR2"/>
13+
14+
</ruleset>

phpunit.xml

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
<phpunit
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
4-
verbose="false">
5-
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" verbose="false">
4+
<coverage processUncoveredFiles="true">
5+
<include>
6+
<directory suffix=".php">src</directory>
7+
</include>
8+
</coverage>
69
<testsuites>
710
<testsuite name="all">
8-
<directory suffix="Test.php" phpVersion="7.2" phpVersionOperator=">=">test</directory>
11+
<directory suffix="Test.php">test</directory>
912
</testsuite>
1013
</testsuites>
11-
12-
<filter>
13-
<whitelist processUncoveredFilesFromWhitelist="true">
14-
<directory suffix=".php">src</directory>
15-
</whitelist>
16-
</filter>
17-
1814
</phpunit>

rector.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Generic PHP 7.4 update.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Rector\Config\RectorConfig;
10+
use Rector\Set\ValueObject\LevelSetList;
11+
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
12+
13+
return static function (RectorConfig $rectorConfig): void {
14+
$rectorConfig->paths([
15+
__DIR__ . '/src',
16+
__DIR__ . '/test',
17+
]);
18+
19+
$rectorConfig->sets([
20+
LevelSetList::UP_TO_PHP_74,
21+
]);
22+
23+
$rectorConfig->skip([
24+
JsonThrowOnErrorRector::class,
25+
]);
26+
};

src/Mock/IdGenerator/Sequential.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Sequential implements IdGeneratorInterface
88
{
9-
private $id = 0;
9+
private int $id = 0;
1010
public function generate()
1111
{
1212
$this->id++;

src/Mock/Storage/JsonObjectMemory.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class JsonObjectMemory extends Memory implements
1313
OffsetterInterface,
1414
LimiterInterface
1515
{
16-
private $offset = 0;
17-
private $limit = 0;
16+
private int $offset = 0;
17+
private int $limit = 0;
1818

19-
private $sorts = [
19+
private array $sorts = [
2020
'ascend' => [],
2121
'descend' => [],
2222
];
2323

24-
private $conditions = [];
24+
private array $conditions = [];
2525

2626
public function retrieveAll(): array
2727
{
@@ -85,9 +85,7 @@ private function applyFilters(array $results)
8585

8686
foreach ($this->sorts as $type => $properties) {
8787
foreach ($properties as $property) {
88-
usort($results, function ($a, $b) use ($property) {
89-
return $this->compare($a, $b, $property);
90-
});
88+
usort($results, fn($a, $b) => $this->compare($a, $b, $property));
9189

9290
if ($type == 'descend') {
9391
$results = array_reverse($results);

0 commit comments

Comments
 (0)