|
13 | 13 | use RuntimeException;
|
14 | 14 | use SebastianBergmann\Comparator\ComparisonFailure;
|
15 | 15 | use SebastianBergmann\Comparator\Factory;
|
| 16 | +use SebastianBergmann\Exporter\Exporter; |
16 | 17 |
|
17 | 18 | use function array_keys;
|
18 | 19 | use function count;
|
@@ -82,14 +83,14 @@ public function evaluate($other, $description = '', $returnResult = false): ?boo
|
82 | 83 | } catch (RuntimeException $e) {
|
83 | 84 | /* This will generally catch internal errors from failAt(), which
|
84 | 85 | * include a key path to pinpoint the failure. */
|
| 86 | + $exporter = new Exporter(); |
85 | 87 | $this->lastFailure = new ComparisonFailure(
|
86 | 88 | $this->value,
|
87 | 89 | $other,
|
88 | 90 | /* TODO: Improve the exporter to canonicalize documents by
|
89 | 91 | * sorting keys and remove spl_object_hash from output. */
|
90 |
| - $this->exporter()->export($this->value), |
91 |
| - $this->exporter()->export($other), |
92 |
| - false, |
| 92 | + $exporter->export($this->value), |
| 93 | + $exporter->export($other), |
93 | 94 | $e->getMessage(),
|
94 | 95 | );
|
95 | 96 | }
|
@@ -256,7 +257,7 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $
|
256 | 257 | $constraint = IsBsonType::anyOf(...(array) $operator['$$type']);
|
257 | 258 |
|
258 | 259 | if (! $constraint->evaluate($actual, '', true)) {
|
259 |
| - self::failAt(sprintf('%s is not an expected BSON type: %s', $this->exporter()->shortenedExport($actual), implode(', ', (array) $operator['$$type'])), $keyPath); |
| 260 | + self::failAt(sprintf('%s is not an expected BSON type: %s', (new Exporter())->shortenedExport($actual), implode(', ', (array) $operator['$$type'])), $keyPath); |
260 | 261 | }
|
261 | 262 |
|
262 | 263 | return;
|
@@ -284,7 +285,7 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $
|
284 | 285 | assertIsString($actual);
|
285 | 286 |
|
286 | 287 | if ($actual !== hex2bin($operator['$$matchesHexBytes'])) {
|
287 |
| - self::failAt(sprintf('%s does not match expected hex bytes: %s', $this->exporter()->shortenedExport($actual), $operator['$$matchesHexBytes']), $keyPath); |
| 288 | + self::failAt(sprintf('%s does not match expected hex bytes: %s', (new Exporter())->shortenedExport($actual), $operator['$$matchesHexBytes']), $keyPath); |
288 | 289 | }
|
289 | 290 |
|
290 | 291 | return;
|
@@ -349,7 +350,7 @@ protected function matches($other): bool
|
349 | 350 |
|
350 | 351 | public function toString(): string
|
351 | 352 | {
|
352 |
| - return 'matches ' . $this->exporter()->export($this->value); |
| 353 | + return 'matches ' . (new Exporter())->export($this->value); |
353 | 354 | }
|
354 | 355 |
|
355 | 356 | /** @psalm-return never-return */
|
|
0 commit comments