Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
Expand Down
6 changes: 0 additions & 6 deletions Loader/LoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
7 changes: 1 addition & 6 deletions Tests/Fixtures/SimpleConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
27 changes: 15 additions & 12 deletions Tests/Loader/LoaderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
3 changes: 2 additions & 1 deletion Tests/PhpUnit/ContainerBuilderHasAliasConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ContainerBuilderHasAliasConstraintTest extends TestCase
{
/**
* @test
*
* @dataProvider containerBuilderProvider
*/
public function match(ContainerBuilder $containerBuilder, $alias, $expectedServiceId, $shouldMatch): void
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ContainerBuilderHasServiceDefinitionConstraintTest extends TestCase
{
/**
* @test
*
* @dataProvider containerBuilderProvider
*/
public function match(
Expand All @@ -25,7 +26,7 @@ public function match(
$this->assertSame($shouldMatch, $constraint->evaluate($containerBuilder, '', true));
}

public function containerBuilderProvider()
public static function containerBuilderProvider()
{
$emptyContainerBuilder = new ContainerBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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]];
Expand Down
6 changes: 4 additions & 2 deletions Tests/PhpUnit/DefinitionDecoratesConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'));
Expand All @@ -46,14 +47,15 @@ public function containerBuilderProvider(): iterable

/**
* @test
*
* @dataProvider stringRepresentationProvider
*/
public function it_has_a_string_representation(DefinitionDecoratesConstraint $constraint, string $expectedRepresentation): void
{
$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.'];
Expand Down
13 changes: 2 additions & 11 deletions Tests/PhpUnit/DefinitionEqualsServiceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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]];
Expand All @@ -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')],
Expand Down
19 changes: 9 additions & 10 deletions Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand All @@ -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);
Expand All @@ -56,6 +52,7 @@ public function definitionProvider()

/**
* @test
*
* @dataProvider invalid_definition_indexes
*
* @param mixed $argument
Expand All @@ -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.',
Expand All @@ -97,6 +94,7 @@ public function invalid_definition_indexes()

/**
* @test
*
* @dataProvider indexed_arguments
*
* @param int $argumentIndex
Expand Down Expand Up @@ -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];
Expand All @@ -143,6 +141,7 @@ public function indexed_arguments()

/**
* @test
*
* @dataProvider named_arguments
*
* @param string $argument
Expand Down Expand Up @@ -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'];
Expand Down
3 changes: 2 additions & 1 deletion Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DefinitionHasMethodCallConstraintTest extends TestCase
{
/**
* @test
*
* @dataProvider definitionProvider
*/
public function match(Definition $definition, $method, $arguments, $index, $expectedToMatch): void
Expand All @@ -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();

Expand Down
4 changes: 3 additions & 1 deletion Tests/PhpUnit/DefinitionHasTagConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DefinitionHasTagConstraintTest extends TestCase
{
/**
* @test
*
* @dataProvider definitionProvider
*/
public function match(Definition $definition, $tag, $attributes, $expectedToMatch): void
Expand All @@ -22,6 +23,7 @@ public function match(Definition $definition, $tag, $attributes, $expectedToMatc

/**
* @test
*
* @dataProvider definitionProvider
*/
public function evaluateThrowsExceptionOnFailure(Definition $definition, $tag, $attributes, $expectedToMatch): void
Expand All @@ -40,7 +42,7 @@ public function evaluateThrowsExceptionOnFailure(Definition $definition, $tag, $
}
}

public function definitionProvider()
public static function definitionProvider()
{
$definitionWithoutTags = new Definition();
$definitionWithTwoTags = new Definition();
Expand Down
Loading