From 074c0ad0cf0a1fd724cd92e9e79f3a0885b1fc31 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Thu, 7 Oct 2021 16:02:50 -0400 Subject: [PATCH] Update Create Messaging Tests --- .gitignore | 3 ++- tests/ApiTest.php | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 4fa7f9b..9563a4b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ vendor composer.lock .phpunit.result.cache -composer.phar \ No newline at end of file +composer.phar +.idea/ diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 9554a96..8661cb3 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -13,6 +13,11 @@ final class ApiTest extends TestCase { protected $bandwidthClient; + protected $bwNumber; + protected $userNumber; + protected $bwMessagingApplicationId; + protected $bwVoiceApplicationId; + protected $baseCallbackUrl; protected function setUp(): void { $config = new BandwidthLib\Configuration( @@ -28,33 +33,45 @@ protected function setUp(): void { ) ); $this->bandwidthClient = new BandwidthLib\BandwidthClient($config); + $this->bwNumber = getenv("BW_NUMBER"); + $this->userNumber = getenv("USER_NUMBER"); + $this->bwMessagingApplicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + $this->bwVoiceApplicationId = getenv("BW_VOICE_APPLICATION_ID"); + $this->baseCallbackUrl = getenv("BASE_CALLBACK_URL"); } - public function testCreateMessage() { + public function testSuccessfulCreateMessage() { $body = new BandwidthLib\Messaging\Models\MessageRequest(); - $body->from = getenv("BW_NUMBER"); - $body->to = [getenv("USER_NUMBER")]; - $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + $body->from = $this->bwNumber; + $body->to = [$this->userNumber]; + $body->applicationId = $this->bwMessagingApplicationId; $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 + $this->assertTrue($response->getStatusCode() == 202); + $this->assertTrue(strlen($response->getResult()->id) == 29); + $this->assertTrue($response->getResult()->owner == $this->bwNumber); + $this->assertTrue($response->getResult()->to == [$this->userNumber]); + $this->assertTrue($response->getResult()->applicationId == $this->bwMessagingApplicationId); + $dt = new DateTime($response->getResult()->time); // assigns the time to a datetime object - if this fails then time is not a valid datetime + $this->assertIsNumeric($response->getResult()->segmentCount); } - public function testCreateMessageInvalidPhoneNumber() { + public function testFailedCreateMessage() { $body = new BandwidthLib\Messaging\Models\MessageRequest(); - $body->from = getenv("BW_NUMBER"); + $body->from = $this->bwNumber; $body->to = ["+1invalid"]; - $body->applicationId = getenv("BW_MESSAGING_APPLICATION_ID"); + $body->applicationId = $this->bwMessagingApplicationId; $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 + $response = $this->bandwidthClient->getMessaging()->getClient()->createMessage(getenv("BW_ACCOUNT_ID"), $body); + //workaround to make sure that if the error is not raised, the build will fail $this->assertTrue(false); } catch (BandwidthLib\Messaging\Exceptions\MessagingException $e) { - $this->assertTrue(strlen($e->description) > 0); + $this->assertTrue($e->type == "request-validation"); + $this->assertIsString($e->description); } }