Skip to content

Commit f19ff4c

Browse files
committed
fixed compatibility with PHP 8
1 parent 15ed6f3 commit f19ff4c

8 files changed

Lines changed: 40 additions & 38 deletions

File tree

src/CodeCoverage/PhpParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public function parse(string $code): \stdClass
7676

7777
switch (is_array($token) ? $token[0] : $token) {
7878
case T_NAMESPACE:
79-
$namespace = ltrim(self::fetch($tokens, [T_STRING, T_NS_SEPARATOR]) . '\\', '\\');
79+
$namespace = self::fetch($tokens, [T_STRING, PHP_VERSION_ID < 80000 ? T_NS_SEPARATOR : T_NAME_QUALIFIED]);
80+
$namespace = ltrim($namespace . '\\', '\\');
8081
break;
8182

8283
case T_CLASS:

tests/Framework/Assert.error.phpt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,37 @@ require __DIR__ . '/../bootstrap.php';
88

99

1010
Assert::error(function () {
11-
$a++;
11+
$a = &pi();
1212
}, E_NOTICE);
1313

1414
Assert::error(function () {
15-
$a++;
15+
$a = &pi();
1616
}, 'E_NOTICE');
1717

1818
Assert::error(function () {
19-
$a++;
20-
}, E_NOTICE, 'Undefined variable: a');
19+
$a = &pi();
20+
}, E_NOTICE, 'Only variables should be assigned by reference');
2121

2222
Assert::error(function () {
23-
$a++;
24-
@$x++;
25-
$b++;
23+
$a = &pi();
24+
@$a++;
25+
$a = &pi();
2626
}, [
27-
[E_NOTICE, 'Undefined variable: a'],
28-
[E_NOTICE, 'Undefined variable: b'],
27+
[E_NOTICE, 'Only variables should be assigned by reference'],
28+
[E_NOTICE, 'Only variables should be assigned by reference'],
2929
]);
3030

3131
Assert::error(function () {
32-
$a++;
33-
$b++;
32+
$a = &pi();
33+
$a = &pi();
3434
}, [
3535
[E_NOTICE],
3636
[E_NOTICE],
3737
]);
3838

3939
Assert::error(function () {
40-
$a++;
41-
$b++;
40+
$a = &pi();
41+
$a = &pi();
4242
}, [E_NOTICE, E_NOTICE]
4343
);
4444

@@ -49,29 +49,29 @@ Assert::exception(function () {
4949

5050
Assert::exception(function () {
5151
Assert::error(function () {
52-
$a++;
52+
$a = &pi();
5353
}, E_WARNING);
54-
}, Tester\AssertException::class, 'E_WARNING was expected, but E_NOTICE (Undefined variable: a) was generated in file %a% on line %d%');
54+
}, Tester\AssertException::class, 'E_WARNING was expected, but E_NOTICE (Only variables should be assigned by reference) was generated in file %a% on line %d%');
5555

5656
Assert::exception(function () {
5757
Assert::error(function () {
58-
$a++;
58+
$a = &pi();
5959
}, E_NOTICE, 'Abc');
60-
}, Tester\AssertException::class, "E_NOTICE with a message matching 'Abc' was expected but got 'Undefined variable: a'");
60+
}, Tester\AssertException::class, "E_NOTICE with a message matching 'Abc' was expected but got 'Only variables should be assigned by reference'");
6161

6262
Assert::exception(function () {
6363
Assert::error(function () {
64-
$a++;
65-
$b++;
66-
}, E_NOTICE, 'Undefined variable: a');
67-
}, Tester\AssertException::class, 'Generated more errors than expected: E_NOTICE (Undefined variable: b) was generated in file %a% on line %d%');
64+
$a = &pi();
65+
$a = &pi();
66+
}, E_NOTICE, 'Only variables should be assigned by reference');
67+
}, Tester\AssertException::class, 'Generated more errors than expected: E_NOTICE (Only variables should be assigned by reference) was generated in file %a% on line %d%');
6868

6969
Assert::exception(function () {
7070
Assert::error(function () {
71-
$a++;
71+
$a = &pi();
7272
}, [
73-
[E_NOTICE, 'Undefined variable: a'],
74-
[E_NOTICE, 'Undefined variable: b'],
73+
[E_NOTICE, 'Only variables should be assigned by reference'],
74+
[E_NOTICE, 'Only variables should be assigned by reference'],
7575
]);
7676
}, Tester\AssertException::class, 'Error was expected, but was not generated');
7777

