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

Add ci.yaml #4

Merged
merged 16 commits into from
Jun 15, 2021
69 changes: 69 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Continuous integration

on:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 4 * * 1,2'

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0]

name: PHP ${{ matrix.php }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
coverage: pcov

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
id: composer-update
run: composer update --no-interaction --no-progress --prefer-dist

- name: Fail the test
if: steps.composer-update.outcome != 'success'
run: exit 1

- name: Get PHPUnit version
id: phpunit-version
run: echo "::set-output name=version::$(composer info phpunit/phpunit | grep versions)"

- name: Set pcov for PHPUnit 5.x, 6.x, 7.x
if: contains(steps.phpunit-version.outputs.version, '* 5.') || contains(steps.phpunit-version.outputs.version, '* 6.') || contains(steps.phpunit-version.outputs.version, '* 7.')
continue-on-error: true
run: |
composer require pcov/clobber --dev
vendor/bin/pcov clobber

- name: PHPUnit tests
run: vendor/bin/phpunit --verbose --coverage-clover ./coverage.xml

- name: Coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
with:
percentage: "100"
filename: "coverage.xml"

- uses: actions/cache@v2
with:
path: ~/.symfony/cache
key: ${{ runner.os }}-php-${{ matrix.php }}
restore-keys: ${{ runner.os }}-php-

- name: The PHP Security Checker
uses: symfonycorp/security-checker-action@v2
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
"bookingsync"
],
"require": {
"php": ">=5.4.0",
"php": "^5.6|^7.0|^8.0",
"league/oauth2-client": "^2.0"
},
"require-dev": {
"mockery/mockery": "~1.3",
"phpunit/phpunit": "^5.7|^6.0",
"phpunit/phpunit": "^5.7|^6.5|^7.5|^8.5|^9.5",
"squizlabs/php_codesniffer": "~2.0",
"jakub-onderka/php-parallel-lint": "0.8.*",
"phpstan/phpstan": "^0.12.49"
"php-parallel-lint/php-parallel-lint": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
52 changes: 33 additions & 19 deletions test/src/Provider/BookingsyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,41 @@

use Bookingsync\OAuth2\Client\Provider\BookingSyncProvider;
use GuzzleHttp\ClientInterface;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

class BookingsyncTest extends TestCase
{
protected $provider;

protected function setUp(): void
/**
* @var BookingSyncProvider
*/
private $provider;

/**
* @return BookingSyncProvider
*/
private function getProvider()
{
$this->provider = new BookingSyncProvider([
if (null !== $this->provider) {
return $this->provider;
}

return $this->provider = new BookingSyncProvider([
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
]);
}

/**
* @return void
*/
public function testGetAuthorizationUrl()
{
$url = $this->provider->getAuthorizationUrl();
$url = $this->getProvider()->getAuthorizationUrl();
$uri = parse_url($url);
parse_str($uri['query'], $query);

Expand All @@ -34,20 +48,20 @@ public function testGetAuthorizationUrl()
$this->assertArrayHasKey('scope', $query);
$this->assertArrayHasKey('response_type', $query);
$this->assertArrayHasKey('approval_prompt', $query);
$this->assertNotNull($this->provider->getState());
$this->assertNotNull($this->getProvider()->getState());
}

public function testGetBaseAuthorizationUrl()
{
$url = $this->provider->getBaseAuthorizationUrl();
$url = $this->getProvider()->getBaseAuthorizationUrl();
$uri = parse_url($url);

$this->assertEquals('/oauth/authorize', $uri['path']);
}

public function testGetBaseAccessTokenUrl()
{
$url = $this->provider->getBaseAccessTokenUrl();
$url = $this->getProvider()->getBaseAccessTokenUrl();
$uri = parse_url($url);

$this->assertEquals('/oauth/token', $uri['path']);
Expand All @@ -70,10 +84,10 @@ public function testGetResourceOwnerDetailsUrl()
$client = m::mock(ClientInterface::class);
$client->shouldReceive('setBaseUrl')->times(1);
$client->shouldReceive('send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$this->getProvider()->setHttpClient($client);

$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$url = $this->provider->getResourceOwnerDetailsUrl($token);
$token = $this->getProvider()->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$url = $this->getProvider()->getResourceOwnerDetailsUrl($token);

$uri = parse_url($url);

Expand All @@ -97,9 +111,9 @@ public function testGetAccessToken()
$client = m::mock(ClientInterface::class);
$client->shouldReceive('setBaseUrl')->times(1);
$client->shouldReceive('send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);
$this->getProvider()->setHttpClient($client);

$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$token = $this->getProvider()->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);

$this->assertEquals('mock_access_token', $token->getToken());
$this->assertLessThanOrEqual(time() + 3600, $token->getExpires());
Expand Down Expand Up @@ -143,10 +157,10 @@ public function testUserData()
$client->shouldReceive('setDefaultOption')->times(4);
$client->shouldReceive('send')->times(1)->andReturn($postResponse);
$client->shouldReceive('send')->times(4)->andReturn($getResponse);
$this->provider->setHttpClient($client);
$this->getProvider()->setHttpClient($client);

$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->provider->getResourceOwner($token);
$token = $this->getProvider()->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$user = $this->getProvider()->getResourceOwner($token);

$this->assertEquals('mock_id', $user->getId());
$this->assertEquals('mock_business_name', $user->getBusinessName());
Expand Down Expand Up @@ -180,12 +194,12 @@ public function testUserDataFails()
$client->shouldReceive('send')
->times(2)
->andReturn($postResponse, $userResponse);
$this->provider->setHttpClient($client);
$this->getProvider()->setHttpClient($client);

$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
$token = $this->getProvider()->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);

try {
$user = $this->provider->getResourceOwner($token);
$this->getProvider()->getResourceOwner($token);
return false;
} catch (\Exception $e) {
$this->assertInstanceOf(IdentityProviderException::class, $e);
Expand Down