Skip to content

Commit 0a03507

Browse files
authored
Update php-parser (#78)
* Update php-parser
1 parent fa8d511 commit 0a03507

20 files changed

+123
-154
lines changed

.github/workflows/ci.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
operating-system: ['ubuntu-latest', 'windows-latest', 'macOS-latest']
11-
php-version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
11+
php-version: ['8.1', '8.2', '8.3']
1212
name: PHP ${{ matrix.php-version }} Test on ${{ matrix.operating-system }}
1313
steps:
1414
- name: Checkout code
@@ -23,6 +23,7 @@ jobs:
2323
with:
2424
php-version: ${{ matrix.php-version }}
2525
tools: composer:v2
26+
coverage: xdebug
2627
- name: Install Composer dependencies
2728
run: composer install --prefer-dist --no-interaction --no-suggest
2829
- name: Install phpcs

build.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/bin/sh
22
set -e
33

4-
git log origin/master... | grep -q SKIP_BUILD && exit 0
5-
64
[ -z "$UPDATE_COVERAGE" ] || composer require satooshi/php-coveralls:v1.1.0
75

86
composer install
9-
git diff $(git merge-base origin/master HEAD) > diff.txt
7+
[ -z "$UPDATE_COVERAGE" ] || git diff $(git merge-base origin/master HEAD) > diff.txt
108
phpcs --standard=psr2 src
119
phpcs --standard=psr2 --ignore=bootstrap.php,fixtures/* tests
1210

@@ -15,6 +13,6 @@ phpmd tests text cleancode,codesize,controversial,unusedcode --exclude fixtures
1513

1614
./vendor/bin/phpunit
1715

18-
bin/diffFilter --phpunit diff.txt report/coverage.xml
16+
[ -z "$UPDATE_COVERAGE" ] || bin/diffFilter --phpunit diff.txt report/coverage.xml
1917

2018
[ -z "$UPDATE_COVERAGE" ] || php vendor/bin/coveralls -v

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
},
2020
"bin": ["bin/diffFilter"],
2121
"require": {
22-
"php": ">=7.0",
22+
"php": ">=8.1",
2323
"ext-xmlreader": "*",
2424
"ext-json": "*",
25-
"nikic/php-parser": "^3.1||^4.0"
25+
"nikic/php-parser": "^3.1||^4.0||^5.0"
2626
}
2727
}

phpunit.xml

+16-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.4/phpunit.xsd"
4-
bootstrap="tests/bootstrap.php"
5-
backupGlobals="false"
6-
beStrictAboutCoversAnnotation="true"
7-
beStrictAboutOutputDuringTests="true"
8-
beStrictAboutTestsThatDoNotTestAnything="true"
9-
beStrictAboutTodoAnnotatedTests="true"
10-
verbose="true">
11-
<testsuite name="coverageChecker">
12-
<directory suffix="Test.php">tests</directory>
13-
</testsuite>
14-
15-
<filter>
16-
<whitelist addUncoveredFilesFromWhitelist="true">
17-
<directory suffix=".php">src</directory>
18-
</whitelist>
19-
</filter>
20-
<logging>
21-
<log
22-
type="coverage-html"
23-
target="report"
24-
lowUpperBound="90"
25-
highLowerBound="95"/>
26-
<log type="coverage-clover" target="report/coverage.xml"/>
27-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" bootstrap="tests/bootstrap.php" backupGlobals="false" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" cacheDirectory=".phpunit.cache" beStrictAboutCoverageMetadata="true">
3+
<coverage includeUncoveredFiles="true">
4+
<report>
5+
<clover outputFile="report/coverage.xml"/>
6+
<html outputDirectory="report" lowUpperBound="90" highLowerBound="95"/>
7+
</report>
8+
</coverage>
9+
<testsuite name="coverageChecker">
10+
<directory suffix="Test.php">tests</directory>
11+
</testsuite>
12+
<logging/>
13+
<source>
14+
<include>
15+
<directory suffix=".php">src</directory>
16+
</include>
17+
</source>
2818
</phpunit>

src/FileParser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FileParser
1818
public function __construct($sourceCode)
1919
{
2020
$this->sourceCode = $sourceCode;
21-
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
21+
$parser = (new ParserFactory)->createForHostVersion();
2222
$this->parse($parser);
2323
}
2424

@@ -56,7 +56,7 @@ protected function getCodeLimits(Node $node): CodeLimits
5656
$startLine = $node->getAttribute('startLine');
5757
$endLine = $node->getAttribute('endLine');
5858
if ($node->getDocComment()) {
59-
$startLine = $node->getDocComment()->getLine();
59+
$startLine = $node->getDocComment()->getStartLine();
6060
}
6161

6262
return new CodeLimits($startLine, $endLine);

src/functions.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function handleOutput(array $lines, float $minimumPercentCovered, Output $output
9292

9393
if ($coveredLines + $uncoveredLines == 0) {
9494
error_log('No lines found!');
95-
95+
9696
$output->output(
9797
$lines['uncoveredLines'],
9898
100,
@@ -126,14 +126,19 @@ function calculateLines(array $lines)
126126

127127
function addExceptionHandler()
128128
{
129-
set_exception_handler(
130-
function ($exception) {
131-
// @codeCoverageIgnoreStart
132-
error_log($exception->getMessage());
133-
exit($exception->getCode());
134-
// @codeCoverageIgnoreEnd
135-
}
136-
);
129+
if ((
130+
!defined('PHPUNIT_COMPOSER_INSTALL') &&
131+
!defined('__PHPUNIT_PHAR__')
132+
)) {
133+
set_exception_handler(
134+
function ($exception) {
135+
// @codeCoverageIgnoreStart
136+
error_log($exception->getMessage());
137+
exit($exception->getCode());
138+
// @codeCoverageIgnoreEnd
139+
}
140+
);
141+
}
137142
}
138143

139144
function getFileChecker(

tests/ArgParserTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace exussum12\CoverageChecker\tests;
33

4+
use PHPUnit\Framework\Attributes\Before;
45
use PHPUnit\Framework\TestCase;
56
use exussum12\CoverageChecker\ArgParser;
67
use exussum12\CoverageChecker\Exceptions\ArgumentNotFound;
@@ -9,9 +10,7 @@ class ArgParserTest extends TestCase
910
{
1011
protected $parser;
1112

12-
/**
13-
* @before
14-
*/
13+
#[Before]
1514
public function setUpTest()
1615
{
1716
$args = [

tests/CoverageCheckTest.php

+49-59
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,20 @@ public function testCoverage()
2828
]);
2929

3030
$xmlReport->method('getErrorsOnLine')
31-
->will(
32-
$this->returnCallback(
33-
function () {
34-
$file = func_get_arg(0);
35-
$line = func_get_arg(1);
36-
37-
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
38-
return $this->errorMessage;
39-
}
40-
if ($file == '/full/path/to/testFile2.php' && $line == 4) {
41-
return $this->errorMessage;
42-
}
43-
44-
return [];
31+
->willReturnCallback(
32+
function () {
33+
$file = func_get_arg(0);
34+
$line = func_get_arg(1);
35+
36+
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
37+
return $this->errorMessage;
38+
}
39+
if ($file == '/full/path/to/testFile2.php' && $line == 4) {
40+
return $this->errorMessage;
4541
}
46-
)
42+
43+
return [];
44+
}
4745
);
4846

4947
$matcher = new FileMatchers\EndsWith;
@@ -87,19 +85,17 @@ public function testCoverageFailed()
8785
->willReturn(null);
8886

8987
$xmlReport->method('getErrorsOnLine')
90-
->will(
91-
$this->returnCallback(
92-
function () {
93-
$file = func_get_arg(0);
94-
$line = func_get_arg(1);
88+
->willReturnCallback(
89+
function () {
90+
$file = func_get_arg(0);
91+
$line = func_get_arg(1);
9592

96-
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
97-
return $this->errorMessage;
98-
}
99-
100-
return [];
93+
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
94+
return $this->errorMessage;
10195
}
102-
)
96+
97+
return [];
98+
}
10399
);
104100

105101
$matcher = new FileMatchers\EndsWith;
@@ -141,19 +137,17 @@ public function testAddingAllUnknownsCovered()
141137
->willReturn(true);
142138

143139
$xmlReport->method('getErrorsOnLine')
144-
->will(
145-
$this->returnCallback(
146-
function () {
147-
$file = func_get_arg(0);
148-
$line = func_get_arg(1);
149-
150-
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
151-
return $this->errorMessage;
152-
}
140+
->willReturnCallback(
141+
function () {
142+
$file = func_get_arg(0);
143+
$line = func_get_arg(1);
153144

154-
return [];
145+
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
146+
return $this->errorMessage;
155147
}
156-
)
148+
149+
return [];
150+
}
157151
);
158152

159153
$matcher = new FileMatchers\EndsWith;
@@ -196,19 +190,17 @@ public function testAddingAllUnknownsUnCovered()
196190
->willReturn(false);
197191

198192
$xmlReport->method('getErrorsOnLine')
199-
->will(
200-
$this->returnCallback(
201-
function () {
202-
$file = func_get_arg(0);
203-
$line = func_get_arg(1);
204-
205-
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
206-
return $this->errorMessage;
207-
}
193+
->willReturnCallback(
194+
function () {
195+
$file = func_get_arg(0);
196+
$line = func_get_arg(1);
208197

209-
return [];
198+
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
199+
return $this->errorMessage;
210200
}
211-
)
201+
202+
return [];
203+
}
212204
);
213205

214206
$matcher = new FileMatchers\EndsWith;
@@ -254,19 +246,17 @@ public function testCoverageForContextLines()
254246
->willReturn(false);
255247

256248
$xmlReport->method('getErrorsOnLine')
257-
->will(
258-
$this->returnCallback(
259-
function () {
260-
$file = func_get_arg(0);
261-
$line = func_get_arg(1);
249+
->willReturnCallback(
250+
function () {
251+
$file = func_get_arg(0);
252+
$line = func_get_arg(1);
262253

263-
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
264-
return null;
265-
}
266-
267-
return [];
254+
if ($file == '/full/path/to/testFile1.php' && $line == 2) {
255+
return null;
268256
}
269-
)
257+
258+
return [];
259+
}
270260
);
271261

272262
$matcher = new FileMatchers\EndsWith;

tests/DiffFileLoadOldVersionTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<?php
22
namespace exussum12\CoverageChecker\tests;
33

4-
use exussum12\CoverageChecker\DiffFileLoaderOldVersion;
4+
use PHPUnit\Framework\Attributes\DataProvider;
55
use PHPUnit\Framework\TestCase;
6+
use exussum12\CoverageChecker\DiffFileLoaderOldVersion;
67

78
class DiffFileLoadOldVersionTest extends TestCase
89
{
9-
/**
10-
* @dataProvider getResults
11-
*/
10+
#[DataProvider('getResults')]
1211
public function testDiffResultsMatch($file, $expected)
1312
{
1413
$changed = $this->getChangedLines($file);
1514

1615
$this->assertEquals($expected, $changed);
1716
}
1817

19-
public function getResults()
18+
public static function getResults()
2019
{
2120
return [
2221
'newFile' => [

tests/DiffFileLoadTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
namespace exussum12\CoverageChecker\tests;
33

44
use InvalidArgumentException;
5+
use PHPUnit\Framework\Attributes\DataProvider;
56
use PHPUnit\Framework\TestCase;
67
use exussum12\CoverageChecker\DiffFileLoader;
78
use exussum12\CoverageChecker\DiffFileState;
89
use exussum12\CoverageChecker\DiffLineHandle\ContextLine;
910

1011
class DiffFileLoadTest extends TestCase
1112
{
12-
/**
13-
* @dataProvider getResults
14-
*/
13+
#[DataProvider('getResults')]
1514
public function testDiffResultsMatch($file, $expected)
1615
{
1716
$changed = $this->getChangedLines($file);
@@ -26,7 +25,7 @@ public function testNonExistantFile()
2625
$this->getChangedLines('ufhbubfusdf');
2726
}
2827

29-
public function getResults()
28+
public static function getResults()
3029
{
3130
return [
3231
'newFile' => [

tests/Loaders/CheckstyleTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
namespace exussum12\CoverageChecker\tests\Loaders;
33

44
use exussum12\CoverageChecker\Loaders\Checkstyle;
5+
use PHPUnit\Framework\Attributes\Before;
56

67
class CheckstyleTest extends PhanTextTest
78
{
89
/** @var Checkstyle */
910
protected $phan;
1011
protected $prefix = '';
1112

12-
/**
13-
* @before
14-
*/
13+
#[Before]
1514
protected function setUpTest()
1615
{
1716
$this->phan = new Checkstyle(__DIR__ . '/../fixtures/checkstyle.xml');

0 commit comments

Comments
 (0)