diff --git a/ChangeLog.md b/ChangeLog.md index b13b170..c45b005 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [6.1.2] - 2024-MM-DD + +### Fixed + +* [#62](https://github.com/sebastianbergmann/exporter/issues/62): Do not limit export of arrays by default (to restore BC with versions prior to 6.1.0) + ## [6.1.1] - 2024-06-18 ### Fixed @@ -140,6 +146,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * Remove HHVM-specific code that is no longer needed +[6.1.2]: https://github.com/sebastianbergmann/exporter/compare/6.1.1...main [6.1.1]: https://github.com/sebastianbergmann/exporter/compare/6.1.0...6.1.1 [6.1.0]: https://github.com/sebastianbergmann/exporter/compare/6.0.3...6.1.0 [6.0.3]: https://github.com/sebastianbergmann/exporter/compare/fe0dca49a60d34440e2f086951952dd13aa9a5d2...6.0.3 diff --git a/src/Exporter.php b/src/Exporter.php index a368541..fdaa3da 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -40,14 +40,14 @@ use UnitEnum; final readonly class Exporter { /** - * @var positive-int + * @var non-negative-int */ private int $shortenArraysLongerThan; /** - * @param positive-int $shortenArraysLongerThan + * @param non-negative-int $shortenArraysLongerThan */ - public function __construct(int $shortenArraysLongerThan = 10) + public function __construct(int $shortenArraysLongerThan = 0) { $this->shortenArraysLongerThan = $shortenArraysLongerThan; } @@ -81,7 +81,8 @@ final readonly class Exporter $export = $this->shortenedCountedRecursiveExport($data, $processed, $counter); - if ($overallCount > $this->shortenArraysLongerThan) { + if ($this->shortenArraysLongerThan > 0 && + $overallCount > $this->shortenArraysLongerThan) { $export .= sprintf(', ...%d more elements', $overallCount - $this->shortenArraysLongerThan); } @@ -209,7 +210,8 @@ final readonly class Exporter $processed->add($data); foreach ($array as $key => $value) { - if ($counter > $this->shortenArraysLongerThan) { + if ($this->shortenArraysLongerThan > 0 && + $counter > $this->shortenArraysLongerThan) { break; } diff --git a/tests/ExporterTest.php b/tests/ExporterTest.php index 0c08177..2f11119 100644 --- a/tests/ExporterTest.php +++ b/tests/ExporterTest.php @@ -349,19 +349,19 @@ EOF, $deepArray = [$array, [$array, [$array, [$array, [$array, [$array, [$array, [$array, [$array, [$array]]]]]]]]]]; return [ - 'null' => [[null], 'null'], - 'boolean true' => [[true], 'true'], - 'boolean false' => [[false], 'false'], - 'int 1' => [[1], '1'], - 'float 1.0' => [[1.0], '1.0'], - 'float 1.2' => [[1.2], '1.2'], - 'numeric string' => [['1'], "'1'"], - 'with numeric array key' => [[2 => 1], '1'], - 'with assoc array key' => [['foo' => 'bar'], '\'bar\''], - 'multidimensional array' => [[[1, 2, 3], [3, 4, 5]], '[1, 2, 3], [3, 4, 5]'], - 'object' => [[new stdClass], 'stdClass Object ()'], - 'big array' => [$bigArray, "'cast('foo0' as blob)', 'cast('foo1' as blob)', 'cast('foo2' as blob)', 'cast('foo3' as blob)', 'cast('foo4' as blob)', 'cast('foo5' as blob)', 'cast('foo6' as blob)', 'cast('foo7' as blob)', 'cast('foo8' as blob)', 'cast('foo9' as blob)', 'cast('foo10' as blob)', ...19990 more elements"], - 'deep array' => [$deepArray, "[1, 2, 'hello', 'world', true, false], [[1, 2, 'hello', 'world']], ...69 more elements"], + 'null' => [[null], 'null', 0], + 'boolean true' => [[true], 'true', 0], + 'boolean false' => [[false], 'false', 0], + 'int 1' => [[1], '1', 0], + 'float 1.0' => [[1.0], '1.0', 0], + 'float 1.2' => [[1.2], '1.2', 0], + 'numeric string' => [['1'], "'1'", 0], + 'with numeric array key' => [[2 => 1], '1', 0], + 'with assoc array key' => [['foo' => 'bar'], '\'bar\'', 0], + 'multidimensional array' => [[[1, 2, 3], [3, 4, 5]], '[1, 2, 3], [3, 4, 5]', 0], + 'object' => [[new stdClass], 'stdClass Object ()', 0], + 'big array' => [$bigArray, "'cast('foo0' as blob)', 'cast('foo1' as blob)', 'cast('foo2' as blob)', 'cast('foo3' as blob)', 'cast('foo4' as blob)', 'cast('foo5' as blob)', 'cast('foo6' as blob)', 'cast('foo7' as blob)', 'cast('foo8' as blob)', 'cast('foo9' as blob)', 'cast('foo10' as blob)', ...19990 more elements", 10], + 'deep array' => [$deepArray, "[1, 2, 'hello', 'world', true, false], [[1, 2, 'hello', 'world']], ...69 more elements", 10], ]; } @@ -511,9 +511,9 @@ EOF; } #[DataProvider('shortenedRecursiveExportProvider')] - public function testShortenedRecursiveExport(array $value, string $expected): void + public function testShortenedRecursiveExport(array $value, string $expected, int $limit): void { - $this->assertEquals($expected, (new Exporter)->shortenedRecursiveExport($value)); + $this->assertEquals($expected, (new Exporter($limit))->shortenedRecursiveExport($value)); } public function testShortenedRecursiveOccurredRecursion(): void