Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
Exception was occurring when the value of SK or PK was 0.
  • Loading branch information
kitar committed Sep 12, 2023
1 parent 6534d78 commit a2223b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Kitar/Dynamodb/Model/Model.php
Expand Up @@ -74,7 +74,7 @@ public function getKey()
$missingKeys = [];

foreach ($key as $name => $value) {
if (empty($value)) {
if (! isset($value) || $value === '') {
$missingKeys[] = $name;
}
}
Expand Down
20 changes: 12 additions & 8 deletions tests/Model/ModelTest.php
Expand Up @@ -162,21 +162,25 @@ public function it_can_create_instance_with_existing_data()
/** @test */
public function it_can_process_get_key_with_primary_key()
{
$user = new UserA(['partition' => 'p']);
$user1 = new UserA(['partition' => 'p']);
$user2 = new UserA(['partition' => "0"]);
$user3 = new UserA(['partition' => 0]);

$this->assertEquals(['partition' => 'p'], $user->getKey());
$this->assertEquals(['partition' => 'p'], $user1->getKey());
$this->assertEquals(['partition' => "0"], $user2->getKey());
$this->assertEquals(['partition' => 0], $user3->getKey());
}


/** @test */
public function it_can_process_get_key_with_primary_key_and_sort_key()
{
$user = new UserB(['partition' => 'p', 'sort' => 's']);
$user1 = new UserB(['partition' => 'p', 'sort' => 's']);
$user2 = new UserB(['partition' => 'p', 'sort' => "0"]);
$user3 = new UserB(['partition' => 'p', 'sort' => 0]);

$this->assertEquals([
'partition' => 'p',
'sort' => 's'
], $user->getKey());
$this->assertEquals(['partition' => 'p', 'sort' => 's'], $user1->getKey());
$this->assertEquals(['partition' => 'p', 'sort' => "0"], $user2->getKey());
$this->assertEquals(['partition' => 'p', 'sort' => 0], $user3->getKey());
}

/** @test */
Expand Down

0 comments on commit a2223b8

Please sign in to comment.