tests/Framework/Assert.noError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Assert::noError(function () {
1313

1414
Assert::exception(function () {
1515
Assert::noError(function () {
16-
$a++;
16+
$a = &pi();
1717
});
1818
}, Tester\AssertException::class, 'Generated more errors than expected: E_NOTICE %a%');
1919

tests/Framework/FileMock.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test(function () {
1818
$cases = [
1919
'r' => $tmp = [
2020
[E_USER_WARNING, 'fopen(mock://none): failed to open stream: No such file or directory'],
21-
[E_WARNING, 'fopen(mock://none): failed to open stream: "Tester\FileMock::stream_open" call failed'],
21+
[E_WARNING, 'fopen(mock://none): %[fF]%ailed to open stream: "Tester\FileMock::stream_open" call failed'],
2222
],
2323
'r+' => $tmp,
2424
'w' => [],
@@ -55,7 +55,7 @@ test(function () {
5555
'a+' => [],
5656
'x' => $tmp = [
5757
[E_USER_WARNING, 'fopen(mock://%i%.): failed to open stream: File exists'],
58-
[E_WARNING, 'fopen(mock://%i%.): failed to open stream: "Tester\FileMock::stream_open" call failed'],
58+
[E_WARNING, 'fopen(mock://%i%.): %[fF]%ailed to open stream: "Tester\FileMock::stream_open" call failed'],
5959
],
6060
'x+' => $tmp,
6161
'c' => [],

tests/Framework/Helpers.escapeArg.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require __DIR__ . '/../bootstrap.php';
99

1010

1111
$win = defined('PHP_WINDOWS_VERSION_BUILD');
12+
setlocale(LC_CTYPE, 'en_US.UTF-8'); // to not strip non-ASCII characters
1213

1314
Assert::same($win ? '""' : "''", Helpers::escapeArg(''));
1415
Assert::same($win ? '"žluťoučký"' : "'žluťoučký'", Helpers::escapeArg('žluťoučký'));

tests/Framework/TestCase.annotationThrows.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,28 @@ class MyTest extends Tester\TestCase
5757
/** @throws E_NOTICE */
5858
public function testNotice()
5959
{
60-
$a++;
60+
$a = &pi();
6161
}
6262

6363

64-
/** @throws E_NOTICE Undefined variable: a */
64+
/** @throws E_NOTICE Only variables should be assigned by reference */
6565
public function testNoticeMessage()
6666
{
67-
$a++;
67+
$a = &pi();
6868
}
6969

7070

7171
/** @throws E_WARNING */
7272
public function testBadError()
7373
{
74-
$a++;
74+
$a = &pi();
7575
}
7676

7777

7878
/** @throws E_NOTICE With message */
7979
public function testNoticeBadMessage()
8080
{
81-
$a++;
81+
$a = &pi();
8282
}
8383

8484

@@ -142,8 +142,8 @@ $test->runTest('testNoticeMessage');
142142

143143
Assert::exception(function () use ($test) {
144144
$test->runTest('testBadError');
145-
}, Tester\AssertException::class, 'E_WARNING was expected, but E_NOTICE (Undefined variable: a) was generated in %a%testBadError()');
145+
}, Tester\AssertException::class, 'E_WARNING was expected, but E_NOTICE (Only variables should be assigned by reference) was generated in %a%testBadError()');
146146

147147
Assert::exception(function () use ($test) {
148148
$test->runTest('testNoticeBadMessage');
149-
}, Tester\AssertException::class, "E_NOTICE with a message matching 'With message' was expected but got 'Undefined variable: a' in testNoticeBadMessage()");
149+
}, Tester\AssertException::class, "E_NOTICE with a message matching 'With message' was expected but got 'Only variables should be assigned by reference' in testNoticeBadMessage()");

tests/Runner/Runner.edge.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ $runner->run();
4545

4646
Assert::same([Test::FAILED, 'Exited with error code 231 (expected 0)'], $logger->results['shutdown.exitCode.a.phptx']);
4747

48-
$bug65275 = PHP_SAPI === 'cli';
48+
$bug65275 = PHP_SAPI === 'cli' && PHP_VERSION_ID < 80000;
4949
Assert::same($bug65275 ? [Test::FAILED, 'Exited with error code 231 (expected 0)'] : [Test::PASSED, null], $logger->results['shutdown.exitCode.b.phptx']);
5050

5151
Assert::same([Test::SKIPPED, 'just skipping'], $logger->results['skip.phptx']);

tests/Runner/Runner.multiple-fails.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ Assert::same(Test::FAILED, $logger->results['testcase-pre-fail.phptx'][0]);
7979

8080
Assert::match(
8181
defined('PHPDBG_VERSION')
82-
? '%A%Parse error: syntax error, unexpected end of file in %a%testcase-syntax-error.phptx on line %d%'
83-
: 'Parse error: syntax error, unexpected end of file in %a%testcase-syntax-error.phptx on line %d%',
82+
? '%A%Parse error: %a% in %a%testcase-syntax-error.phptx on line %d%'
83+
: 'Parse error: %a% in %a%testcase-syntax-error.phptx on line %d%',
8484
trim($logger->results['testcase-syntax-error.phptx'][1])
8585
);
8686
Assert::same(Test::FAILED, $logger->results['testcase-syntax-error.phptx'][0]);

0 commit comments

Comments
 (0)