Skip to content

Commit 4db1d3c

Browse files
authored
add ability to pull out response for logging/reverse engineering (#425)
1 parent ebf3a81 commit 4db1d3c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/SMS/Collection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public function valid(): bool
6161
{
6262
return isset($this->data['messages'][$this->current]);
6363
}
64+
65+
public function getAllMessagesRaw(): array
66+
{
67+
return $this->data;
68+
}
6469
}

test/SMS/ClientTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,44 @@ public function testCanSendSMS(): void
108108
$this->assertSame("my-personal-reference", $sentData->getClientRef());
109109
}
110110

111+
public function testCanGetSmsRawResponse(): void
112+
{
113+
$args = [
114+
'to' => '447700900000',
115+
'from' => '16105551212',
116+
'text' => "Go To Gino's",
117+
'account-ref' => 'customer1234',
118+
'client-ref' => 'my-personal-reference'
119+
];
120+
121+
$this->vonageClient->send(Argument::that(function (Request $request) use ($args) {
122+
$this->assertRequestJsonBodyContains('to', $args['to'], $request);
123+
$this->assertRequestJsonBodyContains('from', $args['from'], $request);
124+
$this->assertRequestJsonBodyContains('text', $args['text'], $request);
125+
$this->assertRequestJsonBodyContains('account-ref', $args['account-ref'], $request);
126+
$this->assertRequestJsonBodyContains('client-ref', $args['client-ref'], $request);
127+
128+
return true;
129+
}))->willReturn($this->getResponse('send-success'));
130+
131+
$message = (new SMS($args['to'], $args['from'], $args['text']))
132+
->setClientRef($args['client-ref'])
133+
->setAccountRef($args['account-ref']);
134+
$response = $this->smsClient->send($message);
135+
$rawResponse = $response->getAllMessagesRaw();
136+
137+
$this->assertCount(2, $rawResponse);
138+
$this->assertSame('1', $rawResponse['message-count']);
139+
$this->assertCount(1, $rawResponse['messages']);
140+
$this->assertSame($args['to'], $rawResponse['messages'][0]['to']);
141+
$this->assertSame('0A0000000123ABCD1', $rawResponse['messages'][0]['message-id']);
142+
$this->assertSame("0.03330000", $rawResponse['messages'][0]['message-price']);
143+
$this->assertSame("12345", $rawResponse['messages'][0]['network']);
144+
$this->assertSame("3.14159265", $rawResponse['messages'][0]['remaining-balance']);
145+
$this->assertSame("customer1234", $rawResponse['messages'][0]['account-ref']);
146+
$this->assertSame("my-personal-reference", $rawResponse['messages'][0]['client-ref']);
147+
}
148+
111149
/**
112150
* @throws ClientExceptionInterface
113151
* @throws Client\Exception\Exception

0 commit comments

Comments
 (0)