Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): return null from PHP catalog info and product on an empty body

Yudhi Armyndharis9e90df66afea
diff --git a/sdk/php/src/Resources/CatalogResource.php b/sdk/php/src/Resources/CatalogResource.php
index 07c7b2eb5..f3f98f6d9 100644
--- a/sdk/php/src/Resources/CatalogResource.php
+++ b/sdk/php/src/Resources/CatalogResource.php
@@ -23,8 +23,12 @@ class CatalogResource
$this->http = $http;
}
- /** @return array<string,mixed> */
- public function info(string $sessionId): array
+ /**
+ * The catalog summary, or null when the account has no catalog collection to describe.
+ *
+ * @return array<string,mixed>|null
+ */
+ public function info(string $sessionId): ?array
{
return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/catalog");
}
@@ -43,8 +47,12 @@ class CatalogResource
?? ['products' => [], 'pagination' => []];
}
- /** @return array<string,mixed> */
- public function product(string $sessionId, string $productId): array
+ /**
+ * One catalog product, or null when no product in the catalog carries that id.
+ *
+ * @return array<string,mixed>|null
+ */
+ public function product(string $sessionId, string $productId): ?array
{
return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/catalog/products/{$this->http->encodeSegment($productId)}");
}
diff --git a/sdk/php/tests/LabelsChannelsCatalogTest.php b/sdk/php/tests/LabelsChannelsCatalogTest.php
index b5b081935..5121b6e37 100644
--- a/sdk/php/tests/LabelsChannelsCatalogTest.php
+++ b/sdk/php/tests/LabelsChannelsCatalogTest.php
@@ -68,6 +68,16 @@ class LabelsChannelsCatalogTest extends TestCase
$this->assertSame(['chatId' => '[email protected]', 'productId' => 'p1', 'body' => 'x'], $backend->calls()[3]['body']);
}
+ public function testCatalogInfoAndProductReturnNullOnAnEmptyBody(): void
+ {
+ $backend = new MockBackend();
+ $backend->on(200);
+ $backend->on(200);
+ $client = $backend->makeClient();
+ $this->assertNull($client->catalog->info('s'));
+ $this->assertNull($client->catalog->product('s', 'missing'));
+ }
+
public function testClientExposesAll11Resources(): void
{
$client = (new MockBackend())->makeClient();