Skip to content

Commit f307729

Browse files
committed
Use the PHPUnit Exporter util class
1 parent a8fc681 commit f307729

9 files changed

+29
-45
lines changed

PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7-
use SebastianBergmann\Exporter\Exporter;
7+
use PHPUnit\Util\Exporter;
88
use Symfony\Component\DependencyInjection\ContainerBuilder;
99

1010
final class ContainerBuilderHasServiceDefinitionConstraint extends Constraint
1111
{
1212
private $serviceId;
1313
private $expectedClass;
1414
private $checkExpectedClass;
15-
private $exporter;
1615

1716
public function __construct(
1817
string $serviceId,
@@ -22,7 +21,6 @@ public function __construct(
2221
$this->serviceId = $serviceId;
2322
$this->expectedClass = $expectedClass;
2423
$this->checkExpectedClass = $checkExpectedClass;
25-
$this->exporter = new Exporter();
2624
}
2725

2826
public function toString(): string
@@ -88,8 +86,8 @@ private function evaluateClass(ContainerBuilder $containerBuilder, bool $returnR
8886
$this->fail($containerBuilder, sprintf(
8987
'The class of the service definition of "%s" (%s) does not match the expected value (%s)',
9088
$this->serviceId,
91-
$this->exporter->export($actualClass),
92-
$this->exporter->export($this->expectedClass)
89+
Exporter::export($actualClass),
90+
Exporter::export($this->expectedClass)
9391
));
9492
}
9593

PhpUnit/ContainerHasParameterConstraint.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
77
use PHPUnit\Framework\Constraint\IsIdentical;
8-
use SebastianBergmann\Exporter\Exporter;
8+
use PHPUnit\Util\Exporter;
99
use Symfony\Component\DependencyInjection\ContainerInterface;
1010

1111
final class ContainerHasParameterConstraint extends Constraint
@@ -14,7 +14,6 @@ final class ContainerHasParameterConstraint extends Constraint
1414
private $expectedParameterValue;
1515
private $checkParameterValue;
1616
private $strict;
17-
private $exporter;
1817

1918
public function __construct(
2019
string $parameterName,
@@ -26,7 +25,6 @@ public function __construct(
2625
$this->expectedParameterValue = $expectedParameterValue;
2726
$this->checkParameterValue = $checkParameterValue;
2827
$this->strict = $strict;
29-
$this->exporter = new Exporter();
3028
}
3129

3230
public function toString(): string
@@ -86,8 +84,8 @@ private function evaluateParameterValue(ContainerInterface $container, bool $ret
8684
$this->fail($container, sprintf(
8785
'The value of parameter "%s" (%s) does not match the expected value (%s)',
8886
$this->parameterName,
89-
$this->exporter->export($actualValue),
90-
$this->exporter->export($this->expectedParameterValue)
87+
Exporter::export($actualValue),
88+
Exporter::export($this->expectedParameterValue)
9189
));
9290
}
9391

PhpUnit/DefinitionArgumentEqualsServiceLocatorConstraint.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7-
use SebastianBergmann\Exporter\Exporter;
7+
use PHPUnit\Util\Exporter;
88
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
99
use Symfony\Component\DependencyInjection\ContainerBuilder;
1010
use Symfony\Component\DependencyInjection\Definition;
@@ -20,7 +20,6 @@ final class DefinitionArgumentEqualsServiceLocatorConstraint extends Constraint
2020
private $argumentIndex;
2121
private $expectedValue;
2222
private $serviceId;
23-
private $exporter;
2423

2524
public function __construct(string $serviceId, $argumentIndex, array $expectedValue)
2625
{
@@ -56,8 +55,6 @@ function ($serviceId) {
5655
},
5756
$expectedValue
5857
);
59-
60-
$this->exporter = new Exporter();
6158
}
6259

6360
public function toString(): string
@@ -130,7 +127,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return
130127
sprintf(
131128
'The value of argument with index %s (%s) was expected to an instance of Symfony\Component\DependencyInjection\Reference or \Symfony\Component\DependencyInjection\Definition',
132129
$this->argumentIndex,
133-
$this->exporter->export($actualValue)
130+
Exporter::export($actualValue)
134131
)
135132
);
136133
}
@@ -145,7 +142,7 @@ private function evaluateArgumentValue(ContainerBuilder $container, bool $return
145142
sprintf(
146143
'The referenced service class of argument with index %s (%s) was expected to be an instance of Symfony\Component\DependencyInjection\ServiceLocator',
147144
$this->argumentIndex,
148-
$this->exporter->export($serviceLocatorDef->getClass())
145+
Exporter::export($serviceLocatorDef->getClass())
149146
)
150147
);
151148
}
@@ -176,8 +173,8 @@ private function evaluateServiceDefinition(
176173
sprintf(
177174
'The value of argument with index %s (%s) does not equal to the expected ServiceLocator service-map (%s)',
178175
$this->argumentIndex,
179-
$this->exporter->export($actualValue),
180-
$this->exporter->export($this->expectedValue)
176+
Exporter::export($actualValue),
177+
Exporter::export($this->expectedValue)
181178
)
182179
);
183180
}

