diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 78decd8..830b722 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,19 +14,26 @@ jobs: - '8.1' - '8.2' - '8.3' + - '8.4' dependency: - '' symfony: - '5.4.*' - '6.4.*' - - '7.0.*' + - '7.3.*' include: - php: '8.1' symfony: '5.4.*' dependency: 'lowest' + - php: '8.4' + symfony: '7.4.*@dev' + dependency: '' + - php: '8.4' + symfony: '8.0.*@dev' + dependency: '' exclude: - php: '8.1' - symfony: '7.0.*' + symfony: '7.3.*' fail-fast: false steps: - name: Checkout diff --git a/Loader/LoaderFactory.php b/Loader/LoaderFactory.php index f1b05ab..9a8cd69 100644 --- a/Loader/LoaderFactory.php +++ b/Loader/LoaderFactory.php @@ -48,6 +48,12 @@ public function createYamlFileLoader($container): YamlFileLoader public function createXmlFileLoader(ContainerBuilder $container): XmlFileLoader { + trigger_deprecation('matthiasnoback/symfony-dependency-injection-test', '6.2', 'Support for XML service definitions is deprecated.'); + + if (!class_exists(XmlFileLoader::class)) { + throw new \RuntimeException('Cannot create the XML loader because the installed version of "symfony/dependency-injection" does not support XML.'); + } + return new XmlFileLoader($container, new FileLocator()); } diff --git a/PhpUnit/AbstractCompilerPassTestCase.php b/PhpUnit/AbstractCompilerPassTestCase.php index 294ae9a..2456d3b 100644 --- a/PhpUnit/AbstractCompilerPassTestCase.php +++ b/PhpUnit/AbstractCompilerPassTestCase.php @@ -2,7 +2,6 @@ namespace Matthias\SymfonyDependencyInjectionTest\PhpUnit; -use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\Attributes\Test; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,7 +19,6 @@ abstract protected function registerCompilerPass(ContainerBuilder $container): v * This test will run the compile method. */ #[Test] - #[CoversNothing] final public function compilation_should_not_fail_with_empty_container(): void { try { diff --git a/Tests/Fixtures/DependableExtension.php b/Tests/Fixtures/DependableExtension.php index 60c0ba3..c8437fe 100644 --- a/Tests/Fixtures/DependableExtension.php +++ b/Tests/Fixtures/DependableExtension.php @@ -3,27 +3,19 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\DependencyInjection\Extension\Extension; -class DependableExtension implements ExtensionInterface +class DependableExtension extends Extension { - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { if ($container->hasParameter('parameter_from_non_dependable')) { $container->setParameter('dependable_parameter', 'dependable value'); } } - public function getAlias() + public function getAlias(): string { return 'dependable'; } - - public function getNamespace(): void - { - } - - public function getXsdValidationBasePath(): void - { - } } diff --git a/Tests/Fixtures/MatthiasDependencyInjectionTestExtension.php b/Tests/Fixtures/MatthiasDependencyInjectionTestExtension.php index aa19748..c4ce538 100644 --- a/Tests/Fixtures/MatthiasDependencyInjectionTestExtension.php +++ b/Tests/Fixtures/MatthiasDependencyInjectionTestExtension.php @@ -5,17 +5,17 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; -class MatthiasDependencyInjectionTestExtension implements ExtensionInterface +class MatthiasDependencyInjectionTestExtension extends Extension { - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { // load some service definitions - $loader = new XmlFileLoader($container, new FileLocator(__DIR__)); - $loader->load('services.xml'); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__)); + $loader->load('services.php'); // set a parameter manually $container->setParameter('manual_parameter', 'parameter value'); @@ -41,16 +41,8 @@ public function load(array $config, ContainerBuilder $container): void $container->setDefinition('manual_with_reference', $definition); } - public function getAlias() + public function getAlias(): string { return 'matthias_dependency_injection_test'; } - - public function getNamespace(): void - { - } - - public function getXsdValidationBasePath(): void - { - } } diff --git a/Tests/Fixtures/NonDependablePrependableExtension.php b/Tests/Fixtures/NonDependablePrependableExtension.php index d6c9398..591b796 100644 --- a/Tests/Fixtures/NonDependablePrependableExtension.php +++ b/Tests/Fixtures/NonDependablePrependableExtension.php @@ -3,29 +3,21 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -class NonDependablePrependableExtension implements ExtensionInterface, PrependExtensionInterface +class NonDependablePrependableExtension extends Extension implements PrependExtensionInterface { - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { } - public function getAlias() + public function getAlias(): string { return 'non_dependable'; } - public function getNamespace(): void - { - } - - public function getXsdValidationBasePath(): void - { - } - - public function prepend(ContainerBuilder $container) + public function prepend(ContainerBuilder $container): void { $container->setParameter('parameter_from_non_dependable', 'non-dependable value'); } diff --git a/Tests/Fixtures/NonPrependableTestExtension.php b/Tests/Fixtures/NonPrependableTestExtension.php index 7ba9f0c..27db5d9 100644 --- a/Tests/Fixtures/NonPrependableTestExtension.php +++ b/Tests/Fixtures/NonPrependableTestExtension.php @@ -3,29 +3,21 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\DependencyInjection\Extension\Extension; -class NonPrependableTestExtension implements ExtensionInterface +class NonPrependableTestExtension extends Extension { public function prepend(ContainerBuilder $container): void { $container->setParameter('ignored_invocation', 'ignored value'); } - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { } - public function getAlias() + public function getAlias(): string { return 'non_prependable_test'; } - - public function getNamespace(): void - { - } - - public function getXsdValidationBasePath(): void - { - } } diff --git a/Tests/Fixtures/PrependableTestExtension.php b/Tests/Fixtures/PrependableTestExtension.php index 490ccf9..4891f77 100644 --- a/Tests/Fixtures/PrependableTestExtension.php +++ b/Tests/Fixtures/PrependableTestExtension.php @@ -3,30 +3,22 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -class PrependableTestExtension implements ExtensionInterface, PrependExtensionInterface +class PrependableTestExtension extends Extension implements PrependExtensionInterface { public function prepend(ContainerBuilder $container): void { $container->setParameter('prepend_parameter_set', 'prepended value'); } - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { } - public function getAlias() + public function getAlias(): string { return 'prependable_test'; } - - public function getNamespace(): void - { - } - - public function getXsdValidationBasePath(): void - { - } } diff --git a/Tests/Fixtures/SimpleExtension.php b/Tests/Fixtures/SimpleExtension.php index e81317b..4b66d4a 100644 --- a/Tests/Fixtures/SimpleExtension.php +++ b/Tests/Fixtures/SimpleExtension.php @@ -3,24 +3,16 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Fixtures; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\DependencyInjection\Extension\Extension; -class SimpleExtension implements ExtensionInterface +class SimpleExtension extends Extension { - public function load(array $config, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $container): void { } - public function getAlias() + public function getAlias(): string { return 'simple'; } - - public function getNamespace(): void - { - } - - public function getXsdValidationBasePath(): void - { - } } diff --git a/Tests/Fixtures/services.php b/Tests/Fixtures/services.php new file mode 100644 index 0000000..26ddecb --- /dev/null +++ b/Tests/Fixtures/services.php @@ -0,0 +1,23 @@ +services() + ->set('loaded_service_id', \stdClass::class) + + ->set('parent_service_id', \stdClass::class) + + ->set('child_service_id') + ->parent('parent_service_id') + ->args([ + 'first argument', + 'second argument', + ]) + + ->set('service_with_method_calls_id') + ->call('theRightMethodName', ['first argument', 'second argument']) + + ->set('synthetic_service') + ->synthetic(); +}; diff --git a/Tests/Fixtures/services.xml b/Tests/Fixtures/services.xml deleted file mode 100644 index 9abc74b..0000000 --- a/Tests/Fixtures/services.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - first argument - second argument - - - - - first argument - second argument - - - - - - - diff --git a/Tests/Loader/LoaderFactoryTest.php b/Tests/Loader/LoaderFactoryTest.php index fb0ae51..31ea47d 100644 --- a/Tests/Loader/LoaderFactoryTest.php +++ b/Tests/Loader/LoaderFactoryTest.php @@ -38,12 +38,13 @@ public function it_creates_a_closure_loader_when_source_is_a_closure(): void public static function fileProvider() { - return [ - ['file.xml', XmlFileLoader::class], - ['file.yml', YamlFileLoader::class], - ['file.yaml', YamlFileLoader::class], - ['file.php', PhpFileLoader::class], - ]; + if (class_exists(XmlFileLoader::class)) { + yield ['file.xml', XmlFileLoader::class]; + } + + yield ['file.yml', YamlFileLoader::class]; + yield ['file.yaml', YamlFileLoader::class]; + yield ['file.php', PhpFileLoader::class]; } private function createMockContainerBuilder(): MockObject&ContainerBuilder diff --git a/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php b/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php index b5dfe45..2e20fe2 100644 --- a/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php +++ b/Tests/PhpUnit/AbstractExtensionConfigurationTestCaseTest.php @@ -9,6 +9,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; class AbstractExtensionConfigurationTestCaseTest extends AbstractExtensionConfigurationTestCase { @@ -36,10 +37,15 @@ function (ContainerBuilder $container): void { ); }, __DIR__.'/../Fixtures/simple.yml', - __DIR__.'/../Fixtures/simple.xml', ]; + $types = ['php', 'closure', 'yml']; - $expectedConfiguration = ['types' => ['php', 'closure', 'yml', 'xml']]; + if (class_exists(XmlFileLoader::class)) { + $sources[] = __DIR__.'/../Fixtures/simple.xml'; + $types[] = 'xml'; + } + + $expectedConfiguration = ['types' => $types]; $this->assertProcessedConfigurationEquals($expectedConfiguration, $sources); } diff --git a/Tests/PhpUnit/AbstractExtensionTestCaseTest.php b/Tests/PhpUnit/AbstractExtensionTestCaseTest.php index a67d9b6..d847eac 100644 --- a/Tests/PhpUnit/AbstractExtensionTestCaseTest.php +++ b/Tests/PhpUnit/AbstractExtensionTestCaseTest.php @@ -21,10 +21,10 @@ public function if_load_is_successful_it_does_not_fail(): void { $this->load(); - // defined in services.xml + // defined in services.php $this->assertContainerBuilderHasService('loaded_service_id', 'stdClass'); - // defined in services.xml + // defined in services.php $this->assertContainerBuilderHasSyntheticService('synthetic_service'); // manually defined parameter diff --git a/composer.json b/composer.json index c92ca5a..b8f2f66 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,10 @@ "matthiasnoback/symfony-config-test": "^5.0 || ^6.0", "phpunit/phpunit": "^10.5.11 || ^11.0 || ^12.0", "sebastian/exporter": " ^5.0 || ^6.0 || ^7.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" + "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0 || ^8.0", + "symfony/deprecation-contracts": "^2.5 || ^3.0", + "symfony/config": "^5.4 || ^6.4 || ^7.0 || ^8.0", + "symfony/yaml": "^5.4 || ^6.4 || ^7.0 || ^8.0" }, "autoload": { "psr-4" : { "Matthias\\SymfonyDependencyInjectionTest\\" : "" }, @@ -30,7 +31,7 @@ }, "extra": { "branch-alias": { - "dev-master": "5.0.x-dev" + "dev-master": "6.x-dev" } }, "minimum-stability": "dev",