From f980a35b2c15f3c569a09424bd9d4b2b107354ea Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 20 Dec 2025 19:58:07 +0100 Subject: [PATCH] Bugfix: Task API returns task_uuid but Task object expects $uuid. See https://dev.chartmogul.com/reference/tasks/retrieve/ with "task_uuid" example, even the PHP code shows that. But field is named $uuid. --- src/Task.php | 8 ++++++++ tests/Unit/TaskTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Task.php b/src/Task.php index 9fc2bc9..cd2b087 100644 --- a/src/Task.php +++ b/src/Task.php @@ -48,4 +48,12 @@ class Task extends AbstractResource protected $completed_at; protected $created_at; protected $updated_at; + + public function __construct(array $attr = [], ?ClientInterface $client = null) + { + if (isset($attr['task_uuid'])) { + $attr['uuid'] = $attr['task_uuid']; + } + parent::__construct($attr); + } } diff --git a/tests/Unit/TaskTest.php b/tests/Unit/TaskTest.php index d6716eb..55aebe5 100644 --- a/tests/Unit/TaskTest.php +++ b/tests/Unit/TaskTest.php @@ -49,6 +49,17 @@ class TaskTest extends TestCase "has_more": true }'; + const TASK_ALTERNATIVE_JSON = '{ + "task_uuid": "00000000-1111-2222-3333-000000000000", + "customer_uuid": "cus_00000000-0000-0000-0000-000000000000", + "task_details": "This is some task details text.", + "assignee": "customer@example.com", + "due_date": "2025-04-30T00:00:00Z", + "completed_at": "2025-04-20T00:00:00Z", + "created_at": "2025-04-01T12:00:00.000Z", + "updated_at": "2025-04-01T12:00:00.000Z" + }'; + public function testListTasks() { $stream = Psr7\stream_for(TaskTest::LIST_TASKS_JSON); @@ -127,6 +138,24 @@ public function testRetrieveTask() $this->assertEquals("2025-04-01T12:00:00.000Z", $result->updated_at); } + public function testRetrieveAlternativeJsonTask() + { + $stream = Psr7\stream_for(TaskTest::TASK_ALTERNATIVE_JSON); + list($cmClient, $mockClient) = $this->getMockClient(0, [200], $stream); + + $uuid = "00000000-1111-2222-3333-000000000000"; + + $result = Task::retrieve($uuid, $cmClient); + $request = $mockClient->getRequests()[0]; + + $this->assertEquals("GET", $request->getMethod()); + $uri = $request->getUri(); + $this->assertEquals("/v1/tasks/".$uuid, $uri->getPath()); + + $this->assertTrue($result instanceof Task); + $this->assertEquals("00000000-1111-2222-3333-000000000000", $result->uuid); + } + public function testUpdateTask() { $stream = Psr7\stream_for(TaskTest::UPDATED_TASK_JSON);