Skip to content

Commit 6894be1

Browse files
authored
Merge pull request #77 from vladsolntsev/chore/update-phpunit
chore(dependencies): update phpunit/phpunit to 10.5
2 parents 22e79a7 + e5d9f80 commit 6894be1

File tree

7 files changed

+70
-75
lines changed

7 files changed

+70
-75
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/build/
22
/vendor/
3+
/var/
4+
/.phpunit.cache/
35
/.php-cs-fixer.cache
46
/composer.lock
5-
/.phpunit.result.cache

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ master
99
* Replace `fabpot/local-php-security-checker` by `composer audit` for the security check
1010
* Move code snippets into tests directory
1111
* Updated nikic/php-parser to 5.4
12+
* Updated phpunit/phpunit to 10.5
1213

14+
v3.0.0
1315
------
1416

1517
* Updated to PHPStan 2.0

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ app-static-analysis: ## to run static analysis
2626
vendor/bin/phpstan analyze --memory-limit=-1
2727

2828
app-test: ## to run unit tests
29-
vendor/bin/phpunit
29+
vendor/bin/phpunit --no-coverage
3030

3131
app-test-functional: ## test some code snippets are detected as banned code
3232
@for filename in $$(find tests/Functional/snippets -type f -name *.php); do \
@@ -39,6 +39,7 @@ app-test-functional: ## test some code snippets are detected as banned code
3939
done \
4040

4141
app-test-with-code-coverage: ## to run unit tests with code-coverage
42+
@php -m | grep -qE 'xdebug|pcov' || (echo "Please install Xdebug or PCOV to enable code coverage." && exit 1)
4243
vendor/bin/phpunit --coverage-text --colors=never
4344

4445
ci: ## to run checks during ci

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"friendsofphp/php-cs-fixer": "^3.0",
2626
"nikic/php-parser": "^5.4",
2727
"phpstan/phpstan-phpunit": "^2.0",
28-
"phpunit/phpunit": "^9.5",
28+
"phpunit/phpunit": "^10.5",
2929
"symfony/var-dumper": "^5.0"
3030
},
3131
"minimum-stability": "dev",

phpunit.xml.dist

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
beStrictAboutOutputDuringTests="true"
6-
beStrictAboutTodoAnnotatedTests="true"
7-
verbose="true">
8-
<testsuites>
9-
<testsuite name="default">
10-
<directory suffix="Test.php">tests</directory>
11-
</testsuite>
12-
</testsuites>
6+
cacheDirectory=".phpunit.cache">
137

14-
<coverage processUncoveredFiles="true">
15-
<include>
16-
<directory suffix=".php">src</directory>
17-
</include>
18-
<report>
19-
<clover outputFile="build/phpunit/clover.xml"/>
20-
<html outputDirectory="build/phpunit/html"/>
21-
</report>
22-
</coverage>
8+
<testsuites>
9+
<testsuite name="default">
10+
<directory suffix="Test.php">tests</directory>
11+
</testsuite>
12+
</testsuites>
2313

24-
<logging>
25-
<junit outputFile="build/phpunit/junit.xml"/>
26-
</logging>
14+
<coverage>
15+
<report>
16+
<clover outputFile="build/phpunit/clover.xml"/>
17+
<html outputDirectory="build/phpunit/html"/>
18+
</report>
19+
</coverage>
20+
21+
<logging>
22+
<junit outputFile="build/phpunit/junit.xml"/>
23+
</logging>
24+
25+
<source>
26+
<include>
27+
<directory suffix=".php">src</directory>
28+
</include>
29+
</source>
2730
</phpunit>

tests/Unit/Rules/BannedNodesRuleTest.php

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use PHPStan\Rules\IdentifierRuleError;
3333
use PHPStan\Rules\NonIgnorableRuleError;
3434
use PHPStan\Rules\RuleError;
35+
use PHPUnit\Framework\Attributes\DataProvider;
3536
use PHPUnit\Framework\MockObject\MockObject;
3637
use PHPUnit\Framework\TestCase;
3738

