File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 28
28
*/
29
29
class Client
30
30
{
31
+ const VERSION = '1.0.0-beta1 ' ;
32
+
31
33
const BASE_API = 'https://api.nexmo.com ' ;
32
34
const BASE_REST = 'https://rest.nexmo.com ' ;
33
35
34
-
35
36
/**
36
37
* API Credentials
37
38
* @var CredentialsInterface
@@ -221,6 +222,13 @@ public function send(\Psr\Http\Message\RequestInterface $request)
221
222
}
222
223
}
223
224
225
+ //set the user-agent
226
+ $ request = $ request ->withHeader ('user-agent ' , implode ('/ ' , [
227
+ 'nexmo-php ' ,
228
+ self ::VERSION ,
229
+ 'PHP- ' . implode ('. ' , [PHP_MAJOR_VERSION , PHP_MINOR_VERSION ])
230
+ ]));
231
+
224
232
$ response = $ this ->client ->sendRequest ($ request );
225
233
return $ response ;
226
234
}
Original file line number Diff line number Diff line change @@ -239,6 +239,36 @@ public function testNamespaceFactory()
239
239
$ this ->assertSame ($ api , $ client ->sms ());
240
240
}
241
241
242
+ public function testUserAgentString ()
243
+ {
244
+ $ version = Client::VERSION ;
245
+ $ php = 'PHP- ' . implode ('. ' , [
246
+ PHP_MAJOR_VERSION ,
247
+ PHP_MINOR_VERSION
248
+ ]);
249
+
250
+ //get a mock response to test
251
+ $ response = new Response ();
252
+ $ response ->getBody ()->write ('test response ' );
253
+ $ this ->http ->addResponse ($ response );
254
+
255
+ $ client = new Client (new Basic ('key ' , 'secret ' ), [], $ this ->http );
256
+ $ request = $ this ->getRequest ();
257
+
258
+ //api client should simply pass back the http response
259
+ $ client ->send ($ request );
260
+
261
+ //useragent should match the expected format
262
+ $ agent = $ this ->http ->getRequests ()[0 ]->getHeaderLine ('user-agent ' );
263
+ $ expected = implode ('/ ' , [
264
+ 'nexmo-php ' ,
265
+ $ version ,
266
+ $ php
267
+ ]);
268
+
269
+ $ this ->assertEquals ($ expected , $ agent );
270
+ }
271
+
242
272
/**
243
273
* Allow tests to check that the API client is correctly forming the HTTP request before sending it to the HTTP
244
274
* client.
You can’t perform that action at this time.
0 commit comments