Skip to content

Commit 88be266

Browse files
authored
Merge pull request #257 from simPod/php8
Add tests for PHP 8
2 parents 8f59dde + 5f16759 commit 88be266

File tree

4 files changed

+171
-8
lines changed

4 files changed

+171
-8
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
php-version:
129129
- "7.1"
130130
- "7.4"
131+
- "8.0"
131132

132133
steps:
133134
- name: "Checkout"

Makefile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
.PHONY: test test-report test-fix update-compatibility-patch
22

3-
PHP_74_OR_NEWER:=$(shell php -r "echo (int) version_compare(PHP_VERSION, '7.4', '>=');")
3+
PHP_VERSION:=$(shell php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")
4+
PATCH_FILE="tests/php$(PHP_VERSION)-compatibility.patch"
45

56
test: test-report test-fix
67

78
test-report: vendor
8-
@if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply tests/php-compatibility.patch; fi
9-
@vendor/bin/phpcs `find tests/input/* | sort` --report=summary --report-file=phpcs.log; diff -u tests/expected_report.txt phpcs.log; if [ $$? -ne 0 ]; then if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi; exit 1; fi
10-
@if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi
9+
@if [ -f "$(PATCH_FILE)" ]; then git apply $(PATCH_FILE) ; fi
10+
@vendor/bin/phpcs `find tests/input/* | sort` --report=summary --report-file=phpcs.log; diff -u tests/expected_report.txt phpcs.log; if [ $$? -ne 0 ] && [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; exit 1; fi
11+
@if [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; fi
1112

1213
test-fix: vendor
13-
@if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply tests/php-compatibility.patch; fi
14+
@if [ -f "$(PATCH_FILE)" ]; then git apply $(PATCH_FILE) ; fi
1415
@cp -R tests/input/ tests/input2/
15-
@vendor/bin/phpcbf tests/input2; diff -u tests/input2 tests/fixed; if [ $$? -ne 0 ]; then rm -rf tests/input2/ && if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi; exit 1; fi
16-
@rm -rf tests/input2/ && if [ $(PHP_74_OR_NEWER) -eq 1 ]; then git apply -R tests/php-compatibility.patch; fi
16+
@vendor/bin/phpcbf tests/input2; diff -u tests/input2 tests/fixed; if [ $$? -ne 0 ]; then rm -rf tests/input2/; if [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; fi; exit 1; fi
17+
@rm -rf tests/input2/;
18+
@if [ -f "$(PATCH_FILE)" ]; then git apply -R $(PATCH_FILE) ; fi
1719

18-
update-compatibility-patch:
20+
update-compatibility-patch-74:
1921
@git apply tests/php-compatibility.patch
2022
@printf "Please open your editor and apply your changes\n"
2123
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
2224
@git diff -- tests/expected_report.txt tests/fixed > .tmp-patch && mv .tmp-patch tests/php-compatibility.patch && git apply -R tests/php-compatibility.patch
2325
@git commit -m 'Update compatibility patch' tests/php-compatibility.patch
2426

27+
update-compatibility-patch-80:
28+
@git apply tests/php80-compatibility.patch
29+
@printf "Please open your editor and apply your changes\n"
30+
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
31+
@git diff -- tests/expected_report.txt tests/fixed > .tmp-patch-80 && mv .tmp-patch-80 tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch
32+
@git commit -m 'Update compatibility patch' tests/php80-compatibility.patch
33+
2534
vendor: composer.json
2635
composer update
2736
touch -c vendor
File renamed without changes.

tests/php80-compatibility.patch

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2+
index c644926..1b5b271 100644
3+
--- a/tests/expected_report.txt
4+
+++ b/tests/expected_report.txt
5+
@@ -15,17 +15,17 @@ tests/input/ControlStructures.php 28 0
6+
tests/input/doc-comment-spacing.php 11 0
7+
tests/input/duplicate-assignment-variable.php 1 0
8+
tests/input/EarlyReturn.php 6 0
9+
-tests/input/example-class.php 38 0
10+
+tests/input/example-class.php 42 0
11+
tests/input/forbidden-comments.php 14 0
12+
tests/input/forbidden-functions.php 6 0
13+
tests/input/inline_type_hint_assertions.php 7 0
14+
tests/input/LowCaseTypes.php 2 0
15+
tests/input/namespaces-spacing.php 7 0
16+
-tests/input/NamingCamelCase.php 6 0
17+
+tests/input/NamingCamelCase.php 9 0
18+
tests/input/negation-operator.php 2 0
19+
-tests/input/new_with_parentheses.php 18 0
20+
+tests/input/new_with_parentheses.php 19 0
21+
tests/input/not_spacing.php 8 0
22+
-tests/input/null_coalesce_equal_operator.php 1 0
23+
+tests/input/null_coalesce_equal_operator.php 5 0
24+
tests/input/null_coalesce_operator.php 3 0
25+
tests/input/optimized-functions.php 1 0
26+
tests/input/PropertyTypeHintSpacing.php 6 0
27+
@@ -39,15 +39,15 @@ tests/input/superfluous-naming.php 11 0
28+
tests/input/test-case.php 8 0
29+
tests/input/trailing_comma_on_array.php 1 0
30+
tests/input/traits-uses.php 11 0
31+
-tests/input/type-hints.php 4 0
32+
+tests/input/type-hints.php 5 0
33+
tests/input/UnusedVariables.php 1 0
34+
tests/input/use-ordering.php 1 0
35+
tests/input/useless-semicolon.php 2 0
36+
tests/input/UselessConditions.php 20 0
37+
----------------------------------------------------------------------
38+
-A TOTAL OF 377 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
39+
+A TOTAL OF 390 ERRORS AND 0 WARNINGS WERE FOUND IN 41 FILES
40+
----------------------------------------------------------------------
41+
-PHPCBF CAN FIX 313 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
42+
+PHPCBF CAN FIX 326 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
43+
----------------------------------------------------------------------
44+
45+
46+
diff --git a/tests/fixed/NamingCamelCase.php b/tests/fixed/NamingCamelCase.php
47+
index 57d9f2b..5493471 100644
48+
--- a/tests/fixed/NamingCamelCase.php
49+
+++ b/tests/fixed/NamingCamelCase.php
50+
@@ -6,14 +6,11 @@ namespace Example;
51+
52+
class NamingCamelCase
53+
{
54+
- /** @var mixed */
55+
- public $A;
56+
+ public mixed $A;
57+
58+
- /** @var mixed */
59+
- protected $B;
60+
+ protected mixed $B;
61+
62+
- /** @var mixed */
63+
- private $C;
64+
+ private mixed $C;
65+
66+
public function fcn(string $A): void
67+
{
68+
diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
69+
index 998e51d..b47d358 100644
70+
--- a/tests/fixed/example-class.php
71+
+++ b/tests/fixed/example-class.php
72+
@@ -25,17 +25,14 @@ class Example implements IteratorAggregate
73+
{
74+
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;
75+
76+
- /** @var int|null */
77+
- private $foo;
78+
+ private ?int $foo = null;
79+
80+
/** @var string[] */
81+
- private $bar;
82+
+ private array $bar;
83+
84+
- /** @var bool */
85+
- private $baz;
86+
+ private bool $baz;
87+
88+
- /** @var ControlStructureSniff|int|string|null */
89+
- private $baxBax;
90+
+ private ControlStructureSniff|int|string|null $baxBax = null;
91+
92+
public function __construct(?int $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
93+
{
94+
diff --git a/tests/fixed/new_with_parentheses.php b/tests/fixed/new_with_parentheses.php
95+
index 6e81bbe..47a06ec 100644
96+
--- a/tests/fixed/new_with_parentheses.php
97+
+++ b/tests/fixed/new_with_parentheses.php
98+
@@ -24,5 +24,5 @@ $y = [new stdClass()];
99+
100+
$z = new stdClass() ? new stdClass() : new stdClass();
101+
102+
-$q = $q ?: new stdClass();
103+
-$e = $e ?? new stdClass();
104+
+$q = $q ?: new stdClass();
105+
+$e ??= new stdClass();
106+
diff --git a/tests/fixed/null_coalesce_equal_operator.php b/tests/fixed/null_coalesce_equal_operator.php
107+
index b997469..6703d30 100644
108+
--- a/tests/fixed/null_coalesce_equal_operator.php
109+
+++ b/tests/fixed/null_coalesce_equal_operator.php
110+
@@ -2,12 +2,12 @@
111+
112+
declare(strict_types=1);
113+
114+
-$bar = $bar ?? 'bar';
115+
+$bar ??= 'bar';
116+
117+
-$bar['baz'] = $bar['baz'] ?? 'baz';
118+
+$bar['baz'] ??= 'baz';
119+
120+
-$bar = $bar ?? 'bar';
121+
+$bar ??= 'bar';
122+
123+
-$object->property = $object->property ?? 'Default Value';
124+
+$object->property ??= 'Default Value';
125+
126+
-Test::$foo = Test::$foo ?? 123;
127+
+Test::$foo ??= 123;
128+
diff --git a/tests/fixed/null_coalesce_operator.php b/tests/fixed/null_coalesce_operator.php
129+
index 8846dd1..51c361c 100644
130+
--- a/tests/fixed/null_coalesce_operator.php
131+
+++ b/tests/fixed/null_coalesce_operator.php
132+
@@ -4,7 +4,7 @@ declare(strict_types=1);
133+
134+
$foo = $_GET['foo'] ?? 'foo';
135+
136+
-$bar = $bar ?? 'bar';
137+
+$bar ??= 'bar';
138+
139+
$bar = $bar['baz'] ?? 'baz';
140+
141+
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
142+
index 0e952fc..9824fb0 100644
143+
--- a/tests/fixed/type-hints.php
144+
+++ b/tests/fixed/type-hints.php
145+
@@ -10,7 +10,7 @@ use Traversable;
146+
class TraversableTypeHints
147+
{
148+
/** @var Traversable */
149+
- private $parameter;
150+
+ private Traversable $parameter;
151+
152+
/**
153+
* @param Iterator $iterator

0 commit comments

Comments
 (0)