Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions PhpUnit/DefinitionHasArgumentConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsEqual;
use SebastianBergmann\Exporter\Exporter;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;

Expand All @@ -16,7 +15,6 @@ final class DefinitionHasArgumentConstraint extends Constraint
private string|int $argumentIndex;
private mixed $expectedValue;
private bool $checkExpectedValue;
private Exporter $exporter;

public function __construct($argumentIndex, $expectedValue, bool $checkExpectedValue = true)
{
Expand All @@ -39,7 +37,6 @@ public function __construct($argumentIndex, $expectedValue, bool $checkExpectedV
$this->argumentIndex = $argumentIndex;
$this->expectedValue = $expectedValue;
$this->checkExpectedValue = $checkExpectedValue;
$this->exporter = new Exporter();
}

public function toString(): string
Expand Down Expand Up @@ -100,15 +97,16 @@ private function evaluateArgumentIndex(Definition $definition, bool $returnResul
private function evaluateArgumentValue(Definition $definition, bool $returnResult): bool
{
$actualValue = $definition->getArgument($this->argumentIndex);
$exporter = $this->exporter();

if (gettype($actualValue) !== gettype($this->expectedValue)) {
$this->fail(
$definition,
sprintf(
'The value of argument named "%s" (%s) is not equal to the expected value (%s)',
$this->argumentIndex,
$this->exporter->export($actualValue),
$this->exporter->export($this->expectedValue)
$exporter->export($actualValue),
$exporter->export($this->expectedValue)
)
);
}
Expand All @@ -124,15 +122,15 @@ private function evaluateArgumentValue(Definition $definition, bool $returnResul
$message = sprintf(
'The value of argument named "%s" (%s) is not equal to the expected value (%s)',
$this->argumentIndex,
$this->exporter->export($actualValue),
$this->exporter->export($this->expectedValue)
$exporter->export($actualValue),
$exporter->export($this->expectedValue)
);
} else {
$message = sprintf(
'The value of argument with index %d (%s) is not equal to the expected value (%s)',
$this->argumentIndex,
$this->exporter->export($actualValue),
$this->exporter->export($this->expectedValue)
$exporter->export($actualValue),
$exporter->export($this->expectedValue)
);
}

Expand Down