1212
1313final class ApiTest extends TestCase
1414{
15- protected $ bandwidthClient ;
15+ protected static $ bandwidthClient ;
16+ protected static $ messagingMFAClient ;
1617
17- protected function setUp (): void {
18+ public static function setUpBeforeClass (): void {
1819 $ config = new BandwidthLib \Configuration (
1920 array (
20- 'messagingBasicAuthUserName ' => getenv ("BW_USERNAME " ),
21- 'messagingBasicAuthPassword ' => getenv ("BW_PASSWORD " ),
2221 'voiceBasicAuthUserName ' => getenv ("BW_USERNAME " ),
2322 'voiceBasicAuthPassword ' => getenv ("BW_PASSWORD " ),
23+ 'phoneNumberLookupBasicAuthUserName ' => getenv ("BW_USERNAME " ),
24+ 'phoneNumberLookupBasicAuthPassword ' => getenv ("BW_PASSWORD " ),
25+ 'clientId ' => getenv ("BW_CLIENT_ID " ),
26+ 'clientSecret ' => getenv ("BW_CLIENT_SECRET " ),
27+ )
28+ );
29+ self ::$ bandwidthClient = new BandwidthLib \BandwidthClient ($ config );
30+
31+ $ messagingMFAConfig = new BandwidthLib \Configuration (
32+ array (
33+ 'messagingBasicAuthUserName ' => getenv ("BW_USERNAME " ),
34+ 'messagingBasicAuthPassword ' => getenv ("BW_PASSWORD " ),
2435 'multiFactorAuthBasicAuthUserName ' => getenv ("BW_USERNAME " ),
2536 'multiFactorAuthBasicAuthPassword ' => getenv ("BW_PASSWORD " ),
26- 'phoneNumberLookupBasicAuthUserName ' => getenv ("BW_USERNAME " ),
27- 'phoneNumberLookupBasicAuthPassword ' => getenv ("BW_PASSWORD " )
2837 )
2938 );
30- $ this -> bandwidthClient = new BandwidthLib \BandwidthClient ($ config );
39+ self :: $ messagingMFAClient = new BandwidthLib \BandwidthClient ($ messagingMFAConfig );
3140 }
3241
3342 public function testCreateMessage () {
@@ -37,7 +46,7 @@ public function testCreateMessage() {
3746 $ body ->applicationId = getenv ("BW_MESSAGING_APPLICATION_ID " );
3847 $ body ->text = "PHP Monitoring " ;
3948
40- $ response = $ this -> bandwidthClient ->getMessaging ()->getClient ()->createMessage (getenv ("BW_ACCOUNT_ID " ), $ body );
49+ $ response = self :: $ messagingMFAClient ->getMessaging ()->getClient ()->createMessage (getenv ("BW_ACCOUNT_ID " ), $ body );
4150
4251 $ this ->assertTrue (strlen ($ response ->getResult ()->id ) > 0 ); //validate that _some_ id was returned
4352 }
@@ -50,7 +59,7 @@ public function testCreateMessageInvalidPhoneNumber() {
5059 $ body ->text = "PHP Monitoring " ;
5160
5261 try {
53- $ this -> bandwidthClient ->getMessaging ()->getClient ()->createMessage (getenv ("BW_ACCOUNT_ID " ), $ body );
62+ self :: $ messagingMFAClient ->getMessaging ()->getClient ()->createMessage (getenv ("BW_ACCOUNT_ID " ), $ body );
5463 //workaround to make sure that if the above error is not raised, the build will fail
5564 $ this ->assertTrue (false );
5665 } catch (BandwidthLib \Messaging \Exceptions \MessagingException $ e ) {
@@ -65,13 +74,13 @@ public function testUploadDownloadMedia() {
6574 $ contentType = 'text/plain ' ;
6675
6776 //media upload
68- $ this -> bandwidthClient ->getMessaging ()->getClient ()->uploadMedia (getenv ("BW_ACCOUNT_ID " ), $ mediaId , $ content , $ contentType );
77+ self :: $ messagingMFAClient ->getMessaging ()->getClient ()->uploadMedia (getenv ("BW_ACCOUNT_ID " ), $ mediaId , $ content , $ contentType );
6978
7079 //media download
71- $ downloadedContent = $ this -> bandwidthClient ->getMessaging ()->getClient ()->getMedia (getenv ("BW_ACCOUNT_ID " ), $ mediaId )->getResult ();
80+ $ downloadedContent = self :: $ messagingMFAClient ->getMessaging ()->getClient ()->getMedia (getenv ("BW_ACCOUNT_ID " ), $ mediaId )->getResult ();
7281
7382 //media delete
74- $ this -> bandwidthClient ->getMessaging ()->getClient ()->deleteMedia (getenv ("BW_ACCOUNT_ID " ), $ mediaId );
83+ self :: $ messagingMFAClient ->getMessaging ()->getClient ()->deleteMedia (getenv ("BW_ACCOUNT_ID " ), $ mediaId );
7584
7685 //validate that response is the same
7786 $ this ->assertEquals ($ downloadedContent , $ content );
@@ -83,13 +92,13 @@ public function testCreateCallAndGetCallState() {
8392 $ body ->to = getenv ("USER_NUMBER " );
8493 $ body ->applicationId = getenv ("BW_VOICE_APPLICATION_ID " );
8594 $ body ->answerUrl = getenv ("BASE_CALLBACK_URL " );
86- $ response = $ this -> bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
95+ $ response = self :: $ bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
8796 $ callId = $ response ->getResult ()->callId ;
8897 $ this ->assertTrue (strlen ($ callId ) > 0 );
8998 $ this ->assertTrue (is_a ($ response ->getResult ()->enqueuedTime , 'DateTime ' ));
9099
91100 //get phone call information (This is commented out until voice fixes their latency issues
92- // $response = $this-> bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId);
101+ // $response = self::$ bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId);
93102 // $this->assertTrue(is_a($response->getResult()->enqueuedTime, 'DateTime'));
94103
95104 }
@@ -113,14 +122,14 @@ public function testCreateCallWithAmdAndGetCallState() {
113122 $ body ->applicationId = getenv ("BW_VOICE_APPLICATION_ID " );
114123 $ body ->answerUrl = getenv ("BASE_CALLBACK_URL " );
115124 $ body ->machineDetection = $ machineDetection ;
116- $ response = $ this -> bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
125+ $ response = self :: $ bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
117126 $ callId = $ response ->getResult ()->callId ;
118127 $ this ->assertTrue (strlen ($ callId ) > 0 );
119128
120129 sleep (25 );
121130
122131 //get phone call information
123- // $response = $this-> bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId);
132+ // $response = self::$ bandwidthClient->getVoice()->getClient()->getCall(getenv("BW_ACCOUNT_ID"), $callId);
124133 // if (($response->getStatus() == 404) ) {
125134 // $this->assertTrue(is_a($response->getResult()->enqueuedTime, 'DateTime'));
126135 // }
@@ -132,7 +141,7 @@ public function testCreateCallWithPriority() {
132141 $ body ->applicationId = getenv ("BW_VOICE_APPLICATION_ID " );
133142 $ body ->answerUrl = getenv ("BASE_CALLBACK_URL " );
134143 $ body ->priority = 1 ;
135- $ response = $ this -> bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
144+ $ response = self :: $ bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
136145 $ callId = $ response ->getResult ()->callId ;
137146 $ this ->assertTrue (strlen ($ callId ) > 0 );
138147 $ this ->assertTrue ($ response ->getResult ()->priority == $ body ->priority );
@@ -146,7 +155,7 @@ public function testCreateCallInvalidPhoneNumber() {
146155 $ body ->answerUrl = getenv ("BASE_CALLBACK_URL " );
147156
148157 try {
149- $ this -> bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
158+ self :: $ bandwidthClient ->getVoice ()->getClient ()->createCall (getenv ("BW_ACCOUNT_ID " ), $ body );
150159 //workaround to make sure that if the above error is not raised, the build will fail
151160 $ this ->assertTrue (false );
152161 } catch (BandwidthLib \Voice \Exceptions \ApiErrorException $ e ) {
@@ -163,7 +172,7 @@ public function testMfaMessaging() {
163172 $ body ->digits = 6 ;
164173 $ body ->message = "Your temporary {NAME} {SCOPE} code is {CODE} " ;
165174
166- $ response = $ this -> bandwidthClient ->getMultiFactorAuth ()->getMFA ()->createMessagingTwoFactor (getenv ("BW_ACCOUNT_ID " ), $ body );
175+ $ response = self :: $ messagingMFAClient ->getMultiFactorAuth ()->getMFA ()->createMessagingTwoFactor (getenv ("BW_ACCOUNT_ID " ), $ body );
167176 $ this ->assertTrue (strlen ($ response ->getResult ()->messageId ) > 0 ); //validate that _some_ id was returned
168177 }
169178
@@ -176,7 +185,7 @@ public function testMfaVoice() {
176185 $ body ->digits = 6 ;
177186 $ body ->message = "Your temporary {NAME} {SCOPE} code is {CODE} " ;
178187
179- $ response = $ this -> bandwidthClient ->getMultiFactorAuth ()->getMFA ()->createVoiceTwoFactor (getenv ("BW_ACCOUNT_ID " ), $ body );
188+ $ response = self :: $ messagingMFAClient ->getMultiFactorAuth ()->getMFA ()->createVoiceTwoFactor (getenv ("BW_ACCOUNT_ID " ), $ body );
180189 $ this ->assertTrue (strlen ($ response ->getResult ()->callId ) > 0 ); //validate that _some_ id was returned
181190 }
182191
@@ -189,14 +198,14 @@ public function testMfaVerify() {
189198 $ body ->digits = 6 ;
190199 $ body ->expirationTimeInMinutes = 3 ;
191200
192- $ response = $ this -> bandwidthClient ->getMultiFactorAuth ()->getMFA ()->createVerifyTwoFactor (getenv ("BW_ACCOUNT_ID " ), $ body );
201+ $ response = self :: $ messagingMFAClient ->getMultiFactorAuth ()->getMFA ()->createVerifyTwoFactor (getenv ("BW_ACCOUNT_ID " ), $ body );
193202 $ this ->assertTrue (is_bool ($ response ->getResult ()->valid ));
194203 }
195204
196205 public function testAsyncTnLookup () {
197206 $ body = new BandwidthLib \PhoneNumberLookup \Models \CreateLookupRequest ();
198207 $ body ->phoneNumbers = [getenv ("USER_NUMBER " )];
199- $ createResponse = $ this -> bandwidthClient ->getPhoneNumberLookup ()->getClient ()->createAsyncBulkLookupRequest (getenv ("BW_ACCOUNT_ID " ), $ body );
208+ $ createResponse = self :: $ bandwidthClient ->getPhoneNumberLookup ()->getClient ()->createAsyncBulkLookupRequest (getenv ("BW_ACCOUNT_ID " ), $ body );
200209 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \CreateAsyncBulkResponse::class, $ createResponse ->getResult ());
201210 $ this ->assertIsArray ($ createResponse ->getResult ()->links );
202211 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \CreateAsyncBulkResponseData::class, $ createResponse ->getResult ()->data );
@@ -206,7 +215,7 @@ public function testAsyncTnLookup() {
206215
207216 sleep (30 );
208217
209- $ statusResponse = $ this -> bandwidthClient ->getPhoneNumberLookup ()->getClient ()->getAsyncLookupRequestStatus (getenv ("BW_ACCOUNT_ID " ), $ createResponse ->getResult ()->data ->requestId );
218+ $ statusResponse = self :: $ bandwidthClient ->getPhoneNumberLookup ()->getClient ()->getAsyncLookupRequestStatus (getenv ("BW_ACCOUNT_ID " ), $ createResponse ->getResult ()->data ->requestId );
210219 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \LookupResponse::class, $ statusResponse ->getResult ());
211220 $ this ->assertIsArray ($ statusResponse ->getResult ()->links );
212221 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \LookupResponseData::class, $ statusResponse ->getResult ()->data );
@@ -225,7 +234,7 @@ public function testAsyncTnLookup() {
225234 public function testSyncTnLookup () {
226235 $ body = new BandwidthLib \PhoneNumberLookup \Models \CreateLookupRequest ();
227236 $ body ->phoneNumbers = [getenv ("USER_NUMBER " )];
228- $ response = $ this -> bandwidthClient ->getPhoneNumberLookup ()->getClient ()->createSyncLookupRequest (getenv ("BW_ACCOUNT_ID " ), $ body );
237+ $ response = self :: $ bandwidthClient ->getPhoneNumberLookup ()->getClient ()->createSyncLookupRequest (getenv ("BW_ACCOUNT_ID " ), $ body );
229238 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \LookupResponse::class, $ response ->getResult ());
230239 $ this ->assertIsArray ($ response ->getResult ()->links );
231240 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \Link::class, $ response ->getResult ()->links [0 ]);
@@ -237,7 +246,7 @@ public function testSyncTnLookup() {
237246 $ this ->assertInstanceOf (BandwidthLib \PhoneNumberLookup \Models \LookupResult::class, $ response ->getResult ()->data ->results [0 ]);
238247 $ this ->assertIsString ($ response ->getResult ()->data ->results [0 ]->phoneNumber );
239248 $ this ->assertIsString ($ response ->getResult ()->data ->results [0 ]->lineType );
240- $ this ->assertIsString ($ response ->getResult ()->data ->results [0 ]->messagingProvider );
249+ // $this->assertIsString($response->getResult()->data->results[0]->messagingProvider);
241250 $ this ->assertIsString ($ response ->getResult ()->data ->results [0 ]->voiceProvider );
242251 $ this ->assertIsString ($ response ->getResult ()->data ->results [0 ]->countryCodeA3 );
243252 $ this ->assertIsArray ($ response ->getResult ()->errors );
0 commit comments