Skip to content

Voice, MFA, and messaging class/method/signature renames (breaking changes) #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-added tests
  • Loading branch information
jmulford-bw committed Jul 22, 2021
commit 8041f28bda71c7acb53b0d937a20cd63da9c20e5
1 change: 1 addition & 0 deletions .gitkeep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
README.md
src/Voice/Bxml/*
src/WebRtc/Utils/*
tests/*
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
"apimatic/jsonmapper": "~1.3.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.7",
"phan/phan": "^1.2",
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "^9"
},
"autoload": {
"psr-4": {
"BandwidthLib\\": "src/"
}
}
}
}
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand Down
157 changes: 157 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

/**
* ApiTest.php
*
* A simple php integration test class for API requests and responses
*
* @copyright Bandwidth INC
*/

use PHPUnit\Framework\TestCase;

final class ApiTest extends TestCase
{
protected $bandwidthClient;

protected function setUp(): void {
$config = new BandwidthLib\Configuration(
array(
'messagingBasicAuthUserName' => getenv("USERNAME"),
'messagingBasicAuthPassword' => getenv("PASSWORD"),
'voiceBasicAuthUserName' => getenv("USERNAME"),
'voiceBasicAuthPassword' => getenv("PASSWORD"),
'twoFactorAuthBasicAuthUserName' => getenv("USERNAME"),
'twoFactorAuthBasicAuthPassword' => getenv("PASSWORD"),
'phoneNumberLookupBasicAuthUserName' => getenv("USERNAME"),
'phoneNumberLookupBasicAuthPassword' => getenv("PASSWORD")
)
);
$this->bandwidthClient = new BandwidthLib\BandwidthClient($config);
}

public function testCreateMessage() {
$body = new BandwidthLib\Messaging\Models\MessageRequest();
$body->from = getenv("PHONE_NUMBER_INBOUND");
$body->to = [getenv("PHONE_NUMBER_OUTBOUND")];
$body->applicationId = getenv("MESSAGING_APPLICATION_ID");
$body->text = "PHP Monitoring";

$response = $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("ACCOUNT_ID"), $body);

$this->assertTrue(strlen($response->getResult()->id) > 0); //validate that _some_ id was returned
}

public function testCreateMessageInvalidPhoneNumber() {
$body = new BandwidthLib\Messaging\Models\MessageRequest();
$body->from = getenv("PHONE_NUMBER_INBOUND");
$body->to = ["+1invalid"];
$body->applicationId = getenv("MESSAGING_APPLICATION_ID");
$body->text = "PHP Monitoring";

try {
$this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("ACCOUNT_ID"), $body);
//workaround to make sure that if the above error is not raised, the build will fail
$this->assertTrue(false);
} catch (BandwidthLib\Messaging\Exceptions\MessagingException $e) {
$this->assertTrue(strlen($e->description) > 0);
}
}

public function testUploadDownloadMedia() {
//constants

$mediaFileName = "php_monitoring";
$mediaFile = "12345"; //todo: confirm binary string?
//media upload
$this->bandwidthClient->getMessaging()->getClient()->uploadMedia(getenv("ACCOUNT_ID"), $mediaFileName, strlen($mediaFile), $mediaFile);

//media download
$downloadedMediaFile = $this->bandwidthClient->getMessaging()->getClient()->getMedia(getenv("ACCOUNT_ID"), $mediaFileName)->getResult();

//validate that response is the same
$this->assertEquals($downloadedMediaFile, $mediaFile);
}

public function testCreateCallAndGetCallState() {
$body = new BandwidthLib\Voice\Models\ApiCreateCallRequest();
$body->from = getenv("PHONE_NUMBER_INBOUND");
$body->to = getenv("PHONE_NUMBER_OUTBOUND");
$body->applicationId = getenv("VOICE_APPLICATION_ID");
$body->answerUrl = getenv("VOICE_CALLBACK_URL");
$response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("ACCOUNT_ID"), $body);
$callId = $response->getResult()->callId;
$this->assertTrue(strlen($callId) > 0);

