Skip to content

Commit

Permalink
Fix bug with renumbering keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
vedanshujain committed Feb 4, 2025
1 parent 6a5201e commit 29d8282
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/tests/unit/MockSerializableKVStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public function fetch( string $site_id, string $entity_type, array $entity_ids,

public function add( string $site_id, string $entity_type, array $entities, int $ttl = -1 ): bool {
$this->init_site_entity_type( $site_id, $entity_type );
$this->data[ $site_id ][ $entity_type ] = array_merge( $this->data[ $site_id ][ $entity_type ], $entities );
foreach ( $entities as $entity_id => $entity ) {
// merge manually instead of array_merge to not have PHP renumber integer keys.
$this->data[ $site_id ][ $entity_type ][ $entity_id ] = $entity;
}
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions app/tests/unit/Webhooks/CategoryWebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function test_create_category(): void {
$this->request->method( 'getPayload' )->willReturn( new InputBag( $request_body ) );
$this->sut->serve();
$categories = $this->kv_store->fetch( $this->site_info->id, 'categories', array( '1' ), array( Category::class ) );
error_log( print_r( $categories, true ) );
$category = $categories[1];
$category = $categories[1];
$this->assertEquals( 1, $category->id );
$this->assertEquals( 'Test Category', $category->name );
$this->assertEquals( 'test-category', $category->slug );
Expand Down

0 comments on commit 29d8282

Please sign in to comment.