Skip to content

Commit fd04aec

Browse files
committed
Fix possible parsing error + upgrade to PHPUnit 10.1.
1 parent 2f6ea9b commit fd04aec

File tree

8 files changed

+44
-6
lines changed

8 files changed

+44
-6
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [3.0.0-rc3] - 2023-04-17
8+
9+
### Fixed
10+
- Fatal error when analyzing snippets like `$a->{$b}` or `$a->{<some_expression>}`.
11+
- Fatal error when analyzing snippets like `$a->{$b}()` or `$a->{<some_expression>}()`.
12+
13+
### Updates
14+
- Update to PHPUnit 10.1
15+
716
## [3.0.0-rc2] - 2023-04-17
817

918
### New features

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
},
3434
"require-dev": {
3535
"phake/phake": "^4.4.0",
36-
"phpstan/extension-installer": "^1.2",
36+
"phpstan/extension-installer": "^1.3",
3737
"phpstan/phpstan": "^1.10",
3838
"phpstan/phpstan-deprecation-rules": "^1.1",
3939
"phpstan/phpstan-phpunit": "^1.3",
4040
"phpstan/phpstan-strict-rules": "^1.5",
41-
"phpunit/phpunit": "^10.0",
41+
"phpunit/phpunit": "^10.1",
4242
"sebastian/comparator": ">=5.0.0",
4343
"squizlabs/php_codesniffer": "^3.7",
4444
"symfony/dom-crawler": "^6.2",

qa/phpunit.xml.dist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
</testsuite>
2525
</testsuites>
2626

27-
<coverage>
27+
<source>
2828
<include>
2929
<directory suffix=".php">../src</directory>
3030
</include>
31-
31+
</source>
32+
<coverage>
3233
<report>
3334
<html outputDirectory="reports/phpunit/coverage-html/"/>
3435
<xml outputDirectory="reports/phpunit/coverage-xml/"/>

src/Hal/Component/File/Reader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function readJson(string $path): mixed
5555
/**
5656
* {@inheritDoc}
5757
* @throws JsonException
58-
* @codeCoverageIgnore Cannot be tested as file_get_contents is calling a URI, and we cannot fake its results.
5958
* @infection-ignore-all Cannot be tested as file_get_contents is calling a URI, and we cannot fake its results.
6059
*/
6160
public function httpReadJson(string $uri): stdClass

src/Hal/DependencyInjection/DependencyInjectionProcessor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
* This class is the technical entrypoint and thus, can't be unit tested.
6363
* The behavior of this class is tested via functional tests.
6464
*
65-
* @codeCoverageIgnore Technical class that can only be tested functionally.
6665
* @infection-ignore-all Technical class that can only be tested functionally.
6766
*/
6867
final class DependencyInjectionProcessor

src/Hal/Metric/Class_/Structural/LcomVisitor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
use PhpParser\Node;
1515
use PhpParser\Node\Stmt;
1616
use PhpParser\NodeVisitorAbstract;
17+
use Stringable;
1718
use function array_filter;
1819
use function array_map;
1920
use function in_array;
21+
use function is_string;
2022
use function property_exists;
2123

2224
/**
@@ -198,6 +200,8 @@ private function getPropertyFetchTreeNodes(Node $node): array
198200
&& property_exists($node->var, 'name')
199201
&& !($node->var->name instanceof Node\Expr\Variable) // Prevents failure when $a->$b.
200202
&& 'this' === (string)$node->var->name
203+
// Prevents failures when $a->{$name} or $a->{<expr>}
204+
&& (is_string($node->name) || $node->name instanceof Stringable)
201205
) {
202206
return [$this->graph->gather((string)$node->name)];
203207
}
@@ -219,6 +223,8 @@ private function getMethodCallTreeNodes(Node $node): array
219223
&& property_exists($node->var, 'name')
220224
&& !($node->var->name instanceof Node\Expr\Variable) // Prevents failure when $a->$b(), or $c().
221225
&& 'this' === (string)$node->var->name
226+
// Prevents failures when $a->{$name}() or $a->{<expr>}()
227+
&& (is_string($node->name) || $node->name instanceof Stringable)
222228
) {
223229
return [$this->graph->gather($node->name . '()')];
224230
}

tests/Component/File/ReaderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55

66
use Hal\Component\File\Reader;
77
use JsonException;
8+
use PHPUnit\Framework\Attributes\IgnoreMethodForCodeCoverage;
89
use PHPUnit\Framework\TestCase;
910
use function chmod;
1011
use function file_put_contents;
1112
use function touch;
1213

14+
// Cannot be tested as file_get_contents is calling a URI, and we cannot fake its results.
15+
#[IgnoreMethodForCodeCoverage(Reader::class, 'httpReadJson')]
1316
final class ReaderTest extends TestCase
1417
{
1518
use TraitTestSystem;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Tests\Hal\DependencyInjection;
5+
6+
use Hal\DependencyInjection\DependencyInjectionProcessor;
7+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
8+
use PHPUnit\Framework\Attributes\IgnoreClassForCodeCoverage;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* Ignores DependencyInjectionProcessor::class because this is a technical class that can only be tested functionally.
13+
*/
14+
#[DoesNotPerformAssertions]
15+
#[IgnoreClassForCodeCoverage(DependencyInjectionProcessor::class)]
16+
final class DependencyInjectionProcessorTest extends TestCase
17+
{
18+
public function test(): void
19+
{
20+
}
21+
}

0 commit comments

Comments
 (0)