diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7538520..7b0bb4d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,21 +11,18 @@ jobs: strategy: matrix: php: - - '7.2' - - '7.3' - - '7.4' - - '8.0' + - '8.1' + - '8.2' dependency: - '' symfony: - - '4.4.*' - - '5.3.*' + - '5.4.*' + - '6.2.*' + - '6.3.*' include: - - php: '7.2' - symfony: '4.4.*' + - php: '8.1' + symfony: '5.4.*' dependency: 'lowest' - - php: '8.0' - symfony: '6.0.*' fail-fast: false steps: - name: Checkout @@ -38,18 +35,12 @@ jobs: extensions: pcov tools: flex - - name: Prefer unstable Composer dependencies for Symfony 6.0 - if: matrix.symfony == '6.0.*' - run: | - composer config prefer-stable false - composer config minimum-stability dev - - name: Get Composer Cache Directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/Loader/LoaderFactory.php b/Loader/LoaderFactory.php index 34c42cc..f1b05ab 100644 --- a/Loader/LoaderFactory.php +++ b/Loader/LoaderFactory.php @@ -7,7 +7,6 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; -use Symfony\Component\DependencyInjection\Loader\IniFileLoader; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; @@ -56,9 +55,4 @@ public function createPhpFileLoader(ContainerBuilder $container): PhpFileLoader { return new PhpFileLoader($container, new FileLocator()); } - - public function createIniFileLoader(ContainerBuilder $container): IniFileLoader - { - return new IniFileLoader($container, new FileLocator()); - } } diff --git a/Tests/Fixtures/SimpleConfiguration.php b/Tests/Fixtures/SimpleConfiguration.php index d781bff..33d287d 100644 --- a/Tests/Fixtures/SimpleConfiguration.php +++ b/Tests/Fixtures/SimpleConfiguration.php @@ -10,12 +10,7 @@ class SimpleConfiguration implements ConfigurationInterface public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('simple'); - - if (method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - $rootNode = $treeBuilder->root('simple'); - } + $rootNode = $treeBuilder->getRootNode(); $rootNode ->fixXmlConfig('type', 'types') diff --git a/Tests/Loader/LoaderFactoryTest.php b/Tests/Loader/LoaderFactoryTest.php index a5ce098..de17e1e 100644 --- a/Tests/Loader/LoaderFactoryTest.php +++ b/Tests/Loader/LoaderFactoryTest.php @@ -3,12 +3,19 @@ namespace Matthias\SymfonyDependencyInjectionTest\Tests\Loader; use Matthias\SymfonyDependencyInjectionTest\Loader\LoaderFactory; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\ClosureLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; class LoaderFactoryTest extends TestCase { /** * @test + * * @dataProvider fileProvider */ public function it_creates_the_appropriate_file_loader_based_on_the_extension($file, $expectedClass): void @@ -29,25 +36,21 @@ public function it_creates_a_closure_loader_when_source_is_a_closure(): void $factory = new LoaderFactory(); $loader = $factory->createLoaderForSource($this->createMockContainerBuilder(), $source); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Loader\ClosureLoader', $loader); + $this->assertInstanceOf(ClosureLoader::class, $loader); } - public function fileProvider() + public static function fileProvider() { return [ - ['file.xml', 'Symfony\Component\DependencyInjection\Loader\XmlFileLoader'], - ['file.yml', 'Symfony\Component\DependencyInjection\Loader\YamlFileLoader'], - ['file.yaml', 'Symfony\Component\DependencyInjection\Loader\YamlFileLoader'], - ['file.php', 'Symfony\Component\DependencyInjection\Loader\PhpFileLoader'], + ['file.xml', XmlFileLoader::class], + ['file.yml', YamlFileLoader::class], + ['file.yaml', YamlFileLoader::class], + ['file.php', PhpFileLoader::class], ]; } - private function createMockContainerBuilder() + private function createMockContainerBuilder(): MockObject&ContainerBuilder { - return $this - ->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') - ->disableOriginalConstructor() - ->setMethods(null) - ->getMock(); + return $this->createMock(ContainerBuilder::class); } } diff --git a/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php b/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php index acd8682..428df7d 100644 --- a/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php +++ b/Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php @@ -10,6 +10,7 @@ class ContainerBuilderHasAliasConstraintTest extends TestCase { /** * @test + * * @dataProvider containerBuilderProvider */ public function match(ContainerBuilder $containerBuilder, $alias, $expectedServiceId, $shouldMatch): void @@ -19,7 +20,7 @@ public function match(ContainerBuilder $containerBuilder, $alias, $expectedServi $this->assertSame($shouldMatch, $constraint->evaluate($containerBuilder, '', true)); } - public function containerBuilderProvider() + public static function containerBuilderProvider() { $emptyContainerBuilder = new ContainerBuilder(); diff --git a/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php b/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php index 911cae7..8f23984 100644 --- a/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php +++ b/Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php @@ -11,6 +11,7 @@ class ContainerBuilderHasServiceDefinitionConstraintTest extends TestCase { /** * @test + * * @dataProvider containerBuilderProvider */ public function match( @@ -25,7 +26,7 @@ public function match( $this->assertSame($shouldMatch, $constraint->evaluate($containerBuilder, '', true)); } - public function containerBuilderProvider() + public static function containerBuilderProvider() { $emptyContainerBuilder = new ContainerBuilder(); diff --git a/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php b/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php index ab52be9..2464543 100644 --- a/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php +++ b/Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php @@ -22,10 +22,6 @@ final class DefinitionArgumentEqualsServiceLocatorConstraintTest extends TestCas protected function setUp(): void { - if (!class_exists(ServiceLocator::class)) { - $this->markTestSkipped('Requires the Symfony DependencyInjection component v3.4 or higher'); - } - $this->containerBuilder = new ContainerBuilder(); } @@ -65,7 +61,7 @@ public function if_fails_if_the_service_definition_value_is_not_a_valid_referenc $this->assertConstraintFails(new DefinitionArgumentEqualsServiceLocatorConstraint('using_service', 0, [new Reference('foo')])); } - public function provideInvalidServiceLocatorReferences() + public static function provideInvalidServiceLocatorReferences() { yield [['']]; yield [[null]]; diff --git a/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php b/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php index fa3e381..9864384 100644 --- a/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php +++ b/Tests/PhpUnit/DefinitionDecoratesConstraintTest.php @@ -12,6 +12,7 @@ class DefinitionDecoratesConstraintTest extends TestCase { /** * @test + * * @dataProvider containerBuilderProvider */ public function match(ContainerBuilder $containerBuilder, bool $expectedToMatch, string $serviceId, string $decoratedServiceId, ?string $renamedId, int $priority, ?int $invalidBehavior): void @@ -21,7 +22,7 @@ public function match(ContainerBuilder $containerBuilder, bool $expectedToMatch, $this->assertSame($expectedToMatch, $constraint->evaluate($containerBuilder, '', true)); } - public function containerBuilderProvider(): iterable + public static function containerBuilderProvider(): iterable { $containerBuilder = new ContainerBuilder(); $containerBuilder->setDefinition('decorated1', new Definition('DecoratedClass1')); @@ -46,6 +47,7 @@ public function containerBuilderProvider(): iterable /** * @test + * * @dataProvider stringRepresentationProvider */ public function it_has_a_string_representation(DefinitionDecoratesConstraint $constraint, string $expectedRepresentation): void @@ -53,7 +55,7 @@ public function it_has_a_string_representation(DefinitionDecoratesConstraint $co $this->assertSame($expectedRepresentation, $constraint->toString()); } - public function stringRepresentationProvider(): iterable + public static function stringRepresentationProvider(): iterable { yield [new DefinitionDecoratesConstraint('decorator', 'decorated'), '"decorator" decorates service "decorated" with priority "0" and "RUNTIME_EXCEPTION_ON_INVALID_REFERENCE" behavior.']; yield [new DefinitionDecoratesConstraint('decorator', 'decorated', 'decorated_0'), '"decorator" decorates service "decorated" and renames it to "decorated_0" with priority "0" and "RUNTIME_EXCEPTION_ON_INVALID_REFERENCE" behavior.']; diff --git a/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php b/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php index c8e4fab..5a6d5f7 100644 --- a/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php +++ b/Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php @@ -20,10 +20,6 @@ final class DefinitionEqualsServiceLocatorTest extends TestCase protected function setUp(): void { - if (!class_exists(ServiceLocator::class)) { - $this->markTestSkipped('Requires the Symfony DependencyInjection component v3.4 or higher'); - } - $this->containerBuilder = new ContainerBuilder(); } @@ -49,7 +45,7 @@ public function if_fails_if_the_service_definition_value_is_not_a_valid_referenc ); } - public function provideInvalidServiceLocatorReferences() + public static function provideInvalidServiceLocatorReferences() { yield [['']]; yield [[null]]; @@ -70,13 +66,8 @@ public function it_does_not_fail_if_the_service_definition_is_a_service_locator( ); } - public function provideValidServiceLocatorDefs() + public static function provideValidServiceLocatorDefs() { - // Data providers get called before setUp? - if (!class_exists(ServiceLocator::class)) { - return [[], []]; - } - yield [ ['bar' => new ServiceClosureArgument(new Reference('foo'))], ['bar' => new Reference('foo')], diff --git a/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php b/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php index 0e6ae76..2988272 100644 --- a/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php @@ -7,12 +7,12 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\DefinitionDecorator; class DefinitionHasArgumentConstraintTest extends TestCase { /** * @test + * * @dataProvider definitionProvider */ public function match(Definition $definition, $argumentIndex, $expectedValue, $shouldMatch): void @@ -22,7 +22,7 @@ public function match(Definition $definition, $argumentIndex, $expectedValue, $s $this->assertSame($shouldMatch, $constraint->evaluate($definition, '', true)); } - public function definitionProvider() + public static function definitionProvider() { $definitionWithNoArguments = new Definition(); @@ -33,11 +33,7 @@ public function definitionProvider() $definitionWithArguments->setArguments($arguments); $parentServiceId = 'parent_service_id'; - if (class_exists(ChildDefinition::class)) { - $decoratedDefinitionWithArguments = new ChildDefinition($parentServiceId); - } else { - $decoratedDefinitionWithArguments = new DefinitionDecorator($parentServiceId); - } + $decoratedDefinitionWithArguments = new ChildDefinition($parentServiceId); $decoratedDefinitionWithArguments->setArguments([0 => 'first argument', 1 => $wrongValue]); $decoratedDefinitionWithArguments->replaceArgument(1, $rightValue); @@ -56,6 +52,7 @@ public function definitionProvider() /** * @test + * * @dataProvider invalid_definition_indexes * * @param mixed $argument @@ -72,7 +69,7 @@ public function validates_definitionIndex($argument, $exceptionMessage): void /** * @return \Generator */ - public function invalid_definition_indexes() + public static function invalid_definition_indexes() { yield [ new \stdClass(), 'Expected either a string or a positive integer for $argumentIndex.', @@ -97,6 +94,7 @@ public function invalid_definition_indexes() /** * @test + * * @dataProvider indexed_arguments * * @param int $argumentIndex @@ -133,7 +131,7 @@ public function supports_indexed_arguments($argumentIndex): void /** * @return \Generator */ - public function indexed_arguments() + public static function indexed_arguments() { // yield [0]; yield [1]; @@ -143,6 +141,7 @@ public function indexed_arguments() /** * @test + * * @dataProvider named_arguments * * @param string $argument @@ -181,7 +180,7 @@ public function supports_named_arguments($argument): void /** * @return \Generator */ - public function named_arguments() + public static function named_arguments() { yield ['$foo']; yield ['$bar']; diff --git a/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php b/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php index a109ca8..a9ce7ac 100644 --- a/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php @@ -10,6 +10,7 @@ class DefinitionHasMethodCallConstraintTest extends TestCase { /** * @test + * * @dataProvider definitionProvider */ public function match(Definition $definition, $method, $arguments, $index, $expectedToMatch): void @@ -19,7 +20,7 @@ public function match(Definition $definition, $method, $arguments, $index, $expe $this->assertSame($expectedToMatch, $constraint->evaluate($definition, '', true)); } - public function definitionProvider() + public static function definitionProvider() { $definitionWithNoMethodCalls = new Definition(); diff --git a/Tests/PhpUnit/DefinitionHasTagConstraintTest.php b/Tests/PhpUnit/DefinitionHasTagConstraintTest.php index 4765320..edb10f3 100644 --- a/Tests/PhpUnit/DefinitionHasTagConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasTagConstraintTest.php @@ -11,6 +11,7 @@ class DefinitionHasTagConstraintTest extends TestCase { /** * @test + * * @dataProvider definitionProvider */ public function match(Definition $definition, $tag, $attributes, $expectedToMatch): void @@ -22,6 +23,7 @@ public function match(Definition $definition, $tag, $attributes, $expectedToMatc /** * @test + * * @dataProvider definitionProvider */ public function evaluateThrowsExceptionOnFailure(Definition $definition, $tag, $attributes, $expectedToMatch): void @@ -40,7 +42,7 @@ public function evaluateThrowsExceptionOnFailure(Definition $definition, $tag, $ } } - public function definitionProvider() + public static function definitionProvider() { $definitionWithoutTags = new Definition(); $definitionWithTwoTags = new Definition(); diff --git a/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php b/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php index 43355b7..e5905cc 100644 --- a/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php +++ b/Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php @@ -12,6 +12,7 @@ class DefinitionIsChildOfConstraintTest extends TestCase { /** * @test + * * @dataProvider definitionProvider */ public function match(Definition $definition, $parentServiceId, $expectedToMatch): void @@ -21,14 +22,10 @@ public function match(Definition $definition, $parentServiceId, $expectedToMatch $this->assertSame($expectedToMatch, $constraint->evaluate($definition, '', true)); } - public function definitionProvider() + public static function definitionProvider() { $definition = new Definition(); - if (class_exists(ChildDefinition::class)) { - $decoratedDefinition = new ChildDefinition('parent_service_id'); - } else { - $decoratedDefinition = new DefinitionDecorator('parent_service_id'); - } + $decoratedDefinition = new ChildDefinition('parent_service_id'); return [ // the provided definition has the same parent service id diff --git a/composer.json b/composer.json index 2fdf1f1..b07c788 100644 --- a/composer.json +++ b/composer.json @@ -13,17 +13,17 @@ } ], "require": { - "php": "^7.2 || ^8.0", - "matthiasnoback/symfony-config-test": "^4.0.1", - "symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0", - "symfony/config": "^4.4 || ^5.3 || ^6.0", - "symfony/yaml": "^4.4 || ^5.3 || ^6.0" + "php": "^8.1", + "matthiasnoback/symfony-config-test": "^5.0", + "symfony/dependency-injection": "^5.4 || ^6.2", + "symfony/config": "^5.4 || ^6.2", + "symfony/yaml": "^5.4 || ^6.2" }, "require-dev": { - "phpunit/phpunit": "^8.0 || ^9.0" + "phpunit/phpunit": "^9.6 || ^10.0" }, "conflict": { - "phpunit/phpunit": "<8.0" + "phpunit/phpunit": "<9.6 || >=11.0" }, "autoload": { "psr-4" : { "Matthias\\SymfonyDependencyInjectionTest\\" : "" }, @@ -34,7 +34,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "5.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 016cf5a..27de55f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,24 @@ + colors="true" +> - Tests + Tests - - - . - - Tests - vendor - - - + + + ./ + + + ./Tests + ./vendor + +