Skip to content

Commit

Permalink
This PR is related to #23: all() method sometimes return null (#34)
Browse files Browse the repository at this point in the history
* make sure to all() method are always return an array

* Update ValuestoreTest.php

Co-authored-by: Freek Van der Herten <freek@spatie.be>
  • Loading branch information
ArroWsGM and freekmurze committed Aug 21, 2020
1 parent 5177691 commit cd02862
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Valuestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? [];
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/ValuestoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit cd02862

Please sign in to comment.