Skip to content

Commit e0032f5

Browse files
authored
Merge pull request #155 from stloyd/bugfix/tests-for-147
Add basic tests for `DefinitionDecoratesConstraint`
2 parents 76663d8 + 355cb4e commit e0032f5

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

PhpUnit/DefinitionDecoratesConstraint.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ final class DefinitionDecoratesConstraint extends Constraint
1616
ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE => 'IGNORE_ON_UNINITIALIZED_REFERENCE',
1717
];
1818

19-
private $serviceId;
20-
private $decoratedServiceId;
21-
private $renamedId;
22-
private $priority;
23-
private $invalidBehavior;
19+
private string $serviceId;
20+
private string $decoratedServiceId;
21+
private ?string $renamedId;
22+
private int $priority;
23+
private ?int $invalidBehavior;
2424

2525
public function __construct(string $serviceId, string $decoratedServiceId, ?string $renamedId = null, int $priority = 0, ?int $invalidBehavior = null)
2626
{
@@ -62,7 +62,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
6262
}
6363

6464
$this->fail(
65-
$containerBuilder,
65+
$this->serviceId,
6666
sprintf(
6767
'The container builder has no service "%s"',
6868
$this->serviceId
@@ -80,7 +80,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
8080
}
8181

8282
$this->fail(
83-
$containerBuilder,
83+
$this->serviceId,
8484
sprintf(
8585
'The container builder has a service "%s", but it does not decorate any service',
8686
$this->serviceId
@@ -94,7 +94,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
9494
}
9595

9696
$this->fail(
97-
$containerBuilder,
97+
$this->serviceId,
9898
sprintf(
9999
'The container builder has a decorator service "%s", but it does decorate service "%s".',
100100
$this->serviceId,
@@ -109,7 +109,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
109109
}
110110

111111
$this->fail(
112-
$containerBuilder,
112+
$this->serviceId,
113113
sprintf(
114114
'The container builder has a decorator service "%s", but it does not rename decorated service to "%s".',
115115
$this->serviceId,
@@ -124,7 +124,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
124124
}
125125

126126
$this->fail(
127-
$containerBuilder,
127+
$this->serviceId,
128128
sprintf(
129129
'The container builder has a decorator service "%s", but it does not decorate at expected "%d" priority.',
130130
$this->serviceId,
@@ -139,7 +139,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
139139
}
140140

141141
$this->fail(
142-
$containerBuilder,
142+
$this->serviceId,
143143
sprintf(
144144
'The container builder has a decorator service "%s", but it does not decorate with expected "%s" behavior.',
145145
$this->serviceId,

Tests/PhpUnit/AbstractExtensionTestCaseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,30 @@ public function if_service_is_not_defined_it_does_not_fail(): void
272272

273273
$this->assertContainerBuilderNotHasService('undefined');
274274
}
275+
276+
/**
277+
* @test
278+
*/
279+
public function if_service_is_not_defined_in_service_decoration_it_fails(): void
280+
{
281+
$this->load();
282+
283+
$this->expectException(ExpectationFailedException::class);
284+
$this->expectExceptionMessage('The container builder has no service "undefined"');
285+
286+
$this->assertContainerBuilderServiceDecoration('undefined', 'undefined');
287+
}
288+
289+
/**
290+
* @test
291+
*/
292+
public function if_service_decoration_is_not_defined_in_service_decoration_it_fails(): void
293+
{
294+
$this->load();
295+
296+
$this->expectException(ExpectationFailedException::class);
297+
$this->expectExceptionMessage('The container builder has a service "manual_service_id", but it does not decorate any service');
298+
299+
$this->assertContainerBuilderServiceDecoration('manual_service_id', 'undefined');
300+
}
275301
}

0 commit comments

Comments
 (0)