File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
Client/Credentials/Handler
Client/Credentials/Handler Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1414use Psr \Container \ContainerInterface ;
1515use Vonage \Client \APIResource ;
1616use Vonage \Client \Credentials \Handler \BasicHandler ;
17+ use Vonage \Client \Credentials \Handler \BasicQueryHandler ;
1718
1819class ClientFactory
1920{
@@ -25,7 +26,7 @@ public function __invoke(ContainerInterface $container): Client
2526 ->setBaseUrl ($ accountApi ->getClient ()->getRestUrl ())
2627 ->setIsHAL (false )
2728 ->setBaseUri ('/account ' )
28- ->setAuthHandler (new BasicHandler ())
29+ ->setAuthHandler (new BasicQueryHandler ())
2930 ;
3031
3132 return new Client ($ accountApi );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Vonage \Client \Credentials \Handler ;
4+
5+ use Psr \Http \Message \RequestInterface ;
6+ use Vonage \Client \Credentials \Basic ;
7+ use Vonage \Client \Credentials \CredentialsInterface ;
8+
9+ class BasicQueryHandler extends AbstractHandler
10+ {
11+ public function __invoke (RequestInterface $ request , CredentialsInterface $ credentials ): RequestInterface
12+ {
13+ $ credentials = $ this ->extract (Basic::class, $ credentials );
14+
15+ return $ request ->withUri ($ request ->getUri ()->withQuery (http_build_query ($ credentials ->asArray ())));
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ public function setUp(): void
5656 $ this ->api = new APIResource ();
5757 $ this ->api ->setBaseUrl ('https://rest.nexmo.com ' )
5858 ->setIsHAL (false )
59+ ->setAuthHandler (new Client \Credentials \Handler \BasicQueryHandler ())
5960 ->setBaseUri ('/account ' );
6061
6162 $ this ->api ->setClient ($ this ->vonageClient ->reveal ());
@@ -163,6 +164,10 @@ public function testGetBalance(): void
163164 $ this ->assertEquals ('rest.nexmo.com ' , $ request ->getUri ()->getHost ());
164165 $ this ->assertEquals ('GET ' , $ request ->getMethod ());
165166
167+ $ uri = $ request ->getUri ();
168+ $ uriString = $ uri ->__toString ();
169+ $ this ->assertEquals ('https://rest.nexmo.com/account/get-balance?api_key=abc&api_secret=def ' , $ uriString );
170+
166171 return true ;
167172 }))->shouldBeCalledTimes (1 )->willReturn ($ this ->getResponse ('get-balance ' ));
168173
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace VonageTest \Client \Credentials \Handler ;
4+
5+ use Laminas \Diactoros \Request ;
6+ use Vonage \Client \Credentials \Basic ;
7+ use Vonage \Client \Credentials \Handler \BasicQueryHandler ;
8+ use PHPUnit \Framework \TestCase ;
9+
10+ class BasicQueryHandlerTest extends TestCase
11+ {
12+ public function testWillAddCredentialsToRequest (): void
13+ {
14+ $ request = new Request ('https://example.com ' );
15+ $ credentials = new Basic ('abc ' , 'xyz ' );
16+ $ handler = new BasicQueryHandler ();
17+ $ request = $ handler ($ request , $ credentials );
18+
19+ $ uri = $ request ->getUri ();
20+ $ uriString = $ uri ->__toString ();
21+ $ this ->assertEquals ('https://example.com?api_key=abc&api_secret=xyz ' , $ uriString );
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments