Skip to content

Commit 0fcb91f

Browse files
authored
add support for phpunit 11 (#157)
* phpunit 11 - added sebastian/exporter dependency * attribute instead of annotation meta * drop phpunit 9 support * upped minimal phpunit dependency to 10.5.11
1 parent 2bd8962 commit 0fcb91f

27 files changed

+169
-271
lines changed

PhpUnit/AbstractCompilerPassTestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Matthias\SymfonyDependencyInjectionTest\PhpUnit;
44

5+
use PHPUnit\Framework\Attributes\CoversNothing;
6+
use PHPUnit\Framework\Attributes\Test;
57
use Symfony\Component\DependencyInjection\ContainerBuilder;
68

79
abstract class AbstractCompilerPassTestCase extends AbstractContainerBuilderTestCase
@@ -16,11 +18,9 @@ abstract protected function registerCompilerPass(ContainerBuilder $container): v
1618

1719
/**
1820
* This test will run the compile method.
19-
*
20-
* @test
21-
*
22-
* @coversNothing
2321
*/
22+
#[Test]
23+
#[CoversNothing]
2424
final public function compilation_should_not_fail_with_empty_container(): void
2525
{
2626
try {

PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7+
use SebastianBergmann\Exporter\Exporter;
78
use Symfony\Component\DependencyInjection\ContainerBuilder;
89

910
final class ContainerBuilderHasServiceDefinitionConstraint extends Constraint
1011
{
1112
private $serviceId;
1213
private $expectedClass;
1314
private $checkExpectedClass;
15+
private $exporter;
1416

1517
public function __construct(
1618
string $serviceId,
@@ -20,6 +22,7 @@ public function __construct(
2022
$this->serviceId = $serviceId;
2123
$this->expectedClass = $expectedClass;
2224
$this->checkExpectedClass = $checkExpectedClass;
25+
$this->exporter = new Exporter();
2326
}
2427

2528
public function toString(): string
@@ -85,8 +88,8 @@ private function evaluateClass(ContainerBuilder $containerBuilder, bool $returnR
8588
$this->fail($containerBuilder, sprintf(
8689
'The class of the service definition of "%s" (%s) does not match the expected value (%s)',
8790
$this->serviceId,
88-
$this->exporter()->export($actualClass),
89-
$this->exporter()->export($this->expectedClass)
91+
$this->exporter->export($actualClass),
92+
$this->exporter->export($this->expectedClass)
9093
));
9194
}
9295

PhpUnit/ContainerHasParameterConstraint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
77
use PHPUnit\Framework\Constraint\IsIdentical;
8+
use SebastianBergmann\Exporter\Exporter;
89
use Symfony\Component\DependencyInjection\ContainerInterface;
910

1011
final class ContainerHasParameterConstraint extends Constraint
@@ -13,6 +14,7 @@ final class ContainerHasParameterConstraint extends Constraint
1314
private $expectedParameterValue;
1415
private $checkParameterValue;
1516
private $strict;
17+
private $exporter;
1618

1719
public function __construct(
1820
string $parameterName,
@@ -24,6 +26,7 @@ public function __construct(
2426
$this->expectedParameterValue = $expectedParameterValue;
2527
$this->checkParameterValue = $checkParameterValue;
2628
$this->strict = $strict;
29+
$this->exporter = new Exporter();
2730
}
2831

2932
public function toString(): string
@@ -83,8 +86,8 @@ private function evaluateParameterValue(ContainerInterface $container, bool $ret
8386
$this->fail($container, sprintf(
8487
'The value of parameter "%s" (%s) does not match the expected value (%s)',
8588
$this->parameterName,
86-
$this->exporter()->export($actualValue),
87-
$this->exporter()->export($this->expectedParameterValue)
89+
$this->exporter->export($actualValue),
90+
$this->exporter->export($this->expectedParameterValue)
8891
));
8992
}
9093

PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7+
use SebastianBergmann\Exporter\Exporter;
78
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
910
use Symfony\Component\DependencyInjection\Definition;
@@ -19,6 +20,7 @@ final class DefinitionArgumentEqualsServiceLocatorConstraint extends Constraint
1920
private $argumentIndex;
2021
private $expectedValue;
2122
private $serviceId;
23+
private $exporter;
2224

2325
public function __construct(string $serviceId, $argumentIndex, array $expectedValue)
2426
{
@@ -54,6 +56,8 @@ function ($serviceId) {
5456
},
5557
$expectedValue
5658
);
59+
60+
$this->exporter = new Exporter();
5761
}
5862

5963
public function toString(): string
@@ -126,7 +130,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return
126130
sprintf(
127131
'The value of argument with index %s (%s) was expected to an instance of Symfony\Component\DependencyInjection\Reference or \Symfony\Component\DependencyInjection\Definition',
128132
$this->argumentIndex,
129-
$this->exporter()->export($actualValue)
133+
$this->exporter->export($actualValue)
130134
)
131135
);
132136
}
@@ -141,7 +145,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return
141145
sprintf(
142146
'The referenced service class of argument with index %s (%s) was expected to be an instance of Symfony\Component\DependencyInjection\ServiceLocator',
143147
$this->argumentIndex,
144-
$this->exporter()->export($serviceLocatorDef->getClass())
148+
$this->exporter->export($serviceLocatorDef->getClass())
145149
)
146150
);
147151
}
@@ -172,8 +176,8 @@ private function evaluateServiceDefinition(
172176
sprintf(
173177
'The value of argument with index %s (%s) does not equal to the expected ServiceLocator service-map (%s)',
174178
$this->argumentIndex,
175-
$this->exporter()->export($actualValue),
176-
$this->exporter()->export($this->expectedValue)
179+
$this->exporter->export($actualValue),
180+
$this->exporter->export($this->expectedValue)
177181
)
178182
);
179183
}

PhpUnit/DefinitionEqualsServiceLocatorConstraint.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7+
use SebastianBergmann\Exporter\Exporter;
78
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
89
use Symfony\Component\DependencyInjection\Definition;
910
use Symfony\Component\DependencyInjection\Reference;
@@ -12,6 +13,7 @@
1213
final class DefinitionEqualsServiceLocatorConstraint extends Constraint
1314
{
1415
private $expectedValue;
16+
private $exporter;
1517

1618
public function __construct($expectedValue)
1719
{
@@ -29,6 +31,7 @@ function ($serviceId) {
2931
},
3032
$expectedValue
3133
);
34+
$this->exporter = new Exporter();
3235
}
3336

3437
public function toString(): string
@@ -70,8 +73,8 @@ private function evaluateServiceDefinitionClass(Definition $definition, bool $re
7073
$definition,
7174
sprintf(
7275
'class %s was expected as service definition class, found %s instead',
73-
$this->exporter()->export(ServiceLocator::class),
74-
$this->exporter()->export($definition->getClass())
76+
$this->exporter->export(ServiceLocator::class),
77+
$this->exporter->export($definition->getClass())
7578
)
7679
);
7780
}
@@ -90,8 +93,8 @@ private function evaluateArgumentIndex(Definition $definition, bool $returnResul
9093
$definition,
9194
sprintf(
9295
'The service-map %s does not equal to the expected service-map (%s)',
93-
$this->exporter()->export($actualValue),
94-
$this->exporter()->export($this->expectedValue)
96+
$this->exporter->export($actualValue),
97+
$this->exporter->export($this->expectedValue)
9598
)
9699
);
97100
}

PhpUnit/DefinitionHasMethodCallConstraint.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7+
use SebastianBergmann\Exporter\Exporter;
78
use Symfony\Component\DependencyInjection\Definition;
89

910
final class DefinitionHasMethodCallConstraint extends Constraint
1011
{
1112
private $methodName;
1213
private $arguments;
1314
private $index;
15+
private $exporter;
1416

1517
public function __construct(string $methodName, array $arguments = [], $index = null)
1618
{
@@ -21,6 +23,7 @@ public function __construct(string $methodName, array $arguments = [], $index =
2123
$this->methodName = $methodName;
2224
$this->arguments = $arguments;
2325
$this->index = $index;
26+
$this->exporter = new Exporter();
2427
}
2528

2629
public function evaluate($other, string $description = '', bool $returnResult = false): bool
@@ -55,7 +58,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
5558
sprintf(
5659
'None of the method calls matched the expected method "%s" with arguments %s with %s invocation order index',
5760
$this->methodName,
58-
$this->exporter()->export($this->arguments),
61+
$this->exporter->export($this->arguments),
5962
(null === $this->index) ? 'any' : sprintf('"%s"', $this->index)
6063
)
6164
);

PhpUnit/DefinitionHasTagConstraint.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7+
use SebastianBergmann\Exporter\Exporter;
78
use Symfony\Component\DependencyInjection\Definition;
89

910
final class DefinitionHasTagConstraint extends Constraint
1011
{
1112
private $name;
1213
private $attributes;
14+
private $exporter;
1315

1416
public function __construct(string $name, array $attributes = [])
1517
{
1618
$this->name = $name;
1719
$this->attributes = $attributes;
20+
$this->exporter = new Exporter();
1821
}
1922

2023
public function evaluate($other, string $description = '', bool $returnResult = false): bool
@@ -42,7 +45,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
4245
sprintf(
4346
'None of the tags matched the expected name "%s" with attributes %s',
4447
$this->name,
45-
$this->exporter()->export($this->attributes)
48+
$this->exporter->export($this->attributes)
4649
)
4750
);
4851
}

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,10 @@ container:
347347

