Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Jan 28, 2024
1 parent e60f286 commit 95a4251
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 13 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.3']

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Print PHP version
run: php -v

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Validate composer.json
run: composer validate

- name: Install dependencies
run: composer install --optimize-autoloader --no-progress --no-interaction --prefer-dist

- name: Run tests
run: vendor/bin/phpunit --testdox

- name: Run PHPStan
run: vendor/bin/phpstan analyse --level 8 --no-interaction --no-progress src

- name: Run PHPCS
run: vendor/bin/phpcs src tests --standard=psr2 -s
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"require-dev": {
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.8",
"mockery/mockery": "^1.6"
"mockery/mockery": "^1.6",
"phpstan/phpstan": "^1.10"
}
}
34 changes: 28 additions & 6 deletions src/Provider/Galette.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class Galette extends AbstractProvider
protected string $pluginDirectory = 'plugin-oauth2';

/**
* @var array
* @var string[]
*/
protected array $scope;

/**
* @param array<string, mixed> $options
* @param array<string, mixed> $collaborators
*/
public function __construct(array $options = [], array $collaborators = [])
{
if (!isset($options['instance'])) {
Expand Down Expand Up @@ -62,38 +66,56 @@ public function getBaseURL(): string
);
}

public function getBaseAuthorizationUrl()
public function getBaseAuthorizationUrl(): string
{
return $this->getBaseURL() . '/authorize';
}

public function getBaseAccessTokenUrl(array $params)
/**
* @param array<string, mixed> $params
* @return string
*/
public function getBaseAccessTokenUrl(array $params): string
{
return $this->getBaseURL() . '/access_token';
}

public function getResourceOwnerDetailsUrl(AccessToken $token)
public function getResourceOwnerDetailsUrl(AccessToken $token): string
{
return $this->getBaseURL() . '/user';
}

protected function getDefaultScopes()
/**
* @return string[]
*/
protected function getDefaultScopes(): array
{
return [];
}

/**
* @param ResponseInterface $response
* @param string|array<string, string> $data
* @return void
* @throws IdentityProviderException
*/
protected function checkResponse(ResponseInterface $response, $data)
{
$statusCode = $response->getStatusCode();
if ($statusCode > 400) {
throw new IdentityProviderException(
$data['message'] ?: $response->getReasonPhrase(),
(is_array($data) && $data['message']) ? $data['message'] : $response->getReasonPhrase(),
$statusCode,
$response
);
}
}

/**
* @param array<string, mixed> $response
* @param AccessToken $token
* @return GaletteResourceOwner
*/
protected function createResourceOwner(array $response, AccessToken $token)
{
return new GaletteResourceOwner($response);
Expand Down
9 changes: 6 additions & 3 deletions src/Provider/GaletteResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

class GaletteResourceOwner implements ResourceOwnerInterface
{
use ArrayAccessorTrait;
use ArrayAccessorTrait;

/**
* @var array<string, mixed>
*/
protected array $response;

/**
* @param array<string, mixed> $response
*/
public function __construct(array $response = [])
{
$this->response = $response;
Expand Down Expand Up @@ -73,10 +76,10 @@ public function getStatus(): ?int
/**
* Return all owner details available as an array.
*
* @return array
* @return array<string, mixed>
*/
public function toArray(): array
{
return $this->response;
}
}
}
6 changes: 3 additions & 3 deletions tests/src/Provider/GaletteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function testGetAuthorizationUrl()
public function testGetAccessToken()
{
$response = m::mock('Psr\Http\Message\ResponseInterface');
//$response->shouldReceive('getBody')->andReturn('{"access_token": "mock_access_token", "token_type": "bearer", "account_id": "12345", "uid": "deprecated_id"}');
$response
->shouldReceive('getBody')
->andReturn(
Expand Down Expand Up @@ -117,7 +116,8 @@ public function testUserData()
->andReturn(
new Stream(
fopen(
'data://text/plain,{"id": '.$userId.', "username": "'.$username.'", "email": "'.$email.'", "language": "'.$lang.'", "status": '.$status.'}',
'data://text/plain,{"id": '.$userId.', "username": "'.$username.'", "email": "'.
$email.'", "language": "'.$lang.'", "status": '.$status.'}',
'r'
)
)
Expand Down Expand Up @@ -156,7 +156,7 @@ public function testUserData()
public function testUserDataFails()
{
$this->expectException(\League\OAuth2\Client\Provider\Exception\IdentityProviderException::class);
$status = rand(400,600);
$status = rand(400, 600);

$postResponse = m::mock('Psr\Http\Message\ResponseInterface');
$postResponse
Expand Down

0 comments on commit 95a4251

Please sign in to comment.