Skip to content

Commit 3c5cf18

Browse files
authored
5.0 Proposal (#148)
* Update dependency ranges and CI for 5.0 * Address a number of PHPUnit deprecations * Remove compat code * Apply CS fixes
1 parent 5d2ef99 commit 3c5cf18

15 files changed

+73
-100
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ jobs:
1111
strategy:
1212
matrix:
1313
php:
14-
- '7.2'
15-
- '7.3'
16-
- '7.4'
17-
- '8.0'
14+
- '8.1'
15+
- '8.2'
1816
dependency:
1917
- ''
2018
symfony:
21-
- '4.4.*'
22-
- '5.3.*'
19+
- '5.4.*'
20+
- '6.2.*'
21+
- '6.3.*'
2322
include:
24-
- php: '7.2'
25-
symfony: '4.4.*'
23+
- php: '8.1'
24+
symfony: '5.4.*'
2625
dependency: 'lowest'
27-
- php: '8.0'
28-
symfony: '6.0.*'
2926
fail-fast: false
3027
steps:
3128
- name: Checkout
@@ -38,18 +35,12 @@ jobs:
3835
extensions: pcov
3936
tools: flex
4037

41-
- name: Prefer unstable Composer dependencies for Symfony 6.0
42-
if: matrix.symfony == '6.0.*'
43-
run: |
44-
composer config prefer-stable false
45-
composer config minimum-stability dev
46-
4738
- name: Get Composer Cache Directory
4839
id: composer-cache
4940
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
5041

5142
- name: Cache dependencies
52-
uses: actions/cache@v2
43+
uses: actions/cache@v3
5344
with:
5445
path: ${{ steps.composer-cache.outputs.dir }}
5546
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}

Loader/LoaderFactory.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Symfony\Component\Config\Loader\LoaderInterface;
88
use Symfony\Component\DependencyInjection\ContainerBuilder;
99
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
10-
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
1110
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1211
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1312
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -56,9 +55,4 @@ public function createPhpFileLoader(ContainerBuilder $container): PhpFileLoader
5655
{
5756
return new PhpFileLoader($container, new FileLocator());
5857
}
59-
60-
public function createIniFileLoader(ContainerBuilder $container): IniFileLoader
61-
{
62-
return new IniFileLoader($container, new FileLocator());
63-
}
6458
}

