-
Notifications
You must be signed in to change notification settings - Fork 13
/
AuthTest.php
73 lines (61 loc) · 1.95 KB
/
AuthTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Choccybiccy\HumanApi;
use Choccybiccy\HumanApi\Traits\ReflectionMethods;
/**
* Class AuthTest
* @package Choccybiccy\HumanApi
*/
class AuthTest extends \PHPUnit_Framework_TestCase
{
use ReflectionMethods;
/**
* Get mock response
*
* @param int $statusCode Response status code
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getMockResponse($statusCode = 204)
{
$response = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')
->disableOriginalConstructor()
->setMethods(array("getBody", "getStatusCode", "getReasonPhrase"))
->getMockForAbstractClass();
$response->expects($this->any())
->method("getBody")
->willReturn(json_encode(array()));
$response->expects($this->any())
->method("getStatusCode")
->willReturn($statusCode);
return $response;
}
/**
* Test auth
*/
public function testAuth()
{
$sessionTokenData = array(
"humanId" => "exampleHumanId",
"clientId" => "exampleClientId",
"sessionToken" => "exampleSessionToken",
);
$clientSecret = "exampleClientSecret";
$auth = $this->getMockBuilder("Choccybiccy\\HumanApi\\Auth")
->setConstructorArgs(array($sessionTokenData, $clientSecret))
->setMethods(array("post"))
->getMock();
$auth->expects($this->once())
->method("post")
->with(
$this->runProtectedMethod(
$auth,
"buildUrlParts",
array(array("tokens"), "connect")
),
array(
"json" => array_merge($sessionTokenData, array("clientSecret" => $clientSecret)),
)
)
->willReturn($this->getMockResponse());
$auth->finish();
}
}