Skip to content

Commit

Permalink
Fix tests for AuthListener
Browse files Browse the repository at this point in the history
Fix filename of the `ErrorListenerTest`
Fix `ErrorListenerTest` for php 5.4+
  • Loading branch information
stloyd committed Dec 21, 2012
1 parent 161335d commit 283d4a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
37 changes: 33 additions & 4 deletions test/Github/Tests/HttpClient/Listener/AuthListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function shouldDoNothingForHaveNullMethod()
->method('getUrl');

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

/**
Expand Down Expand Up @@ -99,35 +99,51 @@ public function shouldDoNothingForPostSend()
->method('getHeader');

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

/**
* @test
*/
public function shouldSetAuthBasicHeaderForAuthPassMethod()
{
$expected = 'Basic '.base64_encode('login:mypasswd');

$request = $this->getMock('Buzz\Message\RequestInterface');
$request->expects($this->once())
->method('addHeader')
->with('Authorization: Basic '.base64_encode('login:mypasswd'));
->with('Authorization: '.$expected);
$request->expects($this->once())
->method('getHeader')
->with('Authorization')
->will($this->returnValue($expected));

$listener = new AuthListener(Client::AUTH_HTTP_PASSWORD, array('tokenOrLogin' => 'login', 'password' => 'mypasswd'));
$listener->preSend($request);

$this->assertEquals($expected, $request->getHeader('Authorization'));
}

/**
* @test
*/
public function shouldSetAuthTokenHeaderForAuthPassMethod()
{
$expected = 'token test';

$request = $this->getMock('Buzz\Message\RequestInterface');
$request->expects($this->once())
->method('addHeader')
->with('Authorization: token test');
->with('Authorization: '.$expected);
$request->expects($this->once())
->method('getHeader')
->with('Authorization')
->will($this->returnValue($expected));

$listener = new AuthListener(Client::AUTH_HTTP_TOKEN, array('tokenOrLogin' => 'test'));
$listener->preSend($request);

$this->assertEquals($expected, $request->getHeader('Authorization'));
}

/**
Expand All @@ -142,4 +158,17 @@ public function shouldSetTokenInUrlForAuthUrlMethod()

$this->assertEquals('/res?access_token=test', $request->getUrl());
}

/**
* @test
*/
public function shouldSetClientDetailsInUrlForAuthUrlMethod()
{
$request = new Request(Request::METHOD_GET, '/res');

$listener = new AuthListener(Client::AUTH_URL_CLIENT_ID, array('tokenOrLogin' => 'clientId', 'password' => 'clientSsecret'));
$listener->preSend($request);

$this->assertEquals('/res?client_id=clientId&client_secret=clientSsecret', $request->getUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Github\Tests\HttpClient;

use Github\Client;
use Github\HttpClient\Listener\ErrorListener;

/**
Expand Down Expand Up @@ -127,9 +126,11 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode)
$content = array(
'message' => 'Validation Failed',
'errors' => array(
'code' => $errorCode,
'field' => 'test',
'resource' => 'fake'
array(
'code' => $errorCode,
'field' => 'test',
'resource' => 'fake'
)
)
);

Expand Down

0 comments on commit 283d4a9

Please sign in to comment.