1
0
Fork 0

Add more tests to cover the new functionality.

pull/6094/head
Stefan Grootscholten 2016-12-27 12:48:54 +01:00
parent a4af559ca8
commit 512750a20e
1 changed files with 71 additions and 0 deletions

View File

@ -99,6 +99,77 @@ class BitbucketTest extends \PHPUnit_Framework_TestCase
);
}
public function testRequestAccessTokenWithValidOAuthConsumerAndValidStoredAccessToken()
{
$this->config->expects($this->once())
->method('get')
->with('bitbucket-oauth')
->willReturn(
array(
$this->origin => array(
'access-token' => $this->token,
'access-token-expiration' => $this->time + 1800,
'consumer-key' => $this->consumer_key,
'consumer-secret' => $this->consumer_secret
)
)
);
$this->assertEquals(
$this->token,
$this->bitbucket->requestToken($this->origin, $this->consumer_key, $this->consumer_secret)
);
}
public function testRequestAccessTokenWithValidOAuthConsumerAndExpiredAccessToken()
{
$this->config->expects($this->once())
->method('get')
->with('bitbucket-oauth')
->willReturn(
array(
$this->origin => array(
'access-token' => 'randomExpiredToken',
'access-token-expiration' => $this->time - 400,
'consumer-key' => $this->consumer_key,
'consumer-secret' => $this->consumer_secret
)
)
);
$this->io->expects($this->once())
->method('setAuthentication')
->with($this->origin, $this->consumer_key, $this->consumer_secret);
$this->rfs->expects($this->once())
->method('getContents')
->with(
$this->origin,
Bitbucket::OAUTH2_ACCESS_TOKEN_URL,
false,
array(
'retry-auth-failure' => false,
'http' => array(
'method' => 'POST',
'content' => 'grant_type=client_credentials',
)
)
)
->willReturn(
sprintf(
'{"access_token": "%s", "scopes": "repository", "expires_in": 3600, "refresh_token": "refreshtoken", "token_type": "bearer"}',
$this->token
)
);
$this->setExpectationsForStoringAccessToken();
$this->assertEquals(
$this->token,
$this->bitbucket->requestToken($this->origin, $this->consumer_key, $this->consumer_secret)
);
}
public function testRequestAccessTokenWithUsernameAndPassword()
{
$this->io->expects($this->once())