From 7518da1fed1faebcc9cb6485b9c5c7545c90d215 Mon Sep 17 00:00:00 2001 From: PGBI Date: Wed, 3 Aug 2016 14:32:08 +0200 Subject: [PATCH] Client::testNewMemberSessionFromCredentials() can accept custom parameters --- src/Client.php | 26 ++++++++++++++------------ tests/ClientTest.php | 12 +++++++++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Client.php b/src/Client.php index e197b21..1aaf062 100644 --- a/src/Client.php +++ b/src/Client.php @@ -121,23 +121,25 @@ public function newMemberSessionFromCode($code) } /** - * @param $username - * @param $password + * @param array $params * @return Session|null */ - public function newMemberSessionFromCredentials($username, $password) + public function newMemberSessionFromCredentials(array $params = []) { + $params += [ + 'username' => null, + 'password' => null, + ]; + $ips = $this->getClientIps(); + $params = array_merge($params, [ + 'grant_type' => 'password', + 'client_id' => $this->client_id, + 'client_secret' => $this->client_secret, + 'ip' => empty($ips) ? null : implode(', ', $ips), + ]); try { - $ips = $this->getClientIps(); $response = $this->request('POST', '/oauth2/auth', null, [ - 'form_params' => [ - 'grant_type' => 'password', - 'client_id' => $this->client_id, - 'client_secret' => $this->client_secret, - 'username' => $username, - 'password' => $password, - 'ip' => empty($ips) ? null : implode(', ', $ips), - ] + 'form_params' => $params ]); } catch (APIResponseException $e) { $response = $e->getResponseData(); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index a1db703..4afec97 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -107,18 +107,24 @@ public function testNewMemberSessionFromCredentials() $this->guzzleMock->shouldReceive('request') ->once() ->with('POST', '/oauth2/auth', Mockery::on(function($args) { - return $args['form_params'] === [ + $this->assertEquals([ 'grant_type' => 'password', 'client_id' => '123', 'client_secret' => '456', 'username' => 'email@domain.tld', 'password' => 'pass', 'ip' => null, - ]; + 'foo' => 'bar', + ], $args['form_params']); + return true; })) ->andReturn(new Response(200, [], "{}")); - $session = $this->client->newMemberSessionFromCredentials("email@domain.tld", "pass"); + $session = $this->client->newMemberSessionFromCredentials([ + 'username' => 'email@domain.tld', + 'password' => 'pass', + 'foo' => 'bar', + ]); $this->assertInstanceOf(Session::class, $session); }