348348
## Version Guidance
349349

350-
| Version | Released | PHPUnit | Status |
351-
|---------|--------------|-------------|------------|
352-
| 4.x | Mar 28, 2019 | 8.x and 9.x | Latest |
353-
| 3.x | Mar 5, 2018 | 7.x | Bugfixes |
354-
| 2.x | May 9, 2017 | 6.x | Bugfixes |
355-
| 1.x | Jul 4, 2016 | 4.x and 5.x | EOL |
350+
| Version | Released | PHPUnit | Status |
351+
|---------|--------------|-------------|----------|
352+
| 5.x | Jan 23, 2024 | 9.x, 10.x | Latest |
353+
| 4.x | Mar 28, 2019 | 8.x and 9.x | Bugfixes |
354+
| 3.x | Mar 5, 2018 | 7.x | Bugfixes |
355+
| 2.x | May 9, 2017 | 6.x | Bugfixes |
356+
| 1.x | Jul 4, 2016 | 4.x and 5.x | EOL |

Tests/Loader/LoaderFactoryTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Matthias\SymfonyDependencyInjectionTest\Tests\Loader;
44

55
use Matthias\SymfonyDependencyInjectionTest\Loader\LoaderFactory;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\Attributes\Test;
68
use PHPUnit\Framework\MockObject\MockObject;
79
use PHPUnit\Framework\TestCase;
810
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -13,11 +15,8 @@
1315

1416
class LoaderFactoryTest extends TestCase
1517
{
16-
/**
17-
* @test
18-
*
19-
* @dataProvider fileProvider
20-
*/
18+
#[Test]
19+
#[DataProvider('fileProvider')]
2120
public function it_creates_the_appropriate_file_loader_based_on_the_extension($file, $expectedClass): void
2221
{
2322
$factory = new LoaderFactory();
@@ -26,9 +25,7 @@ public function it_creates_the_appropriate_file_loader_based_on_the_extension($f
2625
$this->assertInstanceOf($expectedClass, $loader);
2726
}
2827

29-
/**
30-
* @test
31-
*/
28+
#[Test]
3229
public function it_creates_a_closure_loader_when_source_is_a_closure(): void
3330
{
3431
$source = function (): void {

Tests/PhpUnit/AbstractCompilerPassTestCaseTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
66
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\CollectServicesAndAddThemWithMethodCallsCompilerPass;
77
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\CollectServicesAndSetThemAsArgumentCompilerPass;
8+
use PHPUnit\Framework\Attributes\Test;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
910
use Symfony\Component\DependencyInjection\Definition;
1011
use Symfony\Component\DependencyInjection\Reference;
@@ -17,9 +18,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void
1718
$container->addCompilerPass(new CollectServicesAndSetThemAsArgumentCompilerPass());
1819
}
1920

20-
/**
21-
* @test
22-
*/
21+
#[Test]
2322
public function if_compiler_pass_collects_services_by_adding_method_calls_these_can_be_asserted_to_exist(): void
2423
{
2524
$collectingService = new Definition();
@@ -52,9 +51,7 @@ public function if_compiler_pass_collects_services_by_adding_method_calls_these_
5251
);
5352
}
5453

55-
/**
56-
* @test
57-
*/
54+
#[Test]
5855
public function if_compiler_pass_collects_services_by_setting_constructor_argument_it_can_be_asserted_to_exist(): void
5956
{
6057
$collectingService = new Definition();

Tests/PhpUnit/AbstractDependableExtensionTestCaseTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
66
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\DependableExtension;
77
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\NonDependablePrependableExtension;
8+
use PHPUnit\Framework\Attributes\Test;
89

910
class AbstractDependableExtensionTestCaseTest extends AbstractExtensionTestCase
1011
{
@@ -16,9 +17,7 @@ protected function getContainerExtensions(): array
1617
];
1718
}
1819

19-
/**
20-
* @test
21-
*/
20+
#[Test]
2221
public function prepend_invoked_before_any_load(): void
2322
{
2423
$this->load();

Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
66
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\SimpleConfiguration;
77
use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\SimpleExtension;
8+
use PHPUnit\Framework\Attributes\Test;
89
use Symfony\Component\Config\Definition\ConfigurationInterface;
910
use Symfony\Component\DependencyInjection\ContainerBuilder;
1011
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@@ -21,9 +22,7 @@ protected function getConfiguration(): ConfigurationInterface
2122
return new SimpleConfiguration();
2223
}
2324

24-
/**
25-
* @test
26-
*/
25+
#[Test]
2726
public function it_compares_expected_configuration_values_with_values_loaded_from_files(): void
2827
{
2928
$sources = [

0 commit comments

Comments
 (0)