diff --git a/PhpUnit/AbstractCompilerPassTestCase.php b/PhpUnit/AbstractCompilerPassTestCase.php index 964fbc4..294ae9a 100644 --- a/PhpUnit/AbstractCompilerPassTestCase.php +++ b/PhpUnit/AbstractCompilerPassTestCase.php @@ -2,6 +2,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\PhpUnit; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\DependencyInjection\ContainerBuilder; abstract class AbstractCompilerPassTestCase extends AbstractContainerBuilderTestCase @@ -16,11 +18,9 @@ abstract protected function registerCompilerPass(ContainerBuilder $container): v /** * This test will run the compile method. - * - * @test - * - * @coversNothing */ + #[Test] + #[CoversNothing] final public function compilation_should_not_fail_with_empty_container(): void { try { diff --git a/PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php b/PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php index 85e9f08..7873245 100644 --- a/PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php +++ b/PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; +use SebastianBergmann\Exporter\Exporter; use Symfony\Component\DependencyInjection\ContainerBuilder; final class ContainerBuilderHasServiceDefinitionConstraint extends Constraint @@ -11,6 +12,7 @@ final class ContainerBuilderHasServiceDefinitionConstraint extends Constraint private $serviceId; private $expectedClass; private $checkExpectedClass; + private $exporter; public function __construct( string $serviceId, @@ -20,6 +22,7 @@ public function __construct( $this->serviceId = $serviceId; $this->expectedClass = $expectedClass; $this->checkExpectedClass = $checkExpectedClass; + $this->exporter = new Exporter(); } public function toString(): string @@ -85,8 +88,8 @@ private function evaluateClass(ContainerBuilder $containerBuilder, bool $returnR $this->fail($containerBuilder, sprintf( 'The class of the service definition of "%s" (%s) does not match the expected value (%s)', $this->serviceId, - $this->exporter()->export($actualClass), - $this->exporter()->export($this->expectedClass) + $this->exporter->export($actualClass), + $this->exporter->export($this->expectedClass) )); } diff --git a/PhpUnit/ContainerHasParameterConstraint.php b/PhpUnit/ContainerHasParameterConstraint.php index 66d48b8..1f5417c 100644 --- a/PhpUnit/ContainerHasParameterConstraint.php +++ b/PhpUnit/ContainerHasParameterConstraint.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\Constraint\IsIdentical; +use SebastianBergmann\Exporter\Exporter; use Symfony\Component\DependencyInjection\ContainerInterface; final class ContainerHasParameterConstraint extends Constraint @@ -13,6 +14,7 @@ final class ContainerHasParameterConstraint extends Constraint private $expectedParameterValue; private $checkParameterValue; private $strict; + private $exporter; public function __construct( string $parameterName, @@ -24,6 +26,7 @@ public function __construct( $this->expectedParameterValue = $expectedParameterValue; $this->checkParameterValue = $checkParameterValue; $this->strict = $strict; + $this->exporter = new Exporter(); } public function toString(): string @@ -83,8 +86,8 @@ private function evaluateParameterValue(ContainerInterface $container, bool $ret $this->fail($container, sprintf( 'The value of parameter "%s" (%s) does not match the expected value (%s)', $this->parameterName, - $this->exporter()->export($actualValue), - $this->exporter()->export($this->expectedParameterValue) + $this->exporter->export($actualValue), + $this->exporter->export($this->expectedParameterValue) )); } diff --git a/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php b/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php index 74bc8c4..981bc5a 100644 --- a/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php +++ b/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; +use SebastianBergmann\Exporter\Exporter; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -19,6 +20,7 @@ final class DefinitionArgumentEqualsServiceLocatorConstraint extends Constraint private $argumentIndex; private $expectedValue; private $serviceId; + private $exporter; public function __construct(string $serviceId, $argumentIndex, array $expectedValue) { @@ -54,6 +56,8 @@ function ($serviceId) { }, $expectedValue ); + + $this->exporter = new Exporter(); } public function toString(): string @@ -126,7 +130,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return sprintf( 'The value of argument with index %s (%s) was expected to an instance of Symfony\Component\DependencyInjection\Reference or \Symfony\Component\DependencyInjection\Definition', $this->argumentIndex, - $this->exporter()->export($actualValue) + $this->exporter->export($actualValue) ) ); } @@ -141,7 +145,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return sprintf( 'The referenced service class of argument with index %s (%s) was expected to be an instance of Symfony\Component\DependencyInjection\ServiceLocator', $this->argumentIndex, - $this->exporter()->export($serviceLocatorDef->getClass()) + $this->exporter->export($serviceLocatorDef->getClass()) ) ); } @@ -172,8 +176,8 @@ private function evaluateServiceDefinition( sprintf( 'The value of argument with index %s (%s) does not equal to the expected ServiceLocator service-map (%s)', $this->argumentIndex, - $this->exporter()->export($actualValue), - $this->exporter()->export($this->expectedValue) + $this->exporter->export($actualValue), + $this->exporter->export($this->expectedValue) ) ); } diff --git a/PhpUnit/DefinitionEqualsServiceLocatorConstraint.php b/PhpUnit/DefinitionEqualsServiceLocatorConstraint.php index 07d04a7..8d8d0f3 100644 --- a/PhpUnit/DefinitionEqualsServiceLocatorConstraint.php +++ b/PhpUnit/DefinitionEqualsServiceLocatorConstraint.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; +use SebastianBergmann\Exporter\Exporter; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -12,6 +13,7 @@ final class DefinitionEqualsServiceLocatorConstraint extends Constraint { private $expectedValue; + private $exporter; public function __construct($expectedValue) { @@ -29,6 +31,7 @@ function ($serviceId) { }, $expectedValue ); + $this->exporter = new Exporter(); } public function toString(): string @@ -70,8 +73,8 @@ private function evaluateServiceDefinitionClass(Definition $definition, bool $re $definition, sprintf( 'class %s was expected as service definition class, found %s instead', - $this->exporter()->export(ServiceLocator::class), - $this->exporter()->export($definition->getClass()) + $this->exporter->export(ServiceLocator::class), + $this->exporter->export($definition->getClass()) ) ); } @@ -90,8 +93,8 @@ private function evaluateArgumentIndex(Definition $definition, bool $returnResul $definition, sprintf( 'The service-map %s does not equal to the expected service-map (%s)', - $this->exporter()->export($actualValue), - $this->exporter()->export($this->expectedValue) + $this->exporter->export($actualValue), + $this->exporter->export($this->expectedValue) ) ); } diff --git a/PhpUnit/DefinitionHasMethodCallConstraint.php b/PhpUnit/DefinitionHasMethodCallConstraint.php index 682aca8..76b5c01 100644 --- a/PhpUnit/DefinitionHasMethodCallConstraint.php +++ b/PhpUnit/DefinitionHasMethodCallConstraint.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; +use SebastianBergmann\Exporter\Exporter; use Symfony\Component\DependencyInjection\Definition; final class DefinitionHasMethodCallConstraint extends Constraint @@ -11,6 +12,7 @@ final class DefinitionHasMethodCallConstraint extends Constraint private $methodName; private $arguments; private $index; + private $exporter; public function __construct(string $methodName, array $arguments = [], $index = null) { @@ -21,6 +23,7 @@ public function __construct(string $methodName, array $arguments = [], $index = $this->methodName = $methodName; $this->arguments = $arguments; $this->index = $index; + $this->exporter = new Exporter(); } public function evaluate($other, string $description = '', bool $returnResult = false): bool @@ -55,7 +58,7 @@ public function evaluate($other, string $description = '', bool $returnResult = sprintf( 'None of the method calls matched the expected method "%s" with arguments %s with %s invocation order index', $this->methodName, - $this->exporter()->export($this->arguments), + $this->exporter->export($this->arguments), (null === $this->index) ? 'any' : sprintf('"%s"', $this->index) ) ); diff --git a/PhpUnit/DefinitionHasTagConstraint.php b/PhpUnit/DefinitionHasTagConstraint.php index 11d74e1..28ef636 100644 --- a/PhpUnit/DefinitionHasTagConstraint.php +++ b/PhpUnit/DefinitionHasTagConstraint.php @@ -4,17 +4,20 @@ use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; +use SebastianBergmann\Exporter\Exporter; use Symfony\Component\DependencyInjection\Definition; final class DefinitionHasTagConstraint extends Constraint { private $name; private $attributes; + private $exporter; public function __construct(string $name, array $attributes = []) { $this->name = $name; $this->attributes = $attributes; + $this->exporter = new Exporter(); } public function evaluate($other, string $description = '', bool $returnResult = false): bool @@ -42,7 +45,7 @@ public function evaluate($other, string $description = '', bool $returnResult = sprintf( 'None of the tags matched the expected name "%s" with attributes %s', $this->name, - $this->exporter()->export($this->attributes) + $this->exporter->export($this->attributes) ) ); } diff --git a/README.md b/README.md index 1bfeb4a..ae60f7d 100644 --- a/README.md +++ b/README.md @@ -347,9 +347,10 @@ container: ## Version Guidance -| Version | Released | PHPUnit | Status | -|---------|--------------|-------------|------------| -| 4.x | Mar 28, 2019 | 8.x and 9.x | Latest | -| 3.x | Mar 5, 2018 | 7.x | Bugfixes | -| 2.x | May 9, 2017 | 6.x | Bugfixes | -| 1.x | Jul 4, 2016 | 4.x and 5.x | EOL | +| Version | Released | PHPUnit | Status | +|---------|--------------|-------------|----------| +| 5.x | Jan 23, 2024 | 9.x, 10.x | Latest | +| 4.x | Mar 28, 2019 | 8.x and 9.x | Bugfixes | +| 3.x | Mar 5, 2018 | 7.x | Bugfixes | +| 2.x | May 9, 2017 | 6.x | Bugfixes | +| 1.x | Jul 4, 2016 | 4.x and 5.x | EOL | diff --git a/Tests/Loader/LoaderFactoryTest.php b/Tests/Loader/LoaderFactoryTest.php index de17e1e..fb0ae51 100644 --- a/Tests/Loader/LoaderFactoryTest.php +++ b/Tests/Loader/LoaderFactoryTest.php @@ -3,6 +3,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Loader; use Matthias\SymfonyDependencyInjectionTest\Loader\LoaderFactory; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -13,11 +15,8 @@ class LoaderFactoryTest extends TestCase { - /** - * @test - * - * @dataProvider fileProvider - */ + #[Test] + #[DataProvider('fileProvider')] public function it_creates_the_appropriate_file_loader_based_on_the_extension($file, $expectedClass): void { $factory = new LoaderFactory(); @@ -26,9 +25,7 @@ public function it_creates_the_appropriate_file_loader_based_on_the_extension($f $this->assertInstanceOf($expectedClass, $loader); } - /** - * @test - */ + #[Test] public function it_creates_a_closure_loader_when_source_is_a_closure(): void { $source = function (): void { diff --git a/Tests/PhpUnit/AbstractCompilerPassTestCaseTest.php b/Tests/PhpUnit/AbstractCompilerPassTestCaseTest.php index 1b31a9f..b3c70ea 100644 --- a/Tests/PhpUnit/AbstractCompilerPassTestCaseTest.php +++ b/Tests/PhpUnit/AbstractCompilerPassTestCaseTest.php @@ -5,6 +5,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\CollectServicesAndAddThemWithMethodCallsCompilerPass; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\CollectServicesAndSetThemAsArgumentCompilerPass; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -17,9 +18,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new CollectServicesAndSetThemAsArgumentCompilerPass()); } - /** - * @test - */ + #[Test] public function if_compiler_pass_collects_services_by_adding_method_calls_these_can_be_asserted_to_exist(): void { $collectingService = new Definition(); @@ -52,9 +51,7 @@ public function if_compiler_pass_collects_services_by_adding_method_calls_these_ ); } - /** - * @test - */ + #[Test] public function if_compiler_pass_collects_services_by_setting_constructor_argument_it_can_be_asserted_to_exist(): void { $collectingService = new Definition(); diff --git a/Tests/PhpUnit/AbstractDependableExtensionTestCaseTest.php b/Tests/PhpUnit/AbstractDependableExtensionTestCaseTest.php index 780be39..34136b1 100644 --- a/Tests/PhpUnit/AbstractDependableExtensionTestCaseTest.php +++ b/Tests/PhpUnit/AbstractDependableExtensionTestCaseTest.php @@ -5,6 +5,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\DependableExtension; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\NonDependablePrependableExtension; +use PHPUnit\Framework\Attributes\Test; class AbstractDependableExtensionTestCaseTest extends AbstractExtensionTestCase { @@ -16,9 +17,7 @@ protected function getContainerExtensions(): array ]; } - /** - * @test - */ + #[Test] public function prepend_invoked_before_any_load(): void { $this->load(); diff --git a/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php b/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php index 76f210e..b5dfe45 100644 --- a/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php +++ b/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php @@ -5,6 +5,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\SimpleConfiguration; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\SimpleExtension; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; @@ -21,9 +22,7 @@ protected function getConfiguration(): ConfigurationInterface return new SimpleConfiguration(); } - /** - * @test - */ + #[Test] public function it_compares_expected_configuration_values_with_values_loaded_from_files(): void { $sources = [ diff --git a/Tests/PhpUnit/AbstractExtensionTestCaseTest.php b/Tests/PhpUnit/AbstractExtensionTestCaseTest.php index dfd85b6..a67d9b6 100644 --- a/Tests/PhpUnit/AbstractExtensionTestCaseTest.php +++ b/Tests/PhpUnit/AbstractExtensionTestCaseTest.php @@ -4,6 +4,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\MatthiasDependencyInjectionTestExtension; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; class AbstractExtensionTestCaseTest extends AbstractExtensionTestCase @@ -15,9 +16,7 @@ protected function getContainerExtensions(): array ]; } - /** - * @test - */ + #[Test] public function if_load_is_successful_it_does_not_fail(): void { $this->load(); @@ -61,9 +60,7 @@ public function if_load_is_successful_it_does_not_fail(): void $this->assertContainerBuilderHasServiceDefinitionWithArgument('manual_service_id', 1); } - /** - * @test - */ + #[Test] public function if_service_is_undefined_it_fails(): void { $this->load(); @@ -73,9 +70,7 @@ public function if_service_is_undefined_it_fails(): void $this->assertContainerBuilderHasService('undefined', 'AnyClass'); } - /** - * @test - */ + #[Test] public function if_synthetic_service_is_undefined_it_fails(): void { $this->load(); @@ -86,9 +81,7 @@ public function if_synthetic_service_is_undefined_it_fails(): void $this->assertContainerBuilderHasSyntheticService('undefined'); } - /** - * @test - */ + #[Test] public function if_service_is_defined_but_not_synthetic_it_fails(): void { $this->load(); @@ -99,9 +92,7 @@ public function if_service_is_defined_but_not_synthetic_it_fails(): void $this->assertContainerBuilderHasSyntheticService('loaded_service_id'); } - /** - * @test - */ + #[Test] public function if_service_is_defined_but_has_another_class_it_fails(): void { $this->load(); @@ -112,9 +103,7 @@ public function if_service_is_defined_but_has_another_class_it_fails(): void $this->assertContainerBuilderHasService('manual_service_id', 'SomeOtherClass'); } - /** - * @test - */ + #[Test] public function if_alias_is_not_defined_it_fails(): void { $this->load(); @@ -124,9 +113,7 @@ public function if_alias_is_not_defined_it_fails(): void $this->assertContainerBuilderHasAlias('undefined', 'any_service_id'); } - /** - * @test - */ + #[Test] public function if_alias_exists_but_for_wrong_service_it_fails(): void { $this->load(); @@ -137,9 +124,7 @@ public function if_alias_exists_but_for_wrong_service_it_fails(): void $this->assertContainerBuilderHasAlias('manual_alias', 'wrong'); } - /** - * @test - */ + #[Test] public function if_parameter_does_not_exist_it_fails(): void { $this->load(); @@ -150,9 +135,7 @@ public function if_parameter_does_not_exist_it_fails(): void $this->assertContainerBuilderHasParameter('undefined', 'any value'); } - /** - * @test - */ + #[Test] public function if_parameter_exists_but_has_wrong_value_it_fails(): void { $this->load(); @@ -163,9 +146,7 @@ public function if_parameter_exists_but_has_wrong_value_it_fails(): void $this->assertContainerBuilderHasParameter('manual_parameter', 'wrong'); } - /** - * @test - */ + #[Test] public function if_parameter_exists_and_has_good_value_but_has_wrong_type_it_fails(): void { $this->load(); @@ -176,9 +157,7 @@ public function if_parameter_exists_and_has_good_value_but_has_wrong_type_it_fai $this->assertContainerBuilderHasExactParameter('manual_number_parameter', '123123'); } - /** - * @test - */ + #[Test] public function if_parameter_exists_but_has_wrong_order_it_fails(): void { $this->load(); @@ -189,9 +168,7 @@ public function if_parameter_exists_but_has_wrong_order_it_fails(): void $this->assertContainerBuilderHasExactParameter('manual_array_parameter', ['key2' => 'value2', 'key1' => 'value1']); } - /** - * @test - */ + #[Test] public function if_definition_does_not_have_argument_it_fails(): void { $this->load(); @@ -202,9 +179,7 @@ public function if_definition_does_not_have_argument_it_fails(): void $this->assertContainerBuilderHasServiceDefinitionWithArgument('manual_service_id', 10, 'any value'); } - /** - * @test - */ + #[Test] public function if_definition_has_argument_but_with_wrong_value_it_fails(): void { $this->load(); @@ -214,9 +189,7 @@ public function if_definition_has_argument_but_with_wrong_value_it_fails(): void $this->assertContainerBuilderHasServiceDefinitionWithArgument('manual_service_id', 1, 'wrong value'); } - /** - * @test - */ + #[Test] public function if_definition_has_argument_but_with_wrong_value_it_fails1(): void { $this->load(); @@ -227,9 +200,7 @@ public function if_definition_has_argument_but_with_wrong_value_it_fails1(): voi $this->assertContainerBuilderHasServiceDefinitionWithArgument('manual_with_reference', 0, 'manual_service_id'); } - /** - * @test - */ + #[Test] public function if_definition_is_decorated_and_argument_has_wrong_value_it_fails(): void { $this->load(); @@ -240,9 +211,7 @@ public function if_definition_is_decorated_and_argument_has_wrong_value_it_fails $this->assertContainerBuilderHasServiceDefinitionWithArgument('child_service_id', 1, 'wrong value'); } - /** - * @test - */ + #[Test] public function if_definition_is_decorated_but_by_the_wrong_parent_it_fails(): void { $this->load(); @@ -253,9 +222,7 @@ public function if_definition_is_decorated_but_by_the_wrong_parent_it_fails(): v $this->assertContainerBuilderHasServiceDefinitionWithParent('child_service_id', 'wrong_parent_service_id'); } - /** - * @test - */ + #[Test] public function if_definition_should_be_decorated_when_it_is_not_it_fails(): void { $this->load(); @@ -266,9 +233,7 @@ public function if_definition_should_be_decorated_when_it_is_not_it_fails(): voi $this->assertContainerBuilderHasServiceDefinitionWithParent('parent_service_id', 'any_other_service_id'); } - /** - * @test - */ + #[Test] public function if_definition_should_have_a_method_call_and_it_has_not_it_fails(): void { $this->load(); @@ -283,9 +248,7 @@ public function if_definition_should_have_a_method_call_and_it_has_not_it_fails( ); } - /** - * @test - */ + #[Test] public function if_definition_should_have_a_certain_arguments_for_a_method_call_and_it_has_not_it_fails(): void { $this->load(); @@ -300,9 +263,7 @@ public function if_definition_should_have_a_certain_arguments_for_a_method_call_ ); } - /** - * @test - */ + #[Test] public function if_service_is_defined_it_fails(): void { $this->load(); @@ -312,9 +273,7 @@ public function if_service_is_defined_it_fails(): void $this->assertContainerBuilderNotHasService('loaded_service_id'); } - /** - * @test - */ + #[Test] public function if_service_is_not_defined_it_does_not_fail(): void { $this->load(); @@ -322,9 +281,7 @@ public function if_service_is_not_defined_it_does_not_fail(): void $this->assertContainerBuilderNotHasService('undefined'); } - /** - * @test - */ + #[Test] public function if_service_is_not_defined_in_service_decoration_it_fails(): void { $this->load(); @@ -335,9 +292,7 @@ public function if_service_is_not_defined_in_service_decoration_it_fails(): void $this->assertContainerBuilderServiceDecoration('undefined', 'undefined'); } - /** - * @test - */ + #[Test] public function if_service_decoration_is_not_defined_in_service_decoration_it_fails(): void { $this->load(); diff --git a/Tests/PhpUnit/AbstractPrependExtensionTestCaseTest.php b/Tests/PhpUnit/AbstractPrependExtensionTestCaseTest.php index da19553..b055c0b 100644 --- a/Tests/PhpUnit/AbstractPrependExtensionTestCaseTest.php +++ b/Tests/PhpUnit/AbstractPrependExtensionTestCaseTest.php @@ -5,6 +5,7 @@ use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\NonPrependableTestExtension; use Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures\PrependableTestExtension; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; class AbstractPrependExtensionTestCaseTest extends AbstractExtensionTestCase @@ -17,9 +18,7 @@ protected function getContainerExtensions(): array ]; } - /** - * @test - */ + #[Test] public function prepend_invoked_only_if_prepend_interface_is_implemented(): void { $this->load(); @@ -27,9 +26,7 @@ public function prepend_invoked_only_if_prepend_interface_is_implemented(): void $this->assertContainerBuilderHasParameter('prepend_parameter_set', 'prepended value'); } - /** - * @test - */ + #[Test] public function if_prepend_interface_is_not_implemented_prepend_is_not_invoked(): void { $this->load(); diff --git a/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php b/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php index 428df7d..7f28d58 100644 --- a/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php +++ b/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php @@ -3,16 +3,15 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasAliasConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; class ContainerBuilderHasAliasConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider containerBuilderProvider - */ + #[Test] + #[DataProvider('containerBuilderProvider')] public function match(ContainerBuilder $containerBuilder, $alias, $expectedServiceId, $shouldMatch): void { $constraint = new ContainerBuilderHasAliasConstraint($alias, $expectedServiceId); @@ -44,9 +43,7 @@ public static function containerBuilderProvider() ]; } - /** - * @test - */ + #[Test] public function it_has_a_string_representation(): void { $aliasId = 'alias_id'; @@ -58,9 +55,7 @@ public function it_has_a_string_representation(): void ); } - /** - * @test - */ + #[Test] public function it_does_not_change_case_of_aliased_service_ids(): void { $containerBuilder = new ContainerBuilder(); diff --git a/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php b/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php index 8f23984..6de3e9f 100644 --- a/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php +++ b/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php @@ -3,17 +3,16 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasServiceDefinitionConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; class ContainerBuilderHasServiceDefinitionConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider containerBuilderProvider - */ + #[Test] + #[DataProvider('containerBuilderProvider')] public function match( ContainerBuilder $containerBuilder, $serviceId, @@ -68,9 +67,7 @@ public static function containerBuilderProvider() ]; } - /** - * @test - */ + #[Test] public function it_has_a_string_representation(): void { $serviceId = 'some_service_id'; diff --git a/Tests/PhpUnit/ContainerBuilderHasSyntheticServiceConstraintTest.php b/Tests/PhpUnit/ContainerBuilderHasSyntheticServiceConstraintTest.php index 39d332c..75fe351 100644 --- a/Tests/PhpUnit/ContainerBuilderHasSyntheticServiceConstraintTest.php +++ b/Tests/PhpUnit/ContainerBuilderHasSyntheticServiceConstraintTest.php @@ -3,6 +3,7 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerBuilderHasSyntheticServiceConstraint; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,9 +21,7 @@ protected function setUp(): void $this->containerBuilder = new ContainerBuilder(); } - /** - * @test - */ + #[Test] public function it_fails_if_the_service_definition_is_a_regular_definition(): void { $this->containerBuilder->setDefinition('synthetic_service', new Definition()); @@ -32,9 +31,7 @@ public function it_fails_if_the_service_definition_is_a_regular_definition(): vo $this->assertConstraintFails($constraint); } - /** - * @test - */ + #[Test] public function it_does_not_fail_if_the_synthetic_service_definition_exists(): void { $this->containerBuilder->setDefinition('synthetic_service', $this->createSyntheticDefinition()); @@ -44,9 +41,7 @@ public function it_does_not_fail_if_the_synthetic_service_definition_exists(): v $this->assertConstraintPasses($constraint); } - /** - * @test - */ + #[Test] public function it_does_not_fail_if_the_synthetic_service_has_been_provided_already(): void { $this->containerBuilder->setDefinition('synthetic_service', $this->createSyntheticDefinition()); diff --git a/Tests/PhpUnit/ContainerHasParameterConstraintTest.php b/Tests/PhpUnit/ContainerHasParameterConstraintTest.php index 3aa921d..9f72603 100644 --- a/Tests/PhpUnit/ContainerHasParameterConstraintTest.php +++ b/Tests/PhpUnit/ContainerHasParameterConstraintTest.php @@ -3,16 +3,15 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerHasParameterConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; class ContainerHasParameterConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider containerBuilderProvider - */ + #[Test] + #[DataProvider('containerBuilderProvider')] public function match( array $containerParameters, $parameterName, @@ -26,11 +25,8 @@ public function match( $this->assertSame($expectedToMatch, $constraint->evaluate($container, '', true)); } - /** - * @test - * - * @dataProvider typeAwareContainerBuilderProvider - */ + #[Test] + #[DataProvider('typeAwareContainerBuilderProvider')] public function matchWithType( array $containerParameters, $parameterName, diff --git a/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php b/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php index 2464543..86b6d29 100644 --- a/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php +++ b/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php @@ -3,6 +3,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionArgumentEqualsServiceLocatorConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -25,9 +27,7 @@ protected function setUp(): void $this->containerBuilder = new ContainerBuilder(); } - /** - * @test - */ + #[Test] public function it_fails_if_the_service_definition_is_not_a_service_locator(): void { $this->containerBuilder->setDefinition('not_a_service_locator', new Definition()); @@ -36,9 +36,7 @@ public function it_fails_if_the_service_definition_is_not_a_service_locator(): v $this->assertConstraintFails(new DefinitionArgumentEqualsServiceLocatorConstraint('using_service', 0, [])); } - /** - * @test - */ + #[Test] public function if_fails_if_the_service_definition_value_references_a_missing_service(): void { $this->containerBuilder->setDefinition('using_service', new Definition(\stdClass::class, [new Reference('not_a_service_locator')])); @@ -48,11 +46,8 @@ public function if_fails_if_the_service_definition_value_references_a_missing_se $this->assertConstraintFails(new DefinitionArgumentEqualsServiceLocatorConstraint('using_service', 0, [])); } - /** - * @test - * - * @dataProvider provideInvalidServiceLocatorReferences - */ + #[Test] + #[DataProvider('provideInvalidServiceLocatorReferences')] public function if_fails_if_the_service_definition_value_is_not_a_valid_reference($arguments): void { $this->containerBuilder->setDefinition('service_locator', new Definition(ServiceLocator::class, $arguments)); @@ -69,9 +64,7 @@ public static function provideInvalidServiceLocatorReferences() yield [[new Reference('foo'), null]]; } - /** - * @test - */ + #[Test] public function it_does_not_fail_if_the_service_definition_is_a_service_locator(): void { $definition = new Definition(ServiceLocator::class, [['bar' => new ServiceClosureArgument(new Reference('foo'))]]); @@ -80,9 +73,7 @@ public function it_does_not_fail_if_the_service_definition_is_a_service_locator( $this->assertConstraintPasses(new DefinitionArgumentEqualsServiceLocatorConstraint('using_service', '$l', ['bar' => new Reference('foo')])); } - /** - * @test - */ + #[Test] public function it_does_not_fail_if_the_service_definition_is_a_service_locator_reference(): void { $id = ServiceLocatorTagPass::register($this->containerBuilder, ['bar' => new Reference('foo')]); @@ -93,9 +84,7 @@ public function it_does_not_fail_if_the_service_definition_is_a_service_locator_ ); } - /** - * @test - */ + #[Test] public function it_does_not_fail_if_the_service_definition_is_a_service_locator_with_a_with_a_context(): void { $id = ServiceLocatorTagPass::register($this->containerBuilder, ['bar' => new Reference('foo')], 'using_service'); diff --git a/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php b/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php index 9864384..7683a71 100644 --- a/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php +++ b/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php @@ -3,6 +3,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionDecoratesConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -10,11 +12,8 @@ class DefinitionDecoratesConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider containerBuilderProvider - */ + #[Test] + #[DataProvider('containerBuilderProvider')] public function match(ContainerBuilder $containerBuilder, bool $expectedToMatch, string $serviceId, string $decoratedServiceId, ?string $renamedId, int $priority, ?int $invalidBehavior): void { $constraint = new DefinitionDecoratesConstraint($serviceId, $decoratedServiceId, $renamedId, $priority, $invalidBehavior); @@ -45,11 +44,8 @@ public static function containerBuilderProvider(): iterable yield [$containerBuilder, true, 'decorator5', 'decorated5', 'decorated5_0', -3, 2]; } - /** - * @test - * - * @dataProvider stringRepresentationProvider - */ + #[Test] + #[DataProvider('stringRepresentationProvider')] public function it_has_a_string_representation(DefinitionDecoratesConstraint $constraint, string $expectedRepresentation): void { $this->assertSame($expectedRepresentation, $constraint->toString()); diff --git a/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php b/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php index 5a6d5f7..c1ca8e3 100644 --- a/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php +++ b/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php @@ -3,6 +3,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionEqualsServiceLocatorConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -23,20 +25,15 @@ protected function setUp(): void $this->containerBuilder = new ContainerBuilder(); } - /** - * @test - */ + #[Test] public function it_fails_if_the_service_definition_is_not_a_service_locator(): void { $this->assertConstraintFails(new DefinitionEqualsServiceLocatorConstraint([]), new Definition()); $this->assertConstraintFails(new DefinitionEqualsServiceLocatorConstraint([]), new Definition(\stdClass::class)); } - /** - * @test - * - * @dataProvider provideInvalidServiceLocatorReferences - */ + #[Test] + #[DataProvider('provideInvalidServiceLocatorReferences')] public function if_fails_if_the_service_definition_value_is_not_a_valid_reference($arguments): void { $this->assertConstraintFails( @@ -53,11 +50,8 @@ public static function provideInvalidServiceLocatorReferences() yield [[new Reference('foo'), null]]; } - /** - * @test - * - * @dataProvider provideValidServiceLocatorDefs - */ + #[Test] + #[DataProvider('provideValidServiceLocatorDefs')] public function it_does_not_fail_if_the_service_definition_is_a_service_locator(array $defArguments, array $expected): void { $this->assertConstraintPasses( diff --git a/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php b/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php index 2988272..3bb148f 100644 --- a/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php @@ -3,6 +3,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasArgumentConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -10,11 +12,8 @@ class DefinitionHasArgumentConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider definitionProvider - */ + #[Test] + #[DataProvider('definitionProvider')] public function match(Definition $definition, $argumentIndex, $expectedValue, $shouldMatch): void { $constraint = new DefinitionHasArgumentConstraint($argumentIndex, $expectedValue); @@ -51,13 +50,11 @@ public static function definitionProvider() } /** - * @test - * - * @dataProvider invalid_definition_indexes - * * @param mixed $argument * @param string $exceptionMessage */ + #[Test] + #[DataProvider('invalid_definition_indexes')] public function validates_definitionIndex($argument, $exceptionMessage): void { $this->expectException(\InvalidArgumentException::class); @@ -93,12 +90,10 @@ public static function invalid_definition_indexes() } /** - * @test - * - * @dataProvider indexed_arguments - * * @param int $argumentIndex */ + #[Test] + #[DataProvider('indexed_arguments')] public function supports_indexed_arguments($argumentIndex): void { $expectedValue = 'bar'; @@ -140,12 +135,10 @@ public static function indexed_arguments() } /** - * @test - * - * @dataProvider named_arguments - * * @param string $argument */ + #[Test] + #[DataProvider('named_arguments')] public function supports_named_arguments($argument): void { $expectedValue = 'bar'; diff --git a/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php b/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php index a9ce7ac..db25c9f 100644 --- a/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php @@ -3,16 +3,15 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasMethodCallConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Definition; class DefinitionHasMethodCallConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider definitionProvider - */ + #[Test] + #[DataProvider('definitionProvider')] public function match(Definition $definition, $method, $arguments, $index, $expectedToMatch): void { $constraint = new DefinitionHasMethodCallConstraint($method, $arguments, $index); @@ -48,9 +47,7 @@ public static function definitionProvider() ]; } - /** - * @test - */ + #[Test] public function it_has_a_string_representation(): void { $method = 'methodName'; diff --git a/Tests/PhpUnit/DefinitionHasTagConstraintTest.php b/Tests/PhpUnit/DefinitionHasTagConstraintTest.php index edb10f3..764930e 100644 --- a/Tests/PhpUnit/DefinitionHasTagConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasTagConstraintTest.php @@ -3,17 +3,16 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasTagConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Definition; class DefinitionHasTagConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider definitionProvider - */ + #[Test] + #[DataProvider('definitionProvider')] public function match(Definition $definition, $tag, $attributes, $expectedToMatch): void { $constraint = new DefinitionHasTagConstraint($tag, $attributes); @@ -21,11 +20,8 @@ public function match(Definition $definition, $tag, $attributes, $expectedToMatc $this->assertSame($expectedToMatch, $constraint->evaluate($definition, '', true)); } - /** - * @test - * - * @dataProvider definitionProvider - */ + #[Test] + #[DataProvider('definitionProvider')] public function evaluateThrowsExceptionOnFailure(Definition $definition, $tag, $attributes, $expectedToMatch): void { $constraint = new DefinitionHasTagConstraint($tag, $attributes); @@ -69,9 +65,7 @@ public static function definitionProvider() ]; } - /** - * @test - */ + #[Test] public function it_has_a_string_representation(): void { $tag = 'tagName'; diff --git a/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php b/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php index e5905cc..1c82f0c 100644 --- a/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php +++ b/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php @@ -3,6 +3,8 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\PhpUnit; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionIsChildOfConstraint; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Definition; @@ -10,11 +12,8 @@ class DefinitionIsChildOfConstraintTest extends TestCase { - /** - * @test - * - * @dataProvider definitionProvider - */ + #[Test] + #[DataProvider('definitionProvider')] public function match(Definition $definition, $parentServiceId, $expectedToMatch): void { $constraint = new DefinitionIsChildOfConstraint($parentServiceId); diff --git a/composer.json b/composer.json index 8f9a2f1..55a72ee 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,12 @@ "require": { "php": "^8.1", "matthiasnoback/symfony-config-test": "^5.0", + "phpunit/phpunit": "^10.5.11 || ^11.0", + "sebastian/exporter": " ^5.0 || ^6.0", "symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0", "symfony/config": "^5.4 || ^6.2 || ^7.0", "symfony/yaml": "^5.4 || ^6.2 || ^7.0" }, - "require-dev": { - "phpunit/phpunit": "^9.6 || ^10.0" - }, - "conflict": { - "phpunit/phpunit": "<9.6 || >=11.0" - }, "autoload": { "psr-4" : { "Matthias\\SymfonyDependencyInjectionTest\\" : "" }, "exclude-from-classmap": ["/Tests/"] diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 27de55f..e2eaf9c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,17 @@ - - - - Tests - - - - - - ./ - - - ./Tests - ./vendor - - + + + + Tests + + + + + ./ + + + ./Tests + ./vendor + +