Skip to content

Commit

Permalink
Client::testNewMemberSessionFromCredentials() can accept custom param…
Browse files Browse the repository at this point in the history
…eters
  • Loading branch information
PGBI committed Aug 3, 2016
1 parent 5ef8587 commit 7518da1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
26 changes: 14 additions & 12 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 9 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]',
'password' => 'pass',
'ip' => null,
];
'foo' => 'bar',
], $args['form_params']);
return true;
}))
->andReturn(new Response(200, [], "{}"));

$session = $this->client->newMemberSessionFromCredentials("[email protected]", "pass");
$session = $this->client->newMemberSessionFromCredentials([
'username' => '[email protected]',
'password' => 'pass',
'foo' => 'bar',
]);
$this->assertInstanceOf(Session::class, $session);
}

Expand Down

0 comments on commit 7518da1

Please sign in to comment.