//get phone call information
$response = $this->bandwidthClient->getVoice()->getClient()->getCallState(getenv("ACCOUNT_ID"), $callId);
$this->assertTrue(strlen($response->getResult()->state) > 0);
}

public function testCreateCallInvalidPhoneNumber() {
$body = new BandwidthLib\Voice\Models\ApiCreateCallRequest();
$body->from = getenv("PHONE_NUMBER_INBOUND");
$body->to = "+1invalid";
$body->applicationId = getenv("VOICE_APPLICATION_ID");
$body->answerUrl = getenv("VOICE_CALLBACK_URL");

try {
$this->bandwidthClient->getVoice()->getClient()->createCall(getenv("ACCOUNT_ID"), $body);
//workaround to make sure that if the above error is not raised, the build will fail
$this->assertTrue(false);
} catch (BandwidthLib\Voice\Exceptions\ApiErrorResponseException $e) {
$this->assertTrue(strlen($e->description) > 0);
}
}

public function testMfaMessaging() {
$body = new BandwidthLib\TwoFactorAuth\Models\TwoFactorCodeRequestSchema();
$body->from = getenv("PHONE_NUMBER_MFA");
$body->to = getenv("PHONE_NUMBER_INBOUND");
$body->applicationId = getenv("MFA_MESSAGING_APPLICATION_ID");
$body->scope = "scope";
$body->digits = 6;
$body->message = "Your temporary {NAME} {SCOPE} code is {CODE}";

$response = $this->bandwidthClient->getTwoFactorAuth()->getMFA()->createMessagingTwoFactor(getenv("ACCOUNT_ID"), $body);
$this->assertTrue(strlen($response->getResult()->messageId) > 0); //validate that _some_ id was returned
}

public function testMfaVoice() {
$body = new BandwidthLib\TwoFactorAuth\Models\TwoFactorCodeRequestSchema();
$body->from = getenv("PHONE_NUMBER_MFA");
$body->to = getenv("PHONE_NUMBER_INBOUND");
$body->applicationId = getenv("MFA_VOICE_APPLICATION_ID");
$body->scope = "scope";
$body->digits = 6;
$body->message = "Your temporary {NAME} {SCOPE} code is {CODE}";

$response = $this->bandwidthClient->getTwoFactorAuth()->getMFA()->createVoiceTwoFactor(getenv("ACCOUNT_ID"), $body);
$this->assertTrue(strlen($response->getResult()->callId) > 0); //validate that _some_ id was returned
}

public function testMfaVerify() {
$body = new BandwidthLib\TwoFactorAuth\Models\TwoFactorVerifyRequestSchema();
$body->from = getenv("PHONE_NUMBER_MFA");
$body->to = getenv("PHONE_NUMBER_INBOUND");
$body->applicationId = getenv("MFA_VOICE_APPLICATION_ID");
$body->scope = "scope";
$body->code = "123456";
$body->digits = 6;
$body->expirationTimeInMinutes = 3;

$response = $this->bandwidthClient->getTwoFactorAuth()->getMFA()->createVerifyTwoFactor(getenv("ACCOUNT_ID"), $body);
$this->assertTrue(is_bool($response->getResult()->valid));
}

public function testTnLookup() {
$body = new BandwidthLib\PhoneNumberLookup\Models\OrderRequest();
$body->tns = [getenv("PHONE_NUMBER_OUTBOUND")];
$createResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->createLookupRequest(getenv("ACCOUNT_ID"), $body);
$this->assertTrue(strlen($createResponse->getResult()->requestId) > 0);

$requestId = $createResponse->getResult()->requestId;
$getResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->getLookupRequestStatus(getenv("ACCOUNT_ID"), $requestId);
$this->assertTrue(strlen($getResponse->getResult()->status) > 0);
}
}
Loading