PhpUnit/DefinitionEqualsServiceLocatorConstraint.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7-
use SebastianBergmann\Exporter\Exporter;
7+
use PHPUnit\Util\Exporter;
88
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
99
use Symfony\Component\DependencyInjection\Definition;
1010
use Symfony\Component\DependencyInjection\Reference;
@@ -13,7 +13,6 @@
1313
final class DefinitionEqualsServiceLocatorConstraint extends Constraint
1414
{
1515
private $expectedValue;
16-
private $exporter;
1716

1817
public function __construct($expectedValue)
1918
{
@@ -31,7 +30,6 @@ function ($serviceId) {
3130
},
3231
$expectedValue
3332
);
34-
$this->exporter = new Exporter();
3533
}
3634

3735
public function toString(): string
@@ -73,8 +71,8 @@ private function evaluateServiceDefinitionClass(Definition $definition, bool $re
7371
$definition,
7472
sprintf(
7573
'class %s was expected as service definition class, found %s instead',
76-
$this->exporter->export(ServiceLocator::class),
77-
$this->exporter->export($definition->getClass())
74+
Exporter::export(ServiceLocator::class),
75+
Exporter::export($definition->getClass())
7876
)
7977
);
8078
}
@@ -93,8 +91,8 @@ private function evaluateArgumentIndex(Definition $definition, bool $returnResul
9391
$definition,
9492
sprintf(
9593
'The service-map %s does not equal to the expected service-map (%s)',
96-
$this->exporter->export($actualValue),
97-
$this->exporter->export($this->expectedValue)
94+
Exporter::export($actualValue),
95+
Exporter::export($this->expectedValue)
9896
)
9997
);
10098
}

PhpUnit/DefinitionHasArgumentConstraint.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7-
use SebastianBergmann\Exporter\Exporter;
7+
use PHPUnit\Util\Exporter;
88
use Symfony\Component\DependencyInjection\Definition;
99
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
1010

@@ -16,7 +16,6 @@ final class DefinitionHasArgumentConstraint extends Constraint
1616
private string|int $argumentIndex;
1717
private mixed $expectedValue;
1818
private bool $checkExpectedValue;
19-
private Exporter $exporter;
2019

2120
public function __construct($argumentIndex, $expectedValue, bool $checkExpectedValue = true)
2221
{
@@ -39,7 +38,6 @@ public function __construct($argumentIndex, $expectedValue, bool $checkExpectedV
3938
$this->argumentIndex = $argumentIndex;
4039
$this->expectedValue = $expectedValue;
4140
$this->checkExpectedValue = $checkExpectedValue;
42-
$this->exporter = new Exporter();
4341
}
4442

4543
public function toString(): string
@@ -107,8 +105,8 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
107105
sprintf(
108106
'The value of argument named "%s" (%s) is not equal to the expected value (%s)',
109107
$this->argumentIndex,
110-
$this->exporter->export($actualValue),
111-
$this->exporter->export($this->expectedValue)
108+
Exporter::export($actualValue),
109+
Exporter::export($this->expectedValue)
112110
)
113111
);
114112
}
@@ -124,15 +122,15 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
124122
$message = sprintf(
125123
'The value of argument named "%s" (%s) is not equal to the expected value (%s)',
126124
$this->argumentIndex,
127-
$this->exporter->export($actualValue),
128-
$this->exporter->export($this->expectedValue)
125+
Exporter::export($actualValue),
126+
Exporter::export($this->expectedValue)
129127
);
130128
} else {
131129
$message = sprintf(
132130
'The value of argument with index %d (%s) is not equal to the expected value (%s)',
133131
$this->argumentIndex,
134-
$this->exporter->export($actualValue),
135-
$this->exporter->export($this->expectedValue)
132+
Exporter::export($actualValue),
133+
Exporter::export($this->expectedValue)
136134
);
137135
}
138136

