Skip to content

Commit

Permalink
removes implicit dependency on sebastian/exporter
Browse files Browse the repository at this point in the history
Closes #158
  • Loading branch information
ju1ius committed Feb 15, 2024
1 parent 2bd8962 commit 67fbaaa
Showing 1 changed file with 7 additions and 9 deletions.
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

0 comments on commit 67fbaaa

Please sign in to comment.