diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 2c9e53a2..c0de2f0c 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -13,8 +13,8 @@ use Pest\Arch\SingleArchExpectation; use Pest\Exceptions\InvalidExpectation; use Pest\Expectation; use Pest\Support\Arr; +use Pest\Support\Exporter; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\Exporter\Exporter; /** * @internal @@ -160,7 +160,7 @@ final class OppositeExpectation { $arguments = is_array($arguments) ? $arguments : [$arguments]; - $exporter = new Exporter(); + $exporter = Exporter::default(); $toString = fn ($argument): string => $exporter->shortenedExport($argument); diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index afec5ea0..48741dee 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -11,13 +11,13 @@ use InvalidArgumentException; use Pest\Exceptions\InvalidExpectationValue; use Pest\Matchers\Any; use Pest\Support\Arr; +use Pest\Support\Exporter; use Pest\Support\NullClosure; use PHPUnit\Framework\Assert; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\ExpectationFailedException; use ReflectionFunction; use ReflectionNamedType; -use SebastianBergmann\Exporter\Exporter; use Throwable; /** @@ -896,9 +896,9 @@ final class Expectation private function export(mixed $value): string { if ($this->exporter === null) { - $this->exporter = new Exporter(); + $this->exporter = Exporter::default(); } - return $this->exporter->export($value); + return $this->exporter->shortenedExport($value); } } diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 72dfb1b2..5099b13a 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -11,10 +11,10 @@ use Pest\Factories\Covers\CoversFunction; use Pest\Factories\Covers\CoversNothing; use Pest\Factories\TestCaseMethodFactory; use Pest\Support\Backtrace; +use Pest\Support\Exporter; use Pest\Support\HigherOrderCallables; use Pest\Support\NullClosure; use Pest\TestSuite; -use SebastianBergmann\Exporter\Exporter; /** * @internal @@ -276,12 +276,13 @@ final class TestCall */ private function addChain(string $file, int $line, string $name, array $arguments = null): self { + $exporter = Exporter::default(); $this->testCaseMethod ->chains ->add($file, $line, $name, $arguments); if ($this->descriptionLess) { - $exporter = new Exporter(); + Exporter::default(); if ($this->testCaseMethod->description !== null) { $this->testCaseMethod->description .= ' → '; } diff --git a/src/Repositories/DatasetsRepository.php b/src/Repositories/DatasetsRepository.php index df7c71da..c44d5df0 100644 --- a/src/Repositories/DatasetsRepository.php +++ b/src/Repositories/DatasetsRepository.php @@ -9,7 +9,7 @@ use Generator; use Pest\Exceptions\DatasetAlreadyExists; use Pest\Exceptions\DatasetDoesNotExist; use Pest\Exceptions\ShouldNotHappen; -use Pest\Exporters\Exporter; +use Pest\Support\Exporter; use function sprintf; use Traversable; @@ -229,7 +229,7 @@ final class DatasetsRepository */ private static function getDatasetDescription(int|string $key, array $data): string { - $exporter = new Exporter(); + $exporter = Exporter::default(); if (is_int($key)) { return sprintf('(%s)', $exporter->shortenedRecursiveExport($data)); diff --git a/src/Exporters/Exporter.php b/src/Support/Exporter.php similarity index 80% rename from src/Exporters/Exporter.php rename to src/Support/Exporter.php index 25c685b9..651bec1d 100644 --- a/src/Exporters/Exporter.php +++ b/src/Support/Exporter.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Pest\Exporters; +namespace Pest\Support; use SebastianBergmann\Exporter\Exporter as BaseExporter; use SebastianBergmann\RecursionContext\Context; @@ -18,16 +18,22 @@ final class Exporter private const MAX_ARRAY_ITEMS = 3; /** - * The PHPUnit exporter. + * Creates a new Exporter instance. */ - private readonly BaseExporter $exporter; + public function __construct( + private readonly BaseExporter $exporter, + ) { + // ... + } /** - * Instantiate the class. + * Creates a new Exporter instance. */ - public function __construct() + public static function default(): self { - $this->exporter = new BaseExporter(); + return new self( + new BaseExporter() + ); } /** @@ -40,7 +46,7 @@ final class Exporter $result = []; $array = $data; $itemsCount = 0; - $exporter = new self(); + $exporter = self::default(); $context ??= new Context(); $context->add($data); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index d38b77ad..aeb7deaa 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -919,5 +919,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 4 incomplete, 4 todos, 18 skipped, 627 passed (1514 assertions) - + Tests: 4 incomplete, 4 todos, 18 skipped, 636 passed (1556 assertions) \ No newline at end of file diff --git a/tests/Features/Expect/toHaveKey.php b/tests/Features/Expect/toHaveKey.php index 33989236..c1a979f6 100644 --- a/tests/Features/Expect/toHaveKey.php +++ b/tests/Features/Expect/toHaveKey.php @@ -62,15 +62,15 @@ test('fails with wrong value and plain key with dots', function () use ($test_ar test('not failures', function () use ($test_array) { expect($test_array)->not->toHaveKey('c'); -})->throws(ExpectationFailedException::class, "Expecting Array (...) not to have key 'c'"); +})->throws(ExpectationFailedException::class, "Expecting Array (…) not to have key 'c'"); test('not failures with nested key', function () use ($test_array) { expect($test_array)->not->toHaveKey('d.e'); -})->throws(ExpectationFailedException::class, "Expecting Array (...) not to have key 'd.e'"); +})->throws(ExpectationFailedException::class, "Expecting Array (…) not to have key 'd.e'"); test('not failures with plain key with dots', function () use ($test_array) { expect($test_array)->not->toHaveKey('key.with.dots'); -})->throws(ExpectationFailedException::class, "Expecting Array (...) not to have key 'key.with.dots'"); +})->throws(ExpectationFailedException::class, "Expecting Array (…) not to have key 'key.with.dots'"); test('not failures with correct value', function () use ($test_array) { expect($test_array)->not->toHaveKey('c', 'world'); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 5b622870..4e269fcb 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -13,6 +13,6 @@ $run = function () { }; test('parallel', function () use ($run) { - expect($run())->toContain('Running 650 tests using 3 processes') - ->toContain('Tests: 4 incomplete, 4 todos, 15 skipped, 627 passed (1546 assertions)'); + expect($run())->toContain('Running 652 tests using 3 processes') + ->toContain('Tests: 4 incomplete, 4 todos, 15 skipped, 629 passed (1548 assertions)'); });