PhpUnit/DefinitionHasMethodCallConstraint.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7-
use SebastianBergmann\Exporter\Exporter;
7+
use PHPUnit\Util\Exporter;
88
use Symfony\Component\DependencyInjection\Definition;
99

1010
final class DefinitionHasMethodCallConstraint extends Constraint
1111
{
1212
private $methodName;
1313
private $arguments;
1414
private $index;
15-
private $exporter;
1615

1716
public function __construct(string $methodName, array $arguments = [], $index = null)
1817
{
@@ -23,7 +22,6 @@ public function __construct(string $methodName, array $arguments = [], $index =
2322
$this->methodName = $methodName;
2423
$this->arguments = $arguments;
2524
$this->index = $index;
26-
$this->exporter = new Exporter();
2725
}
2826

2927
public function evaluate($other, string $description = '', bool $returnResult = false): bool
@@ -58,7 +56,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
5856
sprintf(
5957
'None of the method calls matched the expected method "%s" with arguments %s with %s invocation order index',
6058
$this->methodName,
61-
$this->exporter->export($this->arguments),
59+
Exporter::export($this->arguments),
6260
(null === $this->index) ? 'any' : sprintf('"%s"', $this->index)
6361
)
6462
);

PhpUnit/DefinitionHasTagConstraint.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44

55
use PHPUnit\Framework\Constraint\Constraint;
66
use PHPUnit\Framework\Constraint\IsEqual;
7-
use SebastianBergmann\Exporter\Exporter;
7+
use PHPUnit\Util\Exporter;
88
use Symfony\Component\DependencyInjection\Definition;
99

1010
final class DefinitionHasTagConstraint extends Constraint
1111
{
1212
private $name;
1313
private $attributes;
14-
private $exporter;
1514

1615
public function __construct(string $name, array $attributes = [])
1716
{
1817
$this->name = $name;
1918
$this->attributes = $attributes;
20-
$this->exporter = new Exporter();
2119
}
2220

2321
public function evaluate($other, string $description = '', bool $returnResult = false): bool
@@ -45,7 +43,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
4543
sprintf(
4644
'None of the tags matched the expected name "%s" with attributes %s',
4745
$this->name,
48-
$this->exporter->export($this->attributes)
46+
Exporter::export($this->attributes)
4947
)
5048
);
5149
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ container:
349349

350350
| Version | Released | PHPUnit | Status |
351351
|---------|--------------|---------------------|------------|
352-
| 6.x | Aug 8, 2024 | 10.5, 11.x and 12.x | Latest |
352+
| 6.x | Aug 8, 2024 | 10.5, 11.5 and 12.x | Latest |
353353
| 5.x | Nov 22, 2023 | 9.6 and 10.x | Bugfixes |
354354
| 4.x | Mar 28, 2019 | 8.x and 9.x | Bugfixes |
355355
| 3.x | Mar 5, 2018 | 7.x | Bugfixes |

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
"require": {
1616
"php": "^8.1",
1717
"matthiasnoback/symfony-config-test": "^5.0 || ^6.0",
18-
"phpunit/phpunit": "^10.5.11 || ^11.0 || ^12.0",
19-
"sebastian/exporter": " ^5.0 || ^6.0 || ^7.0",
18+
"phpunit/phpunit": "^10.5.11 || ^11.5 || ^12.0",
2019
"symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0",
2120
"symfony/config": "^5.4 || ^6.2 || ^7.0",
2221
"symfony/yaml": "^5.4 || ^6.2 || ^7.0"

0 commit comments

Comments
 (0)