Skip to content

Commit

Permalink
Merge 2aa6980 into 0958ebd
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowhand committed Nov 3, 2016
2 parents 0958ebd + 2aa6980 commit 60d929c
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 243 deletions.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"paragonie/random_compat": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0",
"mockery/mockery": "~0.9",
"squizlabs/php_codesniffer": "^2.0",
"jakub-onderka/php-parallel-lint": "~0.9"
"eloquent/liberator": "^2.0",
"eloquent/phony": "0.13.4",
"jakub-onderka/php-parallel-lint": "~0.9",
"phpunit/phpunit": "^5.0",
"squizlabs/php_codesniffer": "^2.0"
},
"keywords": [
"oauth",
Expand Down
10 changes: 2 additions & 8 deletions test/src/Grant/GrantFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use League\OAuth2\Client\Grant\AbstractGrant;
use League\OAuth2\Client\Grant\Exception\InvalidGrantException;
use League\OAuth2\Client\Test\Grant\Fake as MockGrant;
use Mockery as m;
use PHPUnit_Framework_TestCase as TestCase;

class GrantFactoryTest extends \PHPUnit_Framework_TestCase
class GrantFactoryTest extends TestCase
{
/**
* @var AbstractGrant
Expand All @@ -20,12 +20,6 @@ protected function setUp()
$this->factory = new GrantFactory();
}

public function tearDown()
{
m::close();
parent::tearDown();
}

/**
* @dataProvider providerGetGrantDefaults
*/
Expand Down
55 changes: 30 additions & 25 deletions test/src/Grant/GrantTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace League\OAuth2\Client\Test\Grant;

use Eloquent\Phony\Phpunit\Phony;
use GuzzleHttp\ClientInterface;
use PHPUnit_Framework_TestCase as TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Test\Provider\Fake as MockProvider;
use Mockery as m;

abstract class GrantTestCase extends \PHPUnit_Framework_TestCase
abstract class GrantTestCase extends TestCase
{
/** @var \League\OAuth2\Client\Provider\AbstractProvider */
/**
* @var \League\OAuth2\Client\Provider\AbstractProvider
*/
protected $provider;

protected function setUp()
Expand All @@ -23,12 +26,6 @@ protected function setUp()
));
}

public function tearDown()
{
m::close();
parent::tearDown();
}

/**
* Test that the grant's __toString method.
*/
Expand All @@ -53,28 +50,36 @@ abstract protected function getParamExpectation();
*/
public function testGetAccessToken($grant, array $params = [])
{
$stream = m::mock(StreamInterface::class);
$stream->shouldReceive('__toString')->times(1)->andReturn(
// Mock
$stream = Phony::mock(StreamInterface::class);
$stream->__toString->returns(
'{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'
);

$response = m::mock(ResponseInterface::class);
$response->shouldReceive('getBody')->times(1)->andReturn($stream);
$response->shouldReceive('getHeader')->with('content-type')->times(1)->andReturn('application/json');
$response = Phony::mock(ResponseInterface::class);
$response->getBody->returns($stream->get());
$response->getHeader->with('content-type')->returns('application/json');

$paramCheck = $this->getParamExpectation();

$client = m::mock(ClientInterface::class);
$client->shouldReceive('send')->with(
$request = m::on(function ($request) use ($paramCheck) {
parse_str((string) $request->getBody(), $body);
return $paramCheck($body);
})
)->times(1)->andReturn($response);

$this->provider->setHttpClient($client);
$client = Phony::mock(ClientInterface::class);
$client->send->returns($response->get());

// Execute
$this->provider->setHttpClient($client->get());
$token = $this->provider->getAccessToken($grant, $params);

// Verify
$this->assertInstanceOf(AccessToken::class, $token);

Phony::inOrder(
$client->send->times(1)->calledWith(
$this->callback(function ($request) {
parse_str((string) $request->getBody(), $body);
return call_user_func($this->getParamExpectation(), $body);
})
),
$response->getBody->times(1)->called(),
$stream->__toString->times(1)->called(),
$response->getHeader->times(1)->called()
);
}
}

0 comments on commit 60d929c

Please sign in to comment.