Skip to content

Commit

Permalink
Fixed handling of empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Apr 12, 2021
1 parent ea0863a commit 2d4bd57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Services/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function setSimple(): void

public function raw(array $array, int $pad = 1): string
{
if (empty($array)) {
return '[]';
}

$array = $this->convertKeysCase($array);

$keys_size = $this->sizeKeys($array);
Expand Down
9 changes: 9 additions & 0 deletions tests/FormatterRawTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ public function testStoreNotString()
$formatted . PHP_EOL
);
}

public function testEmptyArray()
{
$service = $this->service();

$formatted = $service->raw([]);

$this->assertSame('[]', $formatted);
}
}

0 comments on commit 2d4bd57

Please sign in to comment.