diff --git a/src/Response/MessagesSent.php b/src/Response/MessagesSent.php index b46a385..24c3b18 100644 --- a/src/Response/MessagesSent.php +++ b/src/Response/MessagesSent.php @@ -32,6 +32,10 @@ public function ids() : array $recipients = json_decode(json_encode($this->xml), true)['recipient']; + if(count($recipients) == 1) { + $recipients = [$recipients]; + } + return array_map(fn($r) => [$r['@attributes']['msisdn'] => $r['@attributes']['id']], $recipients); } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 679c213..cce9b83 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -113,7 +113,7 @@ public function testGatewayCanSendMessages() $this->assertEquals($stub, $response->getResponse()->getBody()->getContents()); } - public function testGatewayCanReturnMessageIds() + public function testGatewayCanReturnMultipleMessageIds() { $stub = << @@ -146,4 +146,34 @@ public function testGatewayCanReturnMessageIds() $this->assertEquals('123', $firstId); $this->assertEquals([['4512345679' => '123'], ['4512345679' => '13cab0f4-0e4f-44cf-8f84-a9eb435f36a4']], $ids); } + + public function testGatewayCanReturnSingleMessageId() + { + $stub = << + + + XML; + $mockedResponse = new Response(200, [], $stub); + + $mock = new MockHandler([$mockedResponse, $mockedResponse]); + $mockHandler = new HandlerStack($mock); + $client = new Client(['handler' => $mockHandler]); + + $gateway = new Gateway('foo', $client); + + $gateway->addMessage( + Message::create('foo') + ->from('1245') + ->to([ + new Recipient('4512345679') + ]) + ); + + $response = $gateway->send(); + + $firstId = $response->id(); + + $this->assertEquals('13cab0f4-0e4f-44cf-8f84-a9eb435f36a4', $firstId); + } }