Skip to content

Commit c6b094c

Browse files
stloydNyholm
authored andcommitted
Fixed DefinitionIsChildOfConstraintTest to use newer Symfony code (#88)
* Fixed DefinitionIsChildOfConstraintTest to use newer Symfony code * Fixed DefinitionIsChildOfConstraint to support new Symfony code * Fixed typo in DefinitionIsChildOfConstraint class * Added christians suggestion * Update DefinitionIsChildOfConstraint.php * Removing elseif * Removed type hint * Updated data provider
1 parent f582683 commit c6b094c

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

PhpUnit/DefinitionIsChildOfConstraint.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Matthias\SymfonyDependencyInjectionTest\PhpUnit;
44

55
use PHPUnit\Framework\Constraint\Constraint;
6+
use Symfony\Component\DependencyInjection\ChildDefinition;
67
use Symfony\Component\DependencyInjection\Definition;
78
use Symfony\Component\DependencyInjection\DefinitionDecorator;
89

@@ -19,7 +20,7 @@ public function __construct($expectedParentServiceId)
1920

2021
public function evaluate($other, $description = '', $returnResult = false)
2122
{
22-
if (!($other instanceof Definition)) {
23+
if (!$other instanceof Definition) {
2324
throw new \InvalidArgumentException(
2425
'Expected an instance of Symfony\Component\DependencyInjection\Definition'
2526
);
@@ -46,7 +47,7 @@ public function toString()
4647

4748
private function evaluateDefinitionIsDecorator(Definition $definition, $returnResult)
4849
{
49-
if (!($definition instanceof DefinitionDecorator)) {
50+
if (!$definition instanceof ChildDefinition && !$definition instanceof DefinitionDecorator) {
5051
if ($returnResult) {
5152
return false;
5253
}
@@ -57,7 +58,7 @@ private function evaluateDefinitionIsDecorator(Definition $definition, $returnRe
5758
return true;
5859
}
5960

60-
private function evaluateDefinitionHasExpectedParentService(DefinitionDecorator $definition, $returnResult)
61+
private function evaluateDefinitionHasExpectedParentService($definition, $returnResult)
6162
{
6263
$actualParentService = $this->expectedParentServiceId;
6364

Tests/PhpUnit/DefinitionHasArgumentConstraintTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionHasArgumentConstraint;
66
use PHPUnit\Framework\ExpectationFailedException;
77
use PHPUnit\Framework\TestCase;
8-
use stdClass;
8+
use Symfony\Component\DependencyInjection\ChildDefinition;
99
use Symfony\Component\DependencyInjection\Definition;
1010
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1111

@@ -32,7 +32,13 @@ public function definitionProvider()
3232
$arguments = array(0 => 'first argument', 1 => $rightValue);
3333
$definitionWithArguments->setArguments($arguments);
3434

35-
$decoratedDefinitionWithArguments = new DefinitionDecorator('parent_service_id');
35+
$parentServiceId = 'parent_service_id';
36+
if (class_exists(ChildDefinition::class)) {
37+
$decoratedDefinitionWithArguments = new ChildDefinition($parentServiceId);
38+
} else {
39+
$decoratedDefinitionWithArguments = new DefinitionDecorator($parentServiceId);
40+
}
41+
3642
$decoratedDefinitionWithArguments->setArguments(array(0 => 'first argument', 1 => $wrongValue));
3743
$decoratedDefinitionWithArguments->replaceArgument(1, $rightValue);
3844

@@ -69,7 +75,7 @@ public function validates_definitionIndex($argument, $exceptionMessage)
6975
public function invalid_definition_indexes()
7076
{
7177
yield [
72-
new stdClass(), 'Expected either a string or a positive integer for $argumentIndex.'
78+
new \stdClass(), 'Expected either a string or a positive integer for $argumentIndex.'
7379
];
7480

7581
yield [
@@ -175,5 +181,4 @@ public function named_arguments()
175181
yield ['$bar'];
176182
yield ['$a'];
177183
}
178-
179184
}

Tests/PhpUnit/DefinitionIsChildOfConstraintTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
43
namespace Matthias\DependencyInjectionTests\Test\DependencyInjection;
54

65
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\DefinitionIsChildOfConstraint;
76
use PHPUnit\Framework\TestCase;
7+
use Symfony\Component\DependencyInjection\ChildDefinition;
88
use Symfony\Component\DependencyInjection\Definition;
99
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1010

@@ -24,7 +24,11 @@ public function match(Definition $definition, $parentServiceId, $expectedToMatch
2424
public function definitionProvider()
2525
{
2626
$definition = new Definition();
27-
$decoratedDefinition = new DefinitionDecorator('parent_service_id');
27+
if (class_exists(ChildDefinition::class)) {
28+
$decoratedDefinition = new ChildDefinition('parent_service_id');
29+
} else {
30+
$decoratedDefinition = new DefinitionDecorator('parent_service_id');
31+
}
2832

2933
return array(
3034
// the provided definition has the same parent service id

0 commit comments

Comments
 (0)