@@ -40,15 +41,9 @@
4041
*/
4142
class BannedNodesRuleTest extends TestCase
4243
{
43-
/**
44-
* @var BannedNodesRule
45-
*/
46-
private $rule;
47-
48-
/**
49-
* @var Scope|MockObject
50-
*/
51-
private $scope;
44+
private BannedNodesRule $rule;
45+
46+
private Scope&MockObject $scope;
5247

5348
/**
5449
* {@inheritdoc}
@@ -77,18 +72,6 @@ public function testGetNodeType(): void
7772
$this->assertSame(Node::class, $this->rule->getNodeType());
7873
}
7974

80-
/**
81-
* Tests processNode with unhandled nodes.
82-
*
83-
* @param Expr $node
84-
*
85-
* @dataProvider getUnhandledNodes
86-
*/
87-
public function testProcessNodeWithUnhandledType(Expr $node): void
88-
{
89-
$this->assertCount(0, $this->rule->processNode($node, $this->scope));
90-
}
91-
9275
public function testProcessNodeWithBannedFunctions(): void
9376
{
9477
$ruleWithoutLeadingSlashes = new BannedNodesRule(
@@ -126,20 +109,6 @@ public function testProcessNodeWithBannedFunctions(): void
126109
$this->assertNodeTriggersError($ruleWithLeadingSlashes, $namespacedFunction);
127110
}
128111

129-
protected function assertNodeTriggersError(BannedNodesRule $rule, Node $node): void
130-
{
131-
$errors = $rule->processNode($node, $this->scope);
132-
$this->assertCount(1, $errors);
133-
$error = $errors[0];
134-
$this->assertStringStartsWith('ekinoBannedCode.', $error->getIdentifier());
135-
$this->assertInstanceOf(NonIgnorableRuleError::class, $error);
136-
}
137-
138-
protected function assertNodePasses(BannedNodesRule $rule, Node $node): void
139-
{
140-
$this->assertCount(0, $rule->processNode($node, $this->scope));
141-
}
142-
143112
public function testProcessNodeWithAllowedFunctions(): void
144113
{
145114
$rootFunction = new FuncCall(new Name('allowed'));
@@ -169,12 +138,22 @@ public function testProcessNodeWithArrayDimFetch(): void
169138
}
170139

171140
/**
172-
* Tests processNode with handled nodes.
141+
* Tests processNode with unhandled nodes.
173142
*
174143
* @param Expr $node
144+
*/
145+
#[DataProvider('getUnhandledNodes')]
146+
public function testProcessNodeWithUnhandledType(Expr $node): void
147+
{
148+
$this->assertCount(0, $this->rule->processNode($node, $this->scope));
149+
}
150+
151+
/**
152+
* Tests processNode with handled nodes.
175153
*
176-
* @dataProvider getHandledNodes
154+
* @param Expr $node
177155
*/
156+
#[DataProvider('getHandledNodes')]
178157
public function testProcessNodeWithHandledTypes(Expr $node): void
179158
{
180159
$this->assertNodeTriggersError($this->rule, $node);
@@ -183,19 +162,35 @@ public function testProcessNodeWithHandledTypes(Expr $node): void
183162
/**
184163
* @return \Generator<array<Include_>>
185164
*/
186-
public function getUnhandledNodes(): \Generator
165+
public static function getUnhandledNodes(): \Generator
187166
{
188-
yield [new Include_($this->createMock(Expr::class), Include_::TYPE_INCLUDE)];
167+
yield [new Include_(new String_('test'), Include_::TYPE_INCLUDE)];
189168
}
190169

191170
/**
192171
* @return \Generator<array<mixed>>
193172
*/
194-
public function getHandledNodes(): \Generator
173+
public static function getHandledNodes(): \Generator
195174
{
196-
yield [new Eval_($this->createMock(Expr::class))];
175+
$stringExpr = new String_('test');
176+
177+
yield [new Eval_($stringExpr)];
197178
yield [new Exit_()];
198-
yield [new Print_($this->createMock(Expr::class))];
199-
yield [new ShellExec([new String_('')])];
179+
yield [new Print_($stringExpr)];
180+
yield [new ShellExec([$stringExpr])];
181+
}
182+
183+
protected function assertNodeTriggersError(BannedNodesRule $rule, Node $node): void
184+
{
185+
$errors = $rule->processNode($node, $this->scope);
186+
$this->assertCount(1, $errors);
187+
$error = $errors[0];
188+
$this->assertStringStartsWith('ekinoBannedCode.', $error->getIdentifier());
189+
$this->assertInstanceOf(NonIgnorableRuleError::class, $error);
190+
}
191+
192+
protected function assertNodePasses(BannedNodesRule $rule, Node $node): void
193+
{
194+
$this->assertCount(0, $rule->processNode($node, $this->scope));
200195
}
201196
}

tests/Unit/Rules/BannedUseTestRuleTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,8 @@
3131
*/
3232
class BannedUseTestRuleTest extends TestCase
3333
{
34-
/**
35-
* @var BannedUseTestRule
36-
*/
37-
private $rule;
38-
39-
/**
40-
* @var Scope|MockObject
41-
*/
42-
private $scope;
34+
private BannedUseTestRule $rule;
35+
private Scope&MockObject $scope;
4336

4437
/**
4538
* {@inheritdoc}

0 commit comments

Comments
 (0)