diff --git a/src/Kitar/Dynamodb/Model/Model.php b/src/Kitar/Dynamodb/Model/Model.php index 70afc78..1698f56 100644 --- a/src/Kitar/Dynamodb/Model/Model.php +++ b/src/Kitar/Dynamodb/Model/Model.php @@ -74,7 +74,7 @@ public function getKey() $missingKeys = []; foreach ($key as $name => $value) { - if (empty($value)) { + if (! isset($value) || $value === '') { $missingKeys[] = $name; } } diff --git a/tests/Model/ModelTest.php b/tests/Model/ModelTest.php index 7660bb8..44ddf41 100644 --- a/tests/Model/ModelTest.php +++ b/tests/Model/ModelTest.php @@ -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 */