diff --git a/src/Valuestore.php b/src/Valuestore.php index 62a5aae..9f2189d 100644 --- a/src/Valuestore.php +++ b/src/Valuestore.php @@ -176,7 +176,7 @@ public function all() : array return []; } - return json_decode(file_get_contents($this->fileName), true); + return json_decode(file_get_contents($this->fileName), true) ?? []; } /** diff --git a/tests/ValuestoreTest.php b/tests/ValuestoreTest.php index 32a8e63..270d223 100644 --- a/tests/ValuestoreTest.php +++ b/tests/ValuestoreTest.php @@ -438,4 +438,20 @@ public function it_will_delete_the_underlying_file_when_no_values_are_left_in_th $this->assertFileNotExists($this->storageFile); } + + /** @test */ + public function the_all_function_will_always_return_an_array() + { + $this->assertFileNotExists($this->storageFile); + + touch($this->storageFile); + + $this->assertStringEqualsFile($this->storageFile, ''); + + $this->assertIsArray($this->valuestore->all()); + + $this->valuestore->flush(); + + $this->assertFileNotExists($this->storageFile); + } }