Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbelt committed Apr 1, 2020
1 parent e15618b commit 0a7d609
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Response/MessagesSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
32 changes: 31 additions & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testGatewayCanSendMessages()
$this->assertEquals($stub, $response->getResponse()->getBody()->getContents());
}

public function testGatewayCanReturnMessageIds()
public function testGatewayCanReturnMultipleMessageIds()
{
$stub = <<<XML
<reply>
Expand Down Expand Up @@ -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
<reply>
<recipient msisdn="4512345679" id="13cab0f4-0e4f-44cf-8f84-a9eb435f36a4" />
</reply>
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);
}
}

0 comments on commit 0a7d609

Please sign in to comment.