/** * @expectedException \OpiloClient\Response\CommunicationException */ public function testSendSMSWithError() { // Mock a Guzzle client to be used $responseArray = ['error' => 2]; $responses = [new Response(401, [], json_encode($responseArray))]; $client = $this->mockGuzzleClient($responses); // Make HttpClient to use mocked Guzzle client $httpClient = new HttpClient('no-need-for-username', 'no-need-for-password', $client); // Send sms $message = new OutgoingSMS('9121231234', '9123214321', 'hey'); $httpClient->sendSMS($message); }
public function testSendInvalidSMS() { $client = new HttpClient(new ConnectionConfig(getenv('OPILO_URL')), new Account(getenv('OPILO_USERNAME'), getenv('OPILO_PASSWORD'))); $messages = [new OutgoingSMS('abcd', getenv('DESTINATION'), 'invalid from'), new OutgoingSMS(getenv('PANEL_LINE'), 'abcd', 'invalid to'), new OutgoingSMS('3000', getenv('DESTINATION'), 'unauthorized from'), new OutgoingSMS(getenv('PANEL_LINE'), getenv('DESTINATION'), 'authorized from')]; $response = $client->sendSMS($messages); $this->assertCount(4, $response); $this->assertInstanceOf(SendError::class, $response[0]); $this->assertInstanceOf(SendError::class, $response[1]); $this->assertInstanceOf(SendError::class, $response[2]); $this->assertInstanceOf(SMSId::class, $response[3]); $this->assertSame(SendError::ERROR_RESOURCE_NOT_FOUND, $response[0]->getError()); $this->assertSame(SendError::ERROR_INVALID_DESTINATION, $response[1]->getError()); $this->assertSame(SendError::ERROR_RESOURCE_NOT_FOUND, $response[2]->getError()); }
public function testSendMultipleSMS() { $initCredit = $this->client->getCredit()->getSmsPageCount(); $messages = []; for ($i = 0; $i < 10; $i++) { $messages[] = new OutgoingSMS(getenv('PANEL_LINE'), getenv('DESTINATION'), 'V2::testSendMultipleSMS' . "({$i})", uniqid('test_app:', true), new \DateTime("+{$i} Minutes")); } $response = $this->client->sendSMS($messages); $this->assertCount(10, $response); $ids = []; foreach ($response as $id) { $this->assertInstanceOf(SMSId::class, $id); $ids[] = $id->getId(); } $status = $this->client->checkStatus($ids); $this->assertInstanceOf(CheckStatusResponse::class, $status); $status = $status->getStatusArray(); $this->assertCount(10, $status); foreach ($status as $stat) { $this->assertInstanceOf(Status::class, $stat); } $finalCredit = $this->client->getCredit()->getSmsPageCount(); $this->assertLessThanOrEqual(10, $initCredit - $finalCredit); }
<?php use OpiloClient\Configs\Account; use OpiloClient\Configs\ConnectionConfig; use OpiloClient\V2\HttpClient; use OpiloClient\Request\OutgoingSMS; require_once __DIR__ . '/webservice-bin.phar'; $config = new ConnectionConfig('http://bpanel.opilo.com'); $account = new Account('YOUR_WEBSERVICE_USERNAME', 'YOUR_WEBSERVICE_PASSWORD'); $client = new HttpClient($config, $account); $message = new OutgoingSMS('3000****', '0912*******', 'Hello World!'); $responses = $client->sendSMS($message); echo "Hello World SMS sent!\n";