Skip to content

Commit 283d4a9

Browse files
committed
Fix tests for AuthListener
Fix filename of the `ErrorListenerTest` Fix `ErrorListenerTest` for php 5.4+
1 parent 161335d commit 283d4a9

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

test/Github/Tests/HttpClient/Listener/AuthListenerTest.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function shouldDoNothingForHaveNullMethod()
6868
->method('getUrl');
6969

7070
$listener = new AuthListener(null, array('password' => 'pass', 'tokenOrLogin' => 'test'));
71-
$this->assertNull($listener->preSend($request));
71+
$listener->preSend($request);
7272
}
7373

7474
/**
@@ -99,35 +99,51 @@ public function shouldDoNothingForPostSend()
9999
->method('getHeader');
100100

101101
$listener = new AuthListener(Client::AUTH_HTTP_PASSWORD, array('tokenOrLogin' => 'login', 'password' => 'mypasswd'));
102-
$this->assertNull($listener->postSend($request, $response));
102+
$listener->postSend($request, $response);
103103
}
104104

105105
/**
106106
* @test
107107
*/
108108
public function shouldSetAuthBasicHeaderForAuthPassMethod()
109109
{
110+
$expected = 'Basic '.base64_encode('login:mypasswd');
111+
110112
$request = $this->getMock('Buzz\Message\RequestInterface');
111113
$request->expects($this->once())
112114
->method('addHeader')
113-
->with('Authorization: Basic '.base64_encode('login:mypasswd'));
115+
->with('Authorization: '.$expected);
116+
$request->expects($this->once())
117+
->method('getHeader')
118+
->with('Authorization')
119+
->will($this->returnValue($expected));
114120

115121
$listener = new AuthListener(Client::AUTH_HTTP_PASSWORD, array('tokenOrLogin' => 'login', 'password' => 'mypasswd'));
116122
$listener->preSend($request);
123+
124+
$this->assertEquals($expected, $request->getHeader('Authorization'));
117125
}
118126

119127
/**
120128
* @test
121129
*/
122130
public function shouldSetAuthTokenHeaderForAuthPassMethod()
123131
{
132+
$expected = 'token test';
133+
124134
$request = $this->getMock('Buzz\Message\RequestInterface');
125135
$request->expects($this->once())
126136
->method('addHeader')
127-
->with('Authorization: token test');
137+
->with('Authorization: '.$expected);
138+
$request->expects($this->once())
139+
->method('getHeader')
140+
->with('Authorization')
141+
->will($this->returnValue($expected));
128142

129143
$listener = new AuthListener(Client::AUTH_HTTP_TOKEN, array('tokenOrLogin' => 'test'));
130144
$listener->preSend($request);
145+
146+
$this->assertEquals($expected, $request->getHeader('Authorization'));
131147
}
132148

133149
/**
@@ -142,4 +158,17 @@ public function shouldSetTokenInUrlForAuthUrlMethod()
142158

143159
$this->assertEquals('/res?access_token=test', $request->getUrl());
144160
}
161+
162+
/**
163+
* @test
164+
*/
165+
public function shouldSetClientDetailsInUrlForAuthUrlMethod()
166+
{
167+
$request = new Request(Request::METHOD_GET, '/res');
168+
169+
$listener = new AuthListener(Client::AUTH_URL_CLIENT_ID, array('tokenOrLogin' => 'clientId', 'password' => 'clientSsecret'));
170+
$listener->preSend($request);
171+
172+
$this->assertEquals('/res?client_id=clientId&client_secret=clientSsecret', $request->getUrl());
173+
}
145174
}

test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php.php renamed to test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Github\Tests\HttpClient;
44

5-
use Github\Client;
65
use Github\HttpClient\Listener\ErrorListener;
76

87
/**
@@ -127,9 +126,11 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode)
127126
$content = array(
128127
'message' => 'Validation Failed',
129128
'errors' => array(
130-
'code' => $errorCode,
131-
'field' => 'test',
132-
'resource' => 'fake'
129+
array(
130+
'code' => $errorCode,
131+
'field' => 'test',
132+
'resource' => 'fake'
133+
)
133134
)
134135
);
135136

0 commit comments

Comments
 (0)