Tests/Fixtures/SimpleConfiguration.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ class SimpleConfiguration implements ConfigurationInterface
1010
public function getConfigTreeBuilder()
1111
{
1212
$treeBuilder = new TreeBuilder('simple');
13-
14-
if (method_exists($treeBuilder, 'getRootNode')) {
15-
$rootNode = $treeBuilder->getRootNode();
16-
} else {
17-
$rootNode = $treeBuilder->root('simple');
18-
}
13+
$rootNode = $treeBuilder->getRootNode();
1914

2015
$rootNode
2116
->fixXmlConfig('type', 'types')

Tests/Loader/LoaderFactoryTest.php

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

55
use Matthias\SymfonyDependencyInjectionTest\Loader\LoaderFactory;
6+
use PHPUnit\Framework\MockObject\MockObject;
67
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
10+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
11+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
12+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
713

814
class LoaderFactoryTest extends TestCase
915
{
1016
/**
1117
* @test
18+
*
1219
* @dataProvider fileProvider
1320
*/
1421
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
2936
$factory = new LoaderFactory();
3037

3138
$loader = $factory->createLoaderForSource($this->createMockContainerBuilder(), $source);
32-
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Loader\ClosureLoader', $loader);
39+
$this->assertInstanceOf(ClosureLoader::class, $loader);
3340
}
3441

35-
public function fileProvider()
42+
public static function fileProvider()
3643
{
3744
return [
38-
['file.xml', 'Symfony\Component\DependencyInjection\Loader\XmlFileLoader'],
39-
['file.yml', 'Symfony\Component\DependencyInjection\Loader\YamlFileLoader'],
40-
['file.yaml', 'Symfony\Component\DependencyInjection\Loader\YamlFileLoader'],
41-
['file.php', 'Symfony\Component\DependencyInjection\Loader\PhpFileLoader'],
45+
['file.xml', XmlFileLoader::class],
46+
['file.yml', YamlFileLoader::class],
47+
['file.yaml', YamlFileLoader::class],
48+
['file.php', PhpFileLoader::class],
4249
];
4350
}
4451

45-
private function createMockContainerBuilder()
52+
private function createMockContainerBuilder(): MockObject&ContainerBuilder
4653
{
47-
return $this
48-
->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
49-
->disableOriginalConstructor()
50-
->setMethods(null)
51-
->getMock();
54+
return $this->createMock(ContainerBuilder::class);
5255
}
5356
}

Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ContainerBuilderHasAliasConstraintTest extends TestCase
1010
{
1111
/**
1212
* @test
13+
*
1314
* @dataProvider containerBuilderProvider
1415
*/
1516
public function match(ContainerBuilder $containerBuilder, $alias, $expectedServiceId, $shouldMatch): void
@@ -19,7 +20,7 @@ public function match(ContainerBuilder $containerBuilder, $alias, $expectedServi
1920
$this->assertSame($shouldMatch, $constraint->evaluate($containerBuilder, '', true));
2021
}
2122

22-
public function containerBuilderProvider()
23+
public static function containerBuilderProvider()
2324
{
2425
$emptyContainerBuilder = new ContainerBuilder();
2526

Tests/PhpUnit/ContainerBuilderHasServiceDefinitionConstraintTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ContainerBuilderHasServiceDefinitionConstraintTest extends TestCase
1111
{
1212
/**
1313
* @test
14+
*
1415
* @dataProvider containerBuilderProvider
1516
*/
1617
public function match(
@@ -25,7 +26,7 @@ public function match(
2526
$this->assertSame($shouldMatch, $constraint->evaluate($containerBuilder, '', true));
2627
}
2728

28-
public function containerBuilderProvider()
29+
public static function containerBuilderProvider()
2930
{
3031
$emptyContainerBuilder = new ContainerBuilder();
3132

Tests/PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraintTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ final class DefinitionArgumentEqualsServiceLocatorConstraintTest extends TestCas
2222

2323
protected function setUp(): void
2424
{
25-
if (!class_exists(ServiceLocator::class)) {
26-
$this->markTestSkipped('Requires the Symfony DependencyInjection component v3.4 or higher');
27-
}
28-
2925
$this->containerBuilder = new ContainerBuilder();
3026
}
3127

@@ -65,7 +61,7 @@ public function if_fails_if_the_service_definition_value_is_not_a_valid_referenc
6561
$this->assertConstraintFails(new DefinitionArgumentEqualsServiceLocatorConstraint('using_service', 0, [new Reference('foo')]));
6662
}
6763

68-
public function provideInvalidServiceLocatorReferences()
64+
public static function provideInvalidServiceLocatorReferences()
6965
{
7066
yield [['']];
7167
yield [[null]];

Tests/PhpUnit/DefinitionDecoratesConstraintTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DefinitionDecoratesConstraintTest extends TestCase
1212
{
1313
/**
1414
* @test
15+
*
1516
* @dataProvider containerBuilderProvider
1617
*/
1718
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,
2122
$this->assertSame($expectedToMatch, $constraint->evaluate($containerBuilder, '', true));
2223
}
2324

24-
public function containerBuilderProvider(): iterable
25+
public static function containerBuilderProvider(): iterable
2526
{
2627
$containerBuilder = new ContainerBuilder();
2728
$containerBuilder->setDefinition('decorated1', new Definition('DecoratedClass1'));
@@ -46,14 +47,15 @@ public function containerBuilderProvider(): iterable
4647

4748
/**
4849
* @test
50+
*
4951
* @dataProvider stringRepresentationProvider
5052
*/
5153
public function it_has_a_string_representation(DefinitionDecoratesConstraint $constraint, string $expectedRepresentation): void
5254
{
5355
$this->assertSame($expectedRepresentation, $constraint->toString());
5456
}
5557

56-
public function stringRepresentationProvider(): iterable
58+
public static function stringRepresentationProvider(): iterable
5759
{
5860
yield [new DefinitionDecoratesConstraint('decorator', 'decorated'), '"decorator" decorates service "decorated" with priority "0" and "RUNTIME_EXCEPTION_ON_INVALID_REFERENCE" behavior.'];
5961
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.'];

Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ final class DefinitionEqualsServiceLocatorTest extends TestCase
2020

2121
protected function setUp(): void
2222
{
23-
if (!class_exists(ServiceLocator::class)) {
24-
$this->markTestSkipped('Requires the Symfony DependencyInjection component v3.4 or higher');
25-
}
26-
2723
$this->containerBuilder = new ContainerBuilder();
2824
}
2925

@@ -49,7 +45,7 @@ public function if_fails_if_the_service_definition_value_is_not_a_valid_referenc
4945
);
5046
}
5147

52-
public function provideInvalidServiceLocatorReferences()
48+
public static function provideInvalidServiceLocatorReferences()
5349
{
5450
yield [['']];
5551
yield [[null]];
@@ -70,13 +66,8 @@ public function it_does_not_fail_if_the_service_definition_is_a_service_locator(
7066
);
7167
}
7268

73-
public function provideValidServiceLocatorDefs()
69+
public static function provideValidServiceLocatorDefs()
7470
{
75-
// Data providers get called before setUp?
76-
if (!class_exists(ServiceLocator::class)) {
77-
return [[], []];
78-
}
79-
8071
yield [
8172
['bar' => new ServiceClosureArgument(new Reference('foo'))],
8273
['bar' => new Reference('foo')],

Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use PHPUnit\Framework\TestCase;
88
use Symfony\Component\DependencyInjection\ChildDefinition;
99
use Symfony\Component\DependencyInjection\Definition;
10-
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1110

1211
class DefinitionHasArgumentConstraintTest extends TestCase
1312
{
1413
/**
1514
* @test
15+
*
1616
* @dataProvider definitionProvider
1717
*/
1818
public function match(Definition $definition, $argumentIndex, $expectedValue, $shouldMatch): void
@@ -22,7 +22,7 @@ public function match(Definition $definition, $argumentIndex, $expectedValue, $s
2222
$this->assertSame($shouldMatch, $constraint->evaluate($definition, '', true));
2323
}
2424

25-
public function definitionProvider()
25+
public static function definitionProvider()
2626
{
2727
$definitionWithNoArguments = new Definition();
2828

@@ -33,11 +33,7 @@ public function definitionProvider()
3333
$definitionWithArguments->setArguments($arguments);
3434

3535
$parentServiceId = 'parent_service_id';
36-
if (class_exists(ChildDefinition::class)) {
37-
$decoratedDefinitionWithArguments = new ChildDefinition($parentServiceId);
38-
} else {
39-
$decoratedDefinitionWithArguments = new DefinitionDecorator($parentServiceId);
40-
}
36+
$decoratedDefinitionWithArguments = new ChildDefinition($parentServiceId);
4137

4238
$decoratedDefinitionWithArguments->setArguments([0 => 'first argument', 1 => $wrongValue]);
4339
$decoratedDefinitionWithArguments->replaceArgument(1, $rightValue);
@@ -56,6 +52,7 @@ public function definitionProvider()
5652

5753
/**
5854
* @test
55+
*
5956
* @dataProvider invalid_definition_indexes
6057
*
6158
* @param mixed $argument
@@ -72,7 +69,7 @@ public function validates_definitionIndex($argument, $exceptionMessage): void
7269
/**
7370
* @return \Generator
7471
*/
75-
public function invalid_definition_indexes()
72+
public static function invalid_definition_indexes()
7673
{
7774
yield [
7875
new \stdClass(), 'Expected either a string or a positive integer for $argumentIndex.',
@@ -97,6 +94,7 @@ public function invalid_definition_indexes()
9794

9895
/**
9996
* @test
97+
*
10098
* @dataProvider indexed_arguments
10199
*
102100
* @param int $argumentIndex
@@ -133,7 +131,7 @@ public function supports_indexed_arguments($argumentIndex): void
133131
/**
134132
* @return \Generator
135133
*/
136-
public function indexed_arguments()
134+
public static function indexed_arguments()
137135
{
138136
// yield [0];
139137
yield [1];
@@ -143,6 +141,7 @@ public function indexed_arguments()
143141

144142
/**
145143
* @test
144+
*
146145
* @dataProvider named_arguments
147146
*
148147
* @param string $argument
@@ -181,7 +180,7 @@ public function supports_named_arguments($argument): void
181180
/**
182181
* @return \Generator
183182
*/
184-
public function named_arguments()
183+
public static function named_arguments()
185184
{
186185
yield ['$foo'];
187186
yield ['$bar'];

0 commit comments

Comments
 (0)