Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Mockery with Phony #584

Merged
merged 4 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 30 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- hhvm
matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
- php: nightly
- php: hhvm-3.6
sudo: required
dist: trusty
group: edge
- php: hhvm-3.9
sudo: required
dist: trusty
group: edge
- php: hhvm-3.12
sudo: required
dist: trusty
group: edge
- php: hhvm-3.15
sudo: required
dist: trusty
group: edge
- php: hhvm-nightly
sudo: required
dist: trusty
group: edge
fast_finish: true
allow_failures:
- php: nightly
- php: hhvm-nightly

before_script:
- travis_retry composer install --no-interaction --prefer-source
Expand Down
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.14.1",
"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()
);
}
}