Skip to content

Commit 3d225ce

Browse files
committed
Updating to phpunit 10
1 parent 5b9c5fe commit 3d225ce

File tree

10 files changed

+61
-31
lines changed

10 files changed

+61
-31
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
"symfony/yaml": "^4|^5",
1919
"mamazu/rst": "^2.0",
2020
"symfony/filesystem": "^4|^5.3",
21-
"symfony/dotenv": "^4|^5"
21+
"symfony/dotenv": "^4|^5",
22+
"webmozart/assert": "^1.11"
2223
},
2324
"require-dev": {
2425
"mikey179/vfsstream": "^1.6",
2526
"phpstan/phpstan": "^0.12.78",
2627
"phpstan/phpstan-strict-rules": "^0.12.9",
2728
"phpstan/phpstan-webmozart-assert": "^0.12.12",
2829
"symplify/easy-coding-standard": "^10.2.4",
29-
"phpunit/phpunit": "^9.5"
30+
"phpunit/phpunit": "^10.0",
31+
"rector/rector": "^0.11.60"
3032
},
3133
"autoload": {
3234
"psr-4": {

rector.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Core\Configuration\Option;
6+
use Rector\Set\ValueObject\SetList;
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
9+
return static function (ContainerConfigurator $containerConfigurator): void {
10+
// get parameters
11+
$parameters = $containerConfigurator->parameters();
12+
$parameters->set(Option::PATHS, [
13+
__DIR__ . '/src'
14+
]);
15+
16+
// Define what rule sets will be applied
17+
$containerConfigurator->import(SetList::DEAD_CODE);
18+
$containerConfigurator->import(SetList::CODE_QUALITY);
19+
20+
// get services (needed for register a single rule)
21+
//$services = $containerConfigurator->services();
22+
23+
// register a single rule
24+
//$services->set(WithConsecutiveRector::class);
25+
};

src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function run(FormatterInterface $formatter, FileList $fileList): void
7676
exit($throwable->getCode());
7777
}
7878

79-
if (count($output) > 0) {
79+
if ($output !== []) {
8080
exit(1);
8181
}
8282
}

src/Output/JsonFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final class JsonFormatter implements FormatterInterface
1010
{
1111
public function format(array $output): string
1212
{
13-
if (count($output) === 0) {
13+
if ($output === []) {
1414
return '';
1515
}
1616

src/Utils/PhpCodeEnsurer.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ public function putPhpCodeToFile(string $sourceCode, string $fileName): void
2424
public function getPHPCode(string $sourceCode): string
2525
{
2626
$sourceCode = trim($sourceCode);
27-
28-
// Finding partial classes: meaning the documentation only contains class bodies
29-
// in this case we just define a class around it for it to be valid php
30-
$matches = [];
3127
if ($this->needsToBeWrappedInClass($sourceCode)) {
3228
if ($this->hasPhpTag($sourceCode)) {
3329
$sourceCode = substr($sourceCode, 5);

src/Validator/CompositeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function validate(Block $block): array
3535
$error = [];
3636
foreach ($this->validators as $validator) {
3737
$newErrors = $validator->validate($block);
38-
if ($this->continueValidationOnFailure || count($newErrors) === 0) {
38+
if ($this->continueValidationOnFailure || $newErrors === []) {
3939
$error = array_merge($error, $newErrors);
4040
} else {
4141
return $newErrors;

src/Validator/JSON/JsonValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class JsonValidator implements ValidatorInterface
1414
public function validate(Block $block): array
1515
{
1616
try {
17-
$content = json_decode($block->getContent(), true, 1024, JSON_THROW_ON_ERROR);
17+
json_decode($block->getContent(), true, 1024, JSON_THROW_ON_ERROR);
1818
} catch (JsonException $e) {
1919
return [
2020
Error::errorFromBlock($block, 1, $e->getMessage()),

src/Validator/Php/PhpClassExistsValidator.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ final class PhpClassExistsValidator implements ValidatorInterface
2626

2727
private PhpCodeEnsurerInterface $codeEnsurer;
2828

29-
/**
30-
* @var false|string
31-
*/
32-
private $phpVersion;
33-
3429
public function __construct(
3530
callable $classExists,
3631
?Parser $parser = null,

tests/Mamazu/DocumentationParser/CLITest.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ protected function setUp(): void
2323

2424
public function testParsesAFilesOnlyParameters(): void
2525
{
26+
$matcher = $this->exactly(2);
2627
/** @var FileList|MockObject $fileList */
2728
$fileList = $this->createMock(FileList::class);
28-
$fileList->expects($this->exactly(2))
29+
$fileList->expects($matcher)
2930
->method('addFile')
30-
->withConsecutive(
31-
['abc.php'],
32-
['cde.md']
33-
);
31+
->willReturnCallback(function (...$args) use ($matcher) {
32+
$expected = [
33+
['abc.php'],
34+
['cde.md'],
35+
];
36+
$this->assertEquals($expected[$matcher->numberOfInvocations() - 1], $args);
37+
});
3438

3539
$this->cLI = new CLI($fileList, ['abc.php', 'cde.md']);
3640
$this->assertSame($fileList, $this->cLI->getFilesToParse());
@@ -39,14 +43,18 @@ public function testParsesAFilesOnlyParameters(): void
3943

4044
public function testParsesAFileAnIncludeFileMix(): void
4145
{
46+
$matcher = $this->exactly(2);
4247
/** @var FileList|MockObject $fileList */
4348
$fileList = $this->createMock(FileList::class);
44-
$fileList->expects($this->exactly(2))
49+
$fileList->expects($matcher)
4550
->method('addFile')
46-
->withConsecutive(
47-
['abc.php'],
48-
['cde.md']
49-
);
51+
->willReturnCallback(function (...$args) use ($matcher) {
52+
$expected = [
53+
['abc.php'],
54+
['cde.md'],
55+
];
56+
$this->assertEquals($expected[$matcher->numberOfInvocations() - 1], $args);
57+
});
5058

5159
$this->workDir->addChild(vfsStream::newFile('bananas.php'));
5260
$this->cLI = new CLI($fileList, ['abc.php', '-i', 'vfs://workDir/bananas.php', 'cde.md']);
@@ -56,14 +64,18 @@ public function testParsesAFileAnIncludeFileMix(): void
5664

5765
public function testHasNoIncludeFileIfNoValueWasGiven(): void
5866
{
67+
$matcher = $this->exactly(2);
5968
/** @var FileList|MockObject $fileList */
6069
$fileList = $this->createMock(FileList::class);
61-
$fileList->expects($this->exactly(2))
70+
$fileList->expects($matcher)
6271
->method('addFile')
63-
->withConsecutive(
64-
['abc.php'],
65-
['cde.md']
66-
);
72+
->willReturnCallback(function (...$args) use ($matcher) {
73+
$expected = [
74+
['abc.php'],
75+
['cde.md'],
76+
];
77+
$this->assertEquals($expected[$matcher->numberOfInvocations() - 1], $args);
78+
});
6779

6880
$this->cLI = new CLI($fileList, ['abc.php', 'cde.md', '-i']);
6981
$this->assertSame($fileList, $this->cLI->getFilesToParse());

tests/Mamazu/DocumentationParser/FileListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetsAllValidFiles(): void
3535
$this->fileList->addFile('vfs://workDir/test.php');
3636
$this->fileList->addFile('vfs://workDir/bananas.php');
3737

38-
$this->fileList->getAllValidFiles();
38+
$this->assertSame(['vfs://workDir/test.php'], iterator_to_array($this->fileList->getAllValidFiles()));
3939
}
4040

4141
public function testAddsAFile(): void

0 commit comments

Comments
 (0)