From c081d141152cbbcd71211d0c37a11d7f9685e4c4 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:18:59 -0400 Subject: [PATCH 1/7] DX-2244 Removed URL Encoding for Media Functions --- src/Messaging/Controllers/APIController.php | 21 ++++++++++++--------- tests/ApiTest.php | 5 ++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Messaging/Controllers/APIController.php b/src/Messaging/Controllers/APIController.php index 0a7eca2..99e1fda 100644 --- a/src/Messaging/Controllers/APIController.php +++ b/src/Messaging/Controllers/APIController.php @@ -137,9 +137,10 @@ public function getMedia( //process optional query parameters $_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array ( - 'accountId' => $accountId, - 'mediaId' => $mediaId, - )); + 'accountId' => $accountId, + 'mediaId' => $mediaId, + ), false + ); //validate and preprocess url $_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::MESSAGINGDEFAULT) . $_queryBuilder); @@ -232,9 +233,10 @@ public function uploadMedia( //process optional query parameters $_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array ( - 'accountId' => $accountId, - 'mediaId' => $mediaId, - )); + 'accountId' => $accountId, + 'mediaId' => $mediaId, + ), false + ); //validate and preprocess url $_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::MESSAGINGDEFAULT) . $_queryBuilder); @@ -325,9 +327,10 @@ public function deleteMedia( //process optional query parameters $_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array ( - 'accountId' => $accountId, - 'mediaId' => $mediaId, - )); + 'accountId' => $accountId, + 'mediaId' => $mediaId, + ), false + ); //validate and preprocess url $_queryUrl = APIHelper::cleanUrl($this->config->getBaseUri(Servers::MESSAGINGDEFAULT) . $_queryBuilder); diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 31d8e3f..0f46743 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -61,7 +61,7 @@ public function testCreateMessageInvalidPhoneNumber() { public function testUploadDownloadMedia() { //constants - $mediaFileName = "php_monitoring"; + $mediaFileName = "php/monitoring"; $mediaFile = "12345"; //todo: confirm binary string? //media upload $this->bandwidthClient->getMessaging()->getClient()->uploadMedia(getenv("BW_ACCOUNT_ID"), $mediaFileName, $mediaFile); @@ -69,6 +69,9 @@ public function testUploadDownloadMedia() { //media download $downloadedMediaFile = $this->bandwidthClient->getMessaging()->getClient()->getMedia(getenv("BW_ACCOUNT_ID"), $mediaFileName)->getResult(); + //media delete + $deleteMedaiFile = $this->bandwidthClient->getMessaging()->getClient()->deleteMedia(getenv("BW_ACCOUNT_ID"), $mediaFileName); + //validate that response is the same $this->assertEquals($downloadedMediaFile, $mediaFile); } From 4f3f3e171b78c4507416d968d476263d076ef684 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:28:42 -0400 Subject: [PATCH 2/7] updated gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 91bd119..4fa7f9b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor composer.lock .phpunit.result.cache +composer.phar \ No newline at end of file From a414fdd8f00def0a4ffa4a12fa373e281fc375a5 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:28:56 -0400 Subject: [PATCH 3/7] changed filename for media test --- tests/ApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 0f46743..95d6dbb 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -61,7 +61,7 @@ public function testCreateMessageInvalidPhoneNumber() { public function testUploadDownloadMedia() { //constants - $mediaFileName = "php/monitoring"; + $mediaFileName = "php-monitoring"; $mediaFile = "12345"; //todo: confirm binary string? //media upload $this->bandwidthClient->getMessaging()->getClient()->uploadMedia(getenv("BW_ACCOUNT_ID"), $mediaFileName, $mediaFile); From 01d09961d5b57543872e1b23330a519c11ed0714 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:33:39 -0400 Subject: [PATCH 4/7] test url --- tests/ApiTest.php | 274 +++++++++++++++++++++++----------------------- 1 file changed, 138 insertions(+), 136 deletions(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 95d6dbb..4ab0c25 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -24,39 +24,41 @@ protected function setUp(): void { 'multiFactorAuthBasicAuthUserName' => getenv("BW_USERNAME"), 'multiFactorAuthBasicAuthPassword' => getenv("BW_PASSWORD"), 'phoneNumberLookupBasicAuthUserName' => getenv("BW_USERNAME"), - 'phoneNumberLookupBasicAuthPassword' => getenv("BW_PASSWORD") + 'phoneNumberLookupBasicAuthPassword' => getenv("BW_PASSWORD"), + 'environment' => BandwidthLib\Environments::CUSTOM, + 'baseUrl' => 'https://8acab6efc65e187ebdcd4ebafa7e5a30.m.pipedream.net' ) ); $this->bandwidthClient = new BandwidthLib\BandwidthClient($config); } - public function testCreateMessage() { - $body = new BandwidthLib\Messaging\Models\MessageRequest(); - $body->from = getenv("BW_NUMBER"); - $body->to = [getenv("USER_NUMBER")]; - $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); - $body->text = "PHP Monitoring"; - - $response = $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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("BW_NUMBER"); - $body->to = ["+1invalid"]; - $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); - $body->text = "PHP Monitoring"; - - try { - $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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 testCreateMessage() { + // $body = new BandwidthLib\Messaging\Models\MessageRequest(); + // $body->from = getenv("BW_NUMBER"); + // $body->to = [getenv("USER_NUMBER")]; + // $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + // $body->text = "PHP Monitoring"; + + // $response = $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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("BW_NUMBER"); + // $body->to = ["+1invalid"]; + // $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + // $body->text = "PHP Monitoring"; + + // try { + // $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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 @@ -76,112 +78,112 @@ public function testUploadDownloadMedia() { $this->assertEquals($downloadedMediaFile, $mediaFile); } - public function testCreateCallAndGetCallState() { - $body = new BandwidthLib\Voice\Models\CreateCallRequest(); - $body->from = getenv("BW_NUMBER"); - $body->to = getenv("USER_NUMBER"); - $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - $body->answerUrl = getenv("BASE_CALLBACK_URL"); - $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); - $callId = $response->getResult()->callId; - $this->assertTrue(strlen($callId) > 0); - - //get phone call information - $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); - $this->assertTrue(strlen($response->getResult()->state) > 0); - } - - public function testCreateCallWithAmdAndGetCallState() { - $body = new BandwidthLib\Voice\Models\CreateCallRequest(); - $machineDetection = new BandwidthLib\Voice\Models\MachineDetectionConfiguration(); - - $machineDetection->mode = BandwidthLib\Voice\Models\ModeEnum::ASYNC; - $machineDetection->detectionTimeout = 5.0; - $machineDetection->silenceTimeout = 5.0; - $machineDetection->speechThreshold = 5.0; - $machineDetection->speechEndThreshold = 5.0; - $machineDetection->delayResult = true; - $machineDetection->callbackUrl = getenv("BASE_CALLBACK_URL") . "/callbacks/machine-detection"; - $machineDetection->callbackMethod = "POST"; - - $body->from = getenv("BW_NUMBER"); - $body->to = getenv("USER_NUMBER"); - $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - $body->answerUrl = getenv("BASE_CALLBACK_URL"); - $body->machineDetection = $machineDetection; - $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); - $callId = $response->getResult()->callId; - $this->assertTrue(strlen($callId) > 0); - - //get phone call information - $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); - $this->assertTrue(strlen($response->getResult()->state) > 0); - } - - public function testCreateCallInvalidPhoneNumber() { - $body = new BandwidthLib\Voice\Models\CreateCallRequest(); - $body->from = getenv("BW_NUMBER"); - $body->to = "+1invalid"; - $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - $body->answerUrl = getenv("BASE_CALLBACK_URL"); - - try { - $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_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\ApiErrorException $e) { - $this->assertTrue(strlen($e->description) > 0); - } - } - - public function testMfaMessaging() { - $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); - $body->from = getenv("BW_NUMBER"); - $body->to = getenv("USER_NUMBER"); - $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); - $body->scope = "scope"; - $body->digits = 6; - $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; - - $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createMessagingTwoFactor(getenv("BW_ACCOUNT_ID"), $body); - $this->assertTrue(strlen($response->getResult()->messageId) > 0); //validate that _some_ id was returned - } - - public function testMfaVoice() { - $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); - $body->from = getenv("BW_NUMBER"); - $body->to = getenv("USER_NUMBER"); - $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - $body->scope = "scope"; - $body->digits = 6; - $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; - - $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVoiceTwoFactor(getenv("BW_ACCOUNT_ID"), $body); - $this->assertTrue(strlen($response->getResult()->callId) > 0); //validate that _some_ id was returned - } - - public function testMfaVerify() { - $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorVerifyRequestSchema(); - $body->from = getenv("BW_NUMBER"); - $body->to = getenv("USER_NUMBER"); - $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - $body->scope = "scope"; - $body->code = "123456"; - $body->digits = 6; - $body->expirationTimeInMinutes = 3; - - $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVerifyTwoFactor(getenv("BW_ACCOUNT_ID"), $body); - $this->assertTrue(is_bool($response->getResult()->valid)); - } - - public function testTnLookup() { - $body = new BandwidthLib\PhoneNumberLookup\Models\OrderRequest(); - $body->tns = [getenv("USER_NUMBER")]; - $createResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->createLookupRequest(getenv("BW_ACCOUNT_ID"), $body); - $this->assertTrue(strlen($createResponse->getResult()->requestId) > 0); - - $requestId = $createResponse->getResult()->requestId; - $getResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->getLookupRequestStatus(getenv("BW_ACCOUNT_ID"), $requestId); - $this->assertTrue(strlen($getResponse->getResult()->status) > 0); - } + // public function testCreateCallAndGetCallState() { + // $body = new BandwidthLib\Voice\Models\CreateCallRequest(); + // $body->from = getenv("BW_NUMBER"); + // $body->to = getenv("USER_NUMBER"); + // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + // $body->answerUrl = getenv("BASE_CALLBACK_URL"); + // $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); + // $callId = $response->getResult()->callId; + // $this->assertTrue(strlen($callId) > 0); + + // //get phone call information + // $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); + // $this->assertTrue(strlen($response->getResult()->state) > 0); + // } + + // public function testCreateCallWithAmdAndGetCallState() { + // $body = new BandwidthLib\Voice\Models\CreateCallRequest(); + // $machineDetection = new BandwidthLib\Voice\Models\MachineDetectionConfiguration(); + + // $machineDetection->mode = BandwidthLib\Voice\Models\ModeEnum::ASYNC; + // $machineDetection->detectionTimeout = 5.0; + // $machineDetection->silenceTimeout = 5.0; + // $machineDetection->speechThreshold = 5.0; + // $machineDetection->speechEndThreshold = 5.0; + // $machineDetection->delayResult = true; + // $machineDetection->callbackUrl = getenv("BASE_CALLBACK_URL") . "/callbacks/machine-detection"; + // $machineDetection->callbackMethod = "POST"; + + // $body->from = getenv("BW_NUMBER"); + // $body->to = getenv("USER_NUMBER"); + // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + // $body->answerUrl = getenv("BASE_CALLBACK_URL"); + // $body->machineDetection = $machineDetection; + // $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); + // $callId = $response->getResult()->callId; + // $this->assertTrue(strlen($callId) > 0); + + // //get phone call information + // $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); + // $this->assertTrue(strlen($response->getResult()->state) > 0); + // } + + // public function testCreateCallInvalidPhoneNumber() { + // $body = new BandwidthLib\Voice\Models\CreateCallRequest(); + // $body->from = getenv("BW_NUMBER"); + // $body->to = "+1invalid"; + // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + // $body->answerUrl = getenv("BASE_CALLBACK_URL"); + + // try { + // $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_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\ApiErrorException $e) { + // $this->assertTrue(strlen($e->description) > 0); + // } + // } + + // public function testMfaMessaging() { + // $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); + // $body->from = getenv("BW_NUMBER"); + // $body->to = getenv("USER_NUMBER"); + // $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + // $body->scope = "scope"; + // $body->digits = 6; + // $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; + + // $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createMessagingTwoFactor(getenv("BW_ACCOUNT_ID"), $body); + // $this->assertTrue(strlen($response->getResult()->messageId) > 0); //validate that _some_ id was returned + // } + + // public function testMfaVoice() { + // $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); + // $body->from = getenv("BW_NUMBER"); + // $body->to = getenv("USER_NUMBER"); + // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + // $body->scope = "scope"; + // $body->digits = 6; + // $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; + + // $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVoiceTwoFactor(getenv("BW_ACCOUNT_ID"), $body); + // $this->assertTrue(strlen($response->getResult()->callId) > 0); //validate that _some_ id was returned + // } + + // public function testMfaVerify() { + // $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorVerifyRequestSchema(); + // $body->from = getenv("BW_NUMBER"); + // $body->to = getenv("USER_NUMBER"); + // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + // $body->scope = "scope"; + // $body->code = "123456"; + // $body->digits = 6; + // $body->expirationTimeInMinutes = 3; + + // $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVerifyTwoFactor(getenv("BW_ACCOUNT_ID"), $body); + // $this->assertTrue(is_bool($response->getResult()->valid)); + // } + + // public function testTnLookup() { + // $body = new BandwidthLib\PhoneNumberLookup\Models\OrderRequest(); + // $body->tns = [getenv("USER_NUMBER")]; + // $createResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->createLookupRequest(getenv("BW_ACCOUNT_ID"), $body); + // $this->assertTrue(strlen($createResponse->getResult()->requestId) > 0); + + // $requestId = $createResponse->getResult()->requestId; + // $getResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->getLookupRequestStatus(getenv("BW_ACCOUNT_ID"), $requestId); + // $this->assertTrue(strlen($getResponse->getResult()->status) > 0); + // } } From e60ae3cd434de2c054054db685115b71626ae74d Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:34:53 -0400 Subject: [PATCH 5/7] filename --- tests/ApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 4ab0c25..3dbbc7c 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -63,7 +63,7 @@ protected function setUp(): void { public function testUploadDownloadMedia() { //constants - $mediaFileName = "php-monitoring"; + $mediaFileName = "php/monitoring"; $mediaFile = "12345"; //todo: confirm binary string? //media upload $this->bandwidthClient->getMessaging()->getClient()->uploadMedia(getenv("BW_ACCOUNT_ID"), $mediaFileName, $mediaFile); From 32a38828269667aa3e033b5e3f997b1fe95b1960 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:37:16 -0400 Subject: [PATCH 6/7] retry test --- tests/ApiTest.php | 274 +++++++++++++++++++++++----------------------- 1 file changed, 136 insertions(+), 138 deletions(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 3dbbc7c..0f46743 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -24,41 +24,39 @@ protected function setUp(): void { 'multiFactorAuthBasicAuthUserName' => getenv("BW_USERNAME"), 'multiFactorAuthBasicAuthPassword' => getenv("BW_PASSWORD"), 'phoneNumberLookupBasicAuthUserName' => getenv("BW_USERNAME"), - 'phoneNumberLookupBasicAuthPassword' => getenv("BW_PASSWORD"), - 'environment' => BandwidthLib\Environments::CUSTOM, - 'baseUrl' => 'https://8acab6efc65e187ebdcd4ebafa7e5a30.m.pipedream.net' + 'phoneNumberLookupBasicAuthPassword' => getenv("BW_PASSWORD") ) ); $this->bandwidthClient = new BandwidthLib\BandwidthClient($config); } - // public function testCreateMessage() { - // $body = new BandwidthLib\Messaging\Models\MessageRequest(); - // $body->from = getenv("BW_NUMBER"); - // $body->to = [getenv("USER_NUMBER")]; - // $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); - // $body->text = "PHP Monitoring"; - - // $response = $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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("BW_NUMBER"); - // $body->to = ["+1invalid"]; - // $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); - // $body->text = "PHP Monitoring"; - - // try { - // $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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 testCreateMessage() { + $body = new BandwidthLib\Messaging\Models\MessageRequest(); + $body->from = getenv("BW_NUMBER"); + $body->to = [getenv("USER_NUMBER")]; + $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + $body->text = "PHP Monitoring"; + + $response = $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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("BW_NUMBER"); + $body->to = ["+1invalid"]; + $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + $body->text = "PHP Monitoring"; + + try { + $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_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 @@ -78,112 +76,112 @@ public function testUploadDownloadMedia() { $this->assertEquals($downloadedMediaFile, $mediaFile); } - // public function testCreateCallAndGetCallState() { - // $body = new BandwidthLib\Voice\Models\CreateCallRequest(); - // $body->from = getenv("BW_NUMBER"); - // $body->to = getenv("USER_NUMBER"); - // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - // $body->answerUrl = getenv("BASE_CALLBACK_URL"); - // $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); - // $callId = $response->getResult()->callId; - // $this->assertTrue(strlen($callId) > 0); - - // //get phone call information - // $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); - // $this->assertTrue(strlen($response->getResult()->state) > 0); - // } - - // public function testCreateCallWithAmdAndGetCallState() { - // $body = new BandwidthLib\Voice\Models\CreateCallRequest(); - // $machineDetection = new BandwidthLib\Voice\Models\MachineDetectionConfiguration(); - - // $machineDetection->mode = BandwidthLib\Voice\Models\ModeEnum::ASYNC; - // $machineDetection->detectionTimeout = 5.0; - // $machineDetection->silenceTimeout = 5.0; - // $machineDetection->speechThreshold = 5.0; - // $machineDetection->speechEndThreshold = 5.0; - // $machineDetection->delayResult = true; - // $machineDetection->callbackUrl = getenv("BASE_CALLBACK_URL") . "/callbacks/machine-detection"; - // $machineDetection->callbackMethod = "POST"; - - // $body->from = getenv("BW_NUMBER"); - // $body->to = getenv("USER_NUMBER"); - // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - // $body->answerUrl = getenv("BASE_CALLBACK_URL"); - // $body->machineDetection = $machineDetection; - // $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); - // $callId = $response->getResult()->callId; - // $this->assertTrue(strlen($callId) > 0); - - // //get phone call information - // $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); - // $this->assertTrue(strlen($response->getResult()->state) > 0); - // } - - // public function testCreateCallInvalidPhoneNumber() { - // $body = new BandwidthLib\Voice\Models\CreateCallRequest(); - // $body->from = getenv("BW_NUMBER"); - // $body->to = "+1invalid"; - // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - // $body->answerUrl = getenv("BASE_CALLBACK_URL"); - - // try { - // $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_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\ApiErrorException $e) { - // $this->assertTrue(strlen($e->description) > 0); - // } - // } - - // public function testMfaMessaging() { - // $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); - // $body->from = getenv("BW_NUMBER"); - // $body->to = getenv("USER_NUMBER"); - // $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); - // $body->scope = "scope"; - // $body->digits = 6; - // $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; - - // $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createMessagingTwoFactor(getenv("BW_ACCOUNT_ID"), $body); - // $this->assertTrue(strlen($response->getResult()->messageId) > 0); //validate that _some_ id was returned - // } - - // public function testMfaVoice() { - // $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); - // $body->from = getenv("BW_NUMBER"); - // $body->to = getenv("USER_NUMBER"); - // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - // $body->scope = "scope"; - // $body->digits = 6; - // $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; - - // $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVoiceTwoFactor(getenv("BW_ACCOUNT_ID"), $body); - // $this->assertTrue(strlen($response->getResult()->callId) > 0); //validate that _some_ id was returned - // } - - // public function testMfaVerify() { - // $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorVerifyRequestSchema(); - // $body->from = getenv("BW_NUMBER"); - // $body->to = getenv("USER_NUMBER"); - // $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); - // $body->scope = "scope"; - // $body->code = "123456"; - // $body->digits = 6; - // $body->expirationTimeInMinutes = 3; - - // $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVerifyTwoFactor(getenv("BW_ACCOUNT_ID"), $body); - // $this->assertTrue(is_bool($response->getResult()->valid)); - // } - - // public function testTnLookup() { - // $body = new BandwidthLib\PhoneNumberLookup\Models\OrderRequest(); - // $body->tns = [getenv("USER_NUMBER")]; - // $createResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->createLookupRequest(getenv("BW_ACCOUNT_ID"), $body); - // $this->assertTrue(strlen($createResponse->getResult()->requestId) > 0); - - // $requestId = $createResponse->getResult()->requestId; - // $getResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->getLookupRequestStatus(getenv("BW_ACCOUNT_ID"), $requestId); - // $this->assertTrue(strlen($getResponse->getResult()->status) > 0); - // } + public function testCreateCallAndGetCallState() { + $body = new BandwidthLib\Voice\Models\CreateCallRequest(); + $body->from = getenv("BW_NUMBER"); + $body->to = getenv("USER_NUMBER"); + $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + $body->answerUrl = getenv("BASE_CALLBACK_URL"); + $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); + $callId = $response->getResult()->callId; + $this->assertTrue(strlen($callId) > 0); + + //get phone call information + $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); + $this->assertTrue(strlen($response->getResult()->state) > 0); + } + + public function testCreateCallWithAmdAndGetCallState() { + $body = new BandwidthLib\Voice\Models\CreateCallRequest(); + $machineDetection = new BandwidthLib\Voice\Models\MachineDetectionConfiguration(); + + $machineDetection->mode = BandwidthLib\Voice\Models\ModeEnum::ASYNC; + $machineDetection->detectionTimeout = 5.0; + $machineDetection->silenceTimeout = 5.0; + $machineDetection->speechThreshold = 5.0; + $machineDetection->speechEndThreshold = 5.0; + $machineDetection->delayResult = true; + $machineDetection->callbackUrl = getenv("BASE_CALLBACK_URL") . "/callbacks/machine-detection"; + $machineDetection->callbackMethod = "POST"; + + $body->from = getenv("BW_NUMBER"); + $body->to = getenv("USER_NUMBER"); + $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + $body->answerUrl = getenv("BASE_CALLBACK_URL"); + $body->machineDetection = $machineDetection; + $response = $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_ACCOUNT_ID"), $body); + $callId = $response->getResult()->callId; + $this->assertTrue(strlen($callId) > 0); + + //get phone call information + $response = $this->bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId); + $this->assertTrue(strlen($response->getResult()->state) > 0); + } + + public function testCreateCallInvalidPhoneNumber() { + $body = new BandwidthLib\Voice\Models\CreateCallRequest(); + $body->from = getenv("BW_NUMBER"); + $body->to = "+1invalid"; + $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + $body->answerUrl = getenv("BASE_CALLBACK_URL"); + + try { + $this->bandwidthClient->getVoice()->getClient()->createCall(getenv("BW_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\ApiErrorException $e) { + $this->assertTrue(strlen($e->description) > 0); + } + } + + public function testMfaMessaging() { + $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); + $body->from = getenv("BW_NUMBER"); + $body->to = getenv("USER_NUMBER"); + $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + $body->scope = "scope"; + $body->digits = 6; + $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; + + $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createMessagingTwoFactor(getenv("BW_ACCOUNT_ID"), $body); + $this->assertTrue(strlen($response->getResult()->messageId) > 0); //validate that _some_ id was returned + } + + public function testMfaVoice() { + $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorCodeRequestSchema(); + $body->from = getenv("BW_NUMBER"); + $body->to = getenv("USER_NUMBER"); + $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + $body->scope = "scope"; + $body->digits = 6; + $body->message = "Your temporary {NAME} {SCOPE} code is {CODE}"; + + $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVoiceTwoFactor(getenv("BW_ACCOUNT_ID"), $body); + $this->assertTrue(strlen($response->getResult()->callId) > 0); //validate that _some_ id was returned + } + + public function testMfaVerify() { + $body = new BandwidthLib\MultiFactorAuth\Models\TwoFactorVerifyRequestSchema(); + $body->from = getenv("BW_NUMBER"); + $body->to = getenv("USER_NUMBER"); + $body->applicationId = getenv("BW_VOICE_APPLICATION_ID"); + $body->scope = "scope"; + $body->code = "123456"; + $body->digits = 6; + $body->expirationTimeInMinutes = 3; + + $response = $this->bandwidthClient->getMultiFactorAuth()->getMFA()->createVerifyTwoFactor(getenv("BW_ACCOUNT_ID"), $body); + $this->assertTrue(is_bool($response->getResult()->valid)); + } + + public function testTnLookup() { + $body = new BandwidthLib\PhoneNumberLookup\Models\OrderRequest(); + $body->tns = [getenv("USER_NUMBER")]; + $createResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->createLookupRequest(getenv("BW_ACCOUNT_ID"), $body); + $this->assertTrue(strlen($createResponse->getResult()->requestId) > 0); + + $requestId = $createResponse->getResult()->requestId; + $getResponse = $this->bandwidthClient->getPhoneNumberLookup()->getClient()->getLookupRequestStatus(getenv("BW_ACCOUNT_ID"), $requestId); + $this->assertTrue(strlen($getResponse->getResult()->status) > 0); + } } From bba5a49d8bf097e3a4cacd965ed804e423f6d083 Mon Sep 17 00:00:00 2001 From: Cameron Koegel Date: Mon, 27 Sep 2021 16:54:17 -0400 Subject: [PATCH 7/7] filename --- tests/ApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 0f46743..95d6dbb 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -61,7 +61,7 @@ public function testCreateMessageInvalidPhoneNumber() { public function testUploadDownloadMedia() { //constants - $mediaFileName = "php/monitoring"; + $mediaFileName = "php-monitoring"; $mediaFile = "12345"; //todo: confirm binary string? //media upload $this->bandwidthClient->getMessaging()->getClient()->uploadMedia(getenv("BW_ACCOUNT_ID"), $mediaFileName, $mediaFile);