Skip to content

Commit

Permalink
Merge pull request #155 from stloyd/bugfix/tests-for-147
Browse files Browse the repository at this point in the history
Add basic tests for `DefinitionDecoratesConstraint`
  • Loading branch information
stloyd authored Dec 13, 2023
2 parents 76663d8 + 355cb4e commit e0032f5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
22 changes: 11 additions & 11 deletions PhpUnit/DefinitionDecoratesConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ final class DefinitionDecoratesConstraint extends Constraint
ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE => 'IGNORE_ON_UNINITIALIZED_REFERENCE',
];

private $serviceId;
private $decoratedServiceId;
private $renamedId;
private $priority;
private $invalidBehavior;
private string $serviceId;
private string $decoratedServiceId;
private ?string $renamedId;
private int $priority;
private ?int $invalidBehavior;

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

$this->fail(
$containerBuilder,
$this->serviceId,
sprintf(
'The container builder has no service "%s"',
$this->serviceId
Expand All @@ -80,7 +80,7 @@ private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, b
}

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

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

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

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

$this->fail(
$containerBuilder,
$this->serviceId,
sprintf(
'The container builder has a decorator service "%s", but it does not decorate with expected "%s" behavior.',
$this->serviceId,
Expand Down
26 changes: 26 additions & 0 deletions Tests/PhpUnit/AbstractExtensionTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,30 @@ public function if_service_is_not_defined_it_does_not_fail(): void

$this->assertContainerBuilderNotHasService('undefined');
}

/**
* @test
*/
public function if_service_is_not_defined_in_service_decoration_it_fails(): void
{
$this->load();

$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage('The container builder has no service "undefined"');

$this->assertContainerBuilderServiceDecoration('undefined', 'undefined');
}

/**
* @test
*/
public function if_service_decoration_is_not_defined_in_service_decoration_it_fails(): void
{
$this->load();

$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage('The container builder has a service "manual_service_id", but it does not decorate any service');

$this->assertContainerBuilderServiceDecoration('manual_service_id', 'undefined');
}
}

0 comments on commit e0032f5

Please sign in to comment.