Skip to content

Commit

Permalink
bucket null values getter
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Mar 26, 2024
1 parent c68f983 commit c9ffd0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/KeyValue/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use Basis\Nats\Client;
use Basis\Nats\Consumer\Configuration as ConsumerConfiguration;
use Basis\Nats\Stream\Stream;
use Basis\Nats\Message\Payload;
use Basis\Nats\Stream\Stream;
use Exception;

class Bucket
{
Expand All @@ -24,8 +25,15 @@ public function __construct(

public function get(string $key)
{
$entry = $this->getEntry($key);
return $entry ? $entry->value : null;
try {
$entry = $this->getEntry($key);
return $entry ? $entry->value : null;
} catch (Exception $e) {
if ($e->getMessage() == 'no message found') {
return null;
}
throw $e;
}
}

public function getConfiguration(): Configuration
Expand Down
10 changes: 10 additions & 0 deletions tests/Functional/KeyValue/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

class BucketTest extends FunctionalTestCase
{
public function testNullValues()
{
$bucket = $this->createClient()
->getApi()
->getBucket('test_bucket');

$this->assertSame(0, $bucket->getStatus()->values);
$this->assertNull($bucket->get('username'));
}

public function testBasics()
{
$bucket = $this->createClient()
Expand Down

0 comments on commit c9ffd0b

Please sign in to comment.