Skip to content

Commit

Permalink
PHP8: support
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Jun 24, 2021
1 parent 67a0362 commit 38bc212
Show file tree
Hide file tree
Showing 51 changed files with 152 additions and 104 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Continuous Integration"

on:
pull_request:
push:

jobs:
phpunit:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.1, 7.2, 7.3, 7.4, 8.0]
steps:
- uses: actions/checkout@v2
- name: Install PHP ${{ matrix.php }}
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "memory_limit=-1, phar.readonly=0"
php-version: ${{ matrix.php }}

- name: "Determine composer cache directory"
id: "determine-composer-cache-directory"
run: "echo \"::set-output name=directory::$(composer config cache-dir)\""

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1"
with:
path: "${{ steps.determine-composer-cache-directory.outputs.directory }}"
key: "php-${{ matrix.php }}-ci"
restore-keys: "php-${{ matrix.php }}"

- name: "Install dependencies"
run: composer update --no-progress -o --prefer-dist

- name: "Run PHPUnit"
run: ./vendor/bin/phpunit

- name: "Run PHPStan"
run: ./vendor/bin/phpstan analyze lib test --level=4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
report/
build/
composer.lock
.phpunit.result.cache
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.1|^8.0",
"ext-json": "*",
"jacobkiers/oauth":"~1.0",
"psr/http-message": "^1.0",
Expand All @@ -23,10 +23,11 @@
"php-http/client-common": "^2.0"
},
"require-dev": {
"phpunit/phpunit":"^7.5",
"phpunit/phpunit":"^7.5|^8",
"php-http/mock-client": " ^1.2",
"squizlabs/php_codesniffer": "^3.5",
"php-http/guzzle6-adapter": "^2.0"
"php-http/guzzle6-adapter": "^2.0",
"phpstan/phpstan": "^0.12.90"
},
"conflict": {
"eabay/bitbucket-repo-sync": "*",
Expand Down
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ public function delete($account, $name)
*/
public function members()
{
return $this->api(Members::class);
return new Members([], $this->getClient());
}
}
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/Repositories/Commits.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ public function deleteApproval($account, $repo, $revision)
*/
public function comments()
{
return $this->api(Comments::class);
return new Comments([], $this->getClient());
}
}
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/Repositories/Issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ public function delete($account, $repo, $issueID)
*/
public function comments()
{
return $this->api(Issues\Comments::class);
return new Issues\Comments([], $this->getClient());
}
}
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/Repositories/Pipelines.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ public function stopPipeline($account, $repo, $uuid)
*/
public function steps()
{
return $this->api(Steps::class);
return new Steps([], $this->getClient());
}
}
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/Repositories/PullRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PullRequests extends API\Api
*/
public function comments()
{
return $this->api('Repositories\\PullRequests\\Comments');
return new PullRequests\Comments([], $this->getClient());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Bitbucket/API/Teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function repositories($name)
*/
public function hooks()
{
return $this->api(Teams\Hooks::class);
return new Teams\Hooks([], $this->getClient());
}

/**
Expand All @@ -124,6 +124,6 @@ public function hooks()
*/
public function permissions()
{
return $this->api(Teams\Permissions::class);
return new Teams\Permissions([], $this->getClient());
}
}
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function emails()
*/
public function permissions()
{
return $this->api(User\Permissions::class);
return new User\Permissions([], $this->getClient());
}
}
4 changes: 2 additions & 2 deletions lib/Bitbucket/API/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function repositories($username)
*/
public function invitations()
{
return $this->api(Users\Invitations::class);
return new Users\Invitations([], $this->getClient());
}

/**
Expand All @@ -72,6 +72,6 @@ public function invitations()
*/
public function sshKeys()
{
return $this->api(Users\SshKeys::class);
return new Users\SshKeys([], $this->getClient());
}
}
2 changes: 1 addition & 1 deletion lib/Bitbucket/API/Workspaces/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public function projects($workspace)
*/
public function hooks()
{
return $this->api(Hooks::class);
return new Hooks([], $this->getClient());
}
}
8 changes: 4 additions & 4 deletions test/Bitbucket/Tests/API/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ public function testShouldDoDeleteRequest()
$this->assertSame('DELETE', $request->getMethod());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testFormat()
{
$this->expectException(\InvalidArgumentException::class);

$api = new Api;

// default format
Expand All @@ -96,10 +95,11 @@ public function testFormat()

/**
* @dataProvider invalidChildNameProvider
* @expectedException \InvalidArgumentException
*/
public function testSPFShouldFailWithInvalidClassName($name)
{
$this->expectException(\InvalidArgumentException::class);

$bitbucket = new Api();
$bitbucket->api($name);
}
Expand Down
7 changes: 3 additions & 4 deletions test/Bitbucket/Tests/API/GroupPrivilegesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GroupPrivilegesTest extends TestCase
/** @var GroupPrivileges */
private $groupPrivileges;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->groupPrivileges = $this->getApiMock(GroupPrivileges::class);
Expand Down Expand Up @@ -51,11 +51,10 @@ public function testGetRepositoriesPrivilegeGroupSuccess()
$this->assertRequest('GET', $endpoint, '', 'format=json');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testGrantGroupPrivilegesInvalidPrivilege()
{
$this->expectException(\InvalidArgumentException::class);

$this->groupPrivileges->grant('gentle', 'repo', 'owner', 'sys-admins', 'invalid');
}

Expand Down
2 changes: 1 addition & 1 deletion test/Bitbucket/Tests/API/Groups/MembersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MembersTest extends TestCase
/** @var Members */
private $members;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->members = $this->getApiMock(Members::class);
Expand Down
2 changes: 1 addition & 1 deletion test/Bitbucket/Tests/API/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GroupsTest extends TestCase
/** @var Groups */
private $groups;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->groups = $this->getApiMock(Groups::class);
Expand Down
10 changes: 5 additions & 5 deletions test/Bitbucket/Tests/API/Http/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ClientTest extends Tests\TestCase
/** @var Client */
private $client;

public function setUp()
public function setUp(): void
{
$this->client = new Client(array(), $this->getHttpPluginClientBuilder());
}
Expand All @@ -25,11 +25,10 @@ public function testGetSelfInstance()
$this->assertInstanceOf(HttpMethodsClient::class, $this->client->getClient());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testSetResponseFormatInvalid()
{
$this->expectException(\InvalidArgumentException::class);

$this->client->setResponseFormat('invalid');
}

Expand All @@ -41,11 +40,12 @@ public function testResponseFormatSuccess()

/**
* @dataProvider invalidApiVersionsProvider
* @expectedException \InvalidArgumentException
* @ticket 57
*/
public function testSetApiVersionInvalid($version)
{
$this->expectException(\InvalidArgumentException::class);

$this->client->setApiVersion($version);
}

Expand Down
24 changes: 12 additions & 12 deletions test/Bitbucket/Tests/API/Http/Plugin/OAuth2PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@

namespace Bitbucket\Tests\API\Http\Plugin;

use Bitbucket\API\Exceptions\ForbiddenAccessException;
use Bitbucket\API\Http\ClientInterface;
use Bitbucket\Tests\API as Tests;
use Bitbucket\API\Http\Plugin\OAuth2Plugin;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Http\Client\Promise\HttpFulfilledPromise;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\RequestInterface;

/**
* @author Alexandru G. <[email protected]>
*/
class OAuth2PluginTest extends Tests\TestCase
{
/** @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ClientInterface|MockObject */
private $httpClient;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

$this->httpClient = $this->getMockBuilder(ClientInterface::class)->getMock();
}

/**
* @expectedException \Bitbucket\API\Exceptions\ForbiddenAccessException
*/
public function testGetAccessTokenShouldFailWithInvalidJson()
{
$this->expectException(ForbiddenAccessException::class);

$oauth_params = [
'client_id' => 'aaa',
'client_secret' => 'bbb'
Expand Down Expand Up @@ -61,11 +62,10 @@ public function testGetAccessTokenShouldFailWithInvalidJson()
});
}

/**
* @expectedException \Bitbucket\API\Exceptions\ForbiddenAccessException
*/
public function testGetAccessTokenFail()
{
$this->expectException(ForbiddenAccessException::class);

$responseBody = '{"error_description": "Invalid OAuth client credentials", "error": "unauthorized_client"}';
$response = new Response(200, [], $responseBody);

Expand Down Expand Up @@ -111,8 +111,8 @@ public function testOauth2ListenerDoesNotReplaceExistingBearer()
$plugin->handleRequest($request, function (RequestInterface $request) {
$authHeader = $request->getHeader('Authorization')[0];

$this->assertContains('Bearer', $authHeader);
$this->assertContains('secret', $authHeader);
$this->assertStringContainsString('Bearer', $authHeader);
$this->assertStringContainsString('secret', $authHeader);

return new HttpFulfilledPromise(new Response());
}, function () {
Expand Down Expand Up @@ -148,8 +148,8 @@ public function testMakeSureRequestIncludesBearer()
$plugin->handleRequest($request, function (RequestInterface $request) {
$authHeader = $request->getHeader('Authorization')[0];

$this->assertContains('Bearer', $authHeader);
$this->assertContains('secret', $authHeader);
$this->assertStringContainsString('Bearer', $authHeader);
$this->assertStringContainsString('secret', $authHeader);

return new HttpFulfilledPromise(new Response());
}, function () {
Expand Down
4 changes: 2 additions & 2 deletions test/Bitbucket/Tests/API/Http/Plugin/OAuthPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function testMakeSureRequestIncludesOAuthHeader()
$listener = new OAuthPlugin($oauth_params);
$listener->handleRequest($request, function (RequestInterface $request) use ($oauth_params) {
$authHeader = $request->getHeader('Authorization')[0];
$this->assertContains('OAuth', $authHeader);
$this->assertContains(
$this->assertStringContainsString('OAuth', $authHeader);
$this->assertStringContainsString(
sprintf('oauth_consumer_key="%s"', $oauth_params['oauth_consumer_key']),
$authHeader
);
Expand Down
5 changes: 2 additions & 3 deletions test/Bitbucket/Tests/API/Http/Response/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ public function testFetchAllWithInvalidJsonShouldReturnEmptyValuesArray()
$this->assertEquals($expected, json_decode($response->getBody()->getContents(), true));
}

/**
* @expectedException \UnexpectedValueException
*/
public function testFetchAllWithUnauthorizedHeaderShouldFail()
{
$this->expectException(\UnexpectedValueException::class);

$response = $this->fakeResponse([], 401);

new Pager($this->getHttpPluginClientBuilder(), $response);
Expand Down
2 changes: 1 addition & 1 deletion test/Bitbucket/Tests/API/InvitationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class InvitationsTest extends TestCase
/** @var Invitations */
private $invitations;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->invitations = $this->getApiMock(Invitations::class);
Expand Down
Loading

0 comments on commit 38bc212

Please sign in to comment.