Skip to content

Commit 24151cb

Browse files
committed
remove matthiasnoback dependency for increased Symfony compatibility
1 parent bba0923 commit 24151cb

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ jobs:
139139
- '7.3'
140140
- '7.4'
141141
symfony-version:
142-
# - '4.0' matthiasnoback/symfony-dependency-injection-test 4.3.0 requires symfony/config ^4.4 || ^5.3 || ^6.0
143-
# - '4.1' matthiasnoback/symfony-dependency-injection-test 4.3.0 requires symfony/config ^4.4 || ^5.3 || ^6.0
144-
# - '4.2' matthiasnoback/symfony-dependency-injection-test 4.3.0 requires symfony/config ^4.4 || ^5.3 || ^6.0
145-
# - '4.3' matthiasnoback/symfony-dependency-injection-test 4.3.0 requires symfony/config ^4.4 || ^5.3 || ^6.0
142+
- '4.0'
143+
- '4.1'
144+
- '4.2'
145+
- '4.3'
146146
- '4.4'
147147
composer-dependencies:
148148
- 'highest'

build/composer-dependency-analyser.config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
$config = $config->ignoreErrorsOnPackages([
2828
'consistence/coding-standard',
2929
'phing/phing',
30-
'phpunit/phpunit',
3130
'php-parallel-lint/php-console-highlighter',
3231
'php-parallel-lint/php-parallel-lint',
3332
], [ErrorType::UNUSED_DEPENDENCY]);

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
},
2121
"require-dev": {
2222
"consistence/coding-standard": "3.10.1",
23-
"matthiasnoback/symfony-dependency-injection-test": "4.3",
2423
"php-parallel-lint/php-console-highlighter": "1.0",
2524
"php-parallel-lint/php-parallel-lint": "1.3.2",
2625
"phing/phing": "2.17.2",

tests/DependencyInjection/ConsistenceJmsSerializerExtensionTest.php

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,87 @@
55
namespace Consistence\JmsSerializer\SymfonyBundle\DependencyInjection;
66

77
use Consistence\JmsSerializer\Enum\EnumSerializerHandler;
8+
use PHPUnit\Framework\Assert;
9+
use Symfony\Component\DependencyInjection\ContainerBuilder;
10+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
811

9-
class ConsistenceJmsSerializerExtensionTest extends \Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase
12+
class ConsistenceJmsSerializerExtensionTest extends \PHPUnit\Framework\TestCase
1013
{
1114

12-
/**
13-
* @return \Symfony\Component\DependencyInjection\Extension\ExtensionInterface[]
14-
*/
15-
protected function getContainerExtensions(): array
15+
public function testRegisterSerializerHandler(): void
1616
{
17-
return [
18-
new ConsistenceJmsSerializerExtension(),
19-
];
17+
$container = self::createContainer();
18+
$container->registerExtension(new ConsistenceJmsSerializerExtension());
19+
20+
foreach ($container->getExtensions() as $extension) {
21+
$extension->load([], $container);
22+
}
23+
24+
$serviceId = 'consistence.jms_serializer.enum.enum_serializer_handler';
25+
self::assertContainerHasService($container, $serviceId);
26+
self::assertContainerServiceIsOfType($container, $serviceId, EnumSerializerHandler::class);
27+
self::assertContainerServiceHasTagWithAttributes(
28+
$container,
29+
$serviceId,
30+
'jms_serializer.subscribing_handler',
31+
[]
32+
);
33+
34+
$container->compile();
2035
}
2136

22-
public function testRegisterSerializerHandler(): void
37+
private static function createContainer(): ContainerBuilder
2338
{
24-
$this->load();
39+
$container = new ContainerBuilder(new ParameterBag([]));
40+
$container->getCompilerPassConfig()->setOptimizationPasses([]);
41+
$container->getCompilerPassConfig()->setRemovingPasses([]);
42+
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
43+
44+
return $container;
45+
}
2546

26-
$this->assertContainerBuilderHasService(
27-
'consistence.jms_serializer.enum.enum_serializer_handler',
28-
EnumSerializerHandler::class
47+
private static function assertContainerHasService(ContainerBuilder $container, string $serviceId): void
48+
{
49+
Assert::assertTrue(
50+
$container->has($serviceId),
51+
sprintf('Container is missing required service `%s`.', $serviceId)
2952
);
30-
$this->assertContainerBuilderHasServiceDefinitionWithTag(
31-
'consistence.jms_serializer.enum.enum_serializer_handler',
32-
'jms_serializer.subscribing_handler'
53+
}
54+
55+
private static function assertContainerServiceIsOfType(
56+
ContainerBuilder $container,
57+
string $serviceId,
58+
string $expectedClassString
59+
): void
60+
{
61+
$serviceDefinition = $container->findDefinition($serviceId);
62+
63+
Assert::assertSame(
64+
$expectedClassString,
65+
$container->getParameterBag()->resolveValue($serviceDefinition->getClass())
3366
);
67+
}
68+
69+
private static function assertContainerServiceHasTagWithAttributes(
70+
ContainerBuilder $container,
71+
string $serviceId,
72+
string $tagName
73+
): void
74+
{
75+
$tagExists = false;
76+
$serviceDefinition = $container->findDefinition($serviceId);
77+
78+
foreach ($serviceDefinition->getTags() as $name => $tagsAttributes) {
79+
if ($name !== $tagName) {
80+
continue;
81+
}
82+
83+
$tagExists = true;
84+
}
3485

35-
$this->compile();
86+
if (!$tagExists) {
87+
Assert::fail(sprintf('Service `%s` does not have any tag `%s`.', $serviceId, $tagName));
88+
}
3689
}
3790

3891
}

0 commit comments

Comments
 (0)