Skip to content

Commit a2223b8

Browse files
committed
bugfix
Exception was occurring when the value of SK or PK was 0.
1 parent 6534d78 commit a2223b8

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Kitar/Dynamodb/Model/Model.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getKey()
7474
$missingKeys = [];
7575

7676
foreach ($key as $name => $value) {
77-
if (empty($value)) {
77+
if (! isset($value) || $value === '') {
7878
$missingKeys[] = $name;
7979
}
8080
}

tests/Model/ModelTest.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,25 @@ public function it_can_create_instance_with_existing_data()
162162
/** @test */
163163
public function it_can_process_get_key_with_primary_key()
164164
{
165-
$user = new UserA(['partition' => 'p']);
165+
$user1 = new UserA(['partition' => 'p']);
166+
$user2 = new UserA(['partition' => "0"]);
167+
$user3 = new UserA(['partition' => 0]);
166168

167-
$this->assertEquals(['partition' => 'p'], $user->getKey());
169+
$this->assertEquals(['partition' => 'p'], $user1->getKey());
170+
$this->assertEquals(['partition' => "0"], $user2->getKey());
171+
$this->assertEquals(['partition' => 0], $user3->getKey());
168172
}
169173

170-
171174
/** @test */
172175
public function it_can_process_get_key_with_primary_key_and_sort_key()
173176
{
174-
$user = new UserB(['partition' => 'p', 'sort' => 's']);
177+
$user1 = new UserB(['partition' => 'p', 'sort' => 's']);
178+
$user2 = new UserB(['partition' => 'p', 'sort' => "0"]);
179+
$user3 = new UserB(['partition' => 'p', 'sort' => 0]);
175180

176-
$this->assertEquals([
177-
'partition' => 'p',
178-
'sort' => 's'
179-
], $user->getKey());
181+
$this->assertEquals(['partition' => 'p', 'sort' => 's'], $user1->getKey());
182+
$this->assertEquals(['partition' => 'p', 'sort' => "0"], $user2->getKey());
183+
$this->assertEquals(['partition' => 'p', 'sort' => 0], $user3->getKey());
180184
}
181185

182186
/** @test */

0 commit comments

Comments
 (0)