Skip to content

Commit dc8ff34

Browse files
authored
Move Travis to GH Actions and fix CI builds (#690)
* Move Travis config to GH Actions * Run PHPStan in Continuous integration GH Action * Run unit tests against different Symfony versions * Fix unit tests * Fix tools installation in GHA * Fix Mongodb tests * Install symfony/form and doctrine/annotations for unit tests * Use installed version of phpstan * Fix CS * Normalize composer.json * Run composer install before phpstan * Add phpstan-baseline file * Remove support for Propel * Fix Makefile syntax and Symfony versions in GHA * Update PHPStan baseline * Use ramsey/composer-install for dependencies * Add test dependencies during GH run * Fix dependencies install * Add SYMFONY_DEPRECATIONS_HELPER env variable * Require PHPUnit min 8.5.23 * Update minimum version of php-mock * Disallow Symfony version 6 for some components * Increase deprecation notices * Remove PHP 8.1 from GH actions Support and tests for PHP 8.1 can be added later * Limit symfony/form to 4.4 || 5.1 * Combine GH workflows to a single workflow
1 parent bf5080b commit dc8ff34

20 files changed

+1160
-177
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,73 @@ jobs:
2828

2929
- name: 'Check composer.json'
3030
run: 'composer-normalize --diff --dry-run --no-update-lock'
31+
32+
code-quality:
33+
runs-on: 'ubuntu-latest'
34+
name: 'Code Quality'
35+
steps:
36+
- name: 'Checkout'
37+
uses: 'actions/checkout@v2'
38+
39+
- name: 'Setup PHP'
40+
uses: 'shivammathur/setup-php@v2'
41+
with:
42+
php-version: '7.4'
43+
coverage: 'none'
44+
extensions: 'json, mbstring, tokenizer'
45+
env:
46+
update: true
47+
48+
- uses: 'ramsey/composer-install@v2'
49+
50+
- name: 'Display tools versions'
51+
run: 'vendor/bin/phpstan --version'
52+
53+
- name: 'Run PHPStan'
54+
run: 'vendor/bin/phpstan analyse --configuration phpstan.neon'
55+
56+
unit-tests:
57+
runs-on: 'ubuntu-latest'
58+
name: 'Unit Tests'
59+
strategy:
60+
matrix:
61+
php:
62+
- '7.2'
63+
- '7.3'
64+
- '7.4'
65+
- '8.0'
66+
dependencies:
67+
- 'lowest'
68+
- 'highest'
69+
- 'beta'
70+
include:
71+
- dependencies: 'beta'
72+
env:
73+
SYMFONY_VERSION: '${{ matrix.symfony_version }}'
74+
steps:
75+
- name: 'Checkout'
76+
uses: 'actions/checkout@v2'
77+
78+
- name: 'Setup PHP'
79+
uses: 'shivammathur/setup-php@v2'
80+
with:
81+
php-version: '${{ matrix.php }}'
82+
coverage: 'none'
83+
tools: 'composer:2'
84+
extensions: 'mongodb'
85+
env:
86+
update: true
87+
88+
- run: 'make composer-compat'
89+
90+
- run: |
91+
if [ "${{ matrix.dependencies }}" = "beta" ]; then make composer-config-beta; fi;
92+
93+
- run: 'composer rem symfony/form -n --no-update && composer req "symfony/form: ^4.4 || ^5.1" doctrine/annotations --no-update -n'
94+
95+
- uses: 'ramsey/composer-install@v2'
96+
with:
97+
dependency-versions: '${{ matrix.dependencies }}'
98+
composer-options: '${{ matrix.composer-options }}'
99+
100+
- run: 'make phpunit-coverage'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Propel/om/
55
Propel/map/
66
composer.lock
77
.php_cs.cache
8+
.phpunit.result.cache

.travis.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ composer-config-beta:
2626

2727
composer-install:
2828
rm -f composer.lock && cp composer.json composer.json~
29-
[[ -v SYMFONY_VERSION ]] && composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update || true
29+
ifdef SYMFONY_VERSION
30+
composer require "symfony/symfony:$(SYMFONY_VERSION)" --no-update --no-interaction
31+
endif
3032
composer update --prefer-dist --no-interaction
3133
mv composer.json~ composer.json
3234

Tests/Command/CleanCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public function testItShouldRemoveExpiredToken(): void
9292

9393
$display = $tester->getDisplay();
9494

95-
$this->assertContains(sprintf('Removed %d items from %s storage.', $expiredAccessTokens, get_class($this->accessTokenManager)), $display);
96-
$this->assertContains(sprintf('Removed %d items from %s storage.', $expiredRefreshTokens, get_class($this->refreshTokenManager)), $display);
97-
$this->assertContains(sprintf('Removed %d items from %s storage.', $expiredAuthCodes, get_class($this->authCodeManager)), $display);
95+
$this->assertStringContainsString(sprintf('Removed %d items from %s storage.', $expiredAccessTokens, get_class($this->accessTokenManager)), $display);
96+
$this->assertStringContainsString(sprintf('Removed %d items from %s storage.', $expiredRefreshTokens, get_class($this->refreshTokenManager)), $display);
97+
$this->assertStringContainsString(sprintf('Removed %d items from %s storage.', $expiredAuthCodes, get_class($this->authCodeManager)), $display);
9898
}
9999

100100
/**

Tests/Command/CreateClientCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public function testItShouldCreateClient($client): void
8080

8181
$output = $commandTester->getDisplay();
8282

83-
$this->assertContains('Client ID', $output);
84-
$this->assertContains('Client Secret', $output);
83+
$this->assertStringContainsString('Client ID', $output);
84+
$this->assertStringContainsString('Client Secret', $output);
8585
}
8686

8787
/**

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,32 @@ public function testShouldNotMandatoryServiceIfNotCustomDriverIsUsed(): void
5252
'auth_code_class' => 'anAuthCodeClass',
5353
]]);
5454

55-
$this->assertArraySubset([
55+
$this->assertSame([
5656
'db_driver' => 'orm',
5757
'client_class' => 'aClientClass',
5858
'access_token_class' => 'anAccessTokenClass',
5959
'refresh_token_class' => 'aRefreshTokenClass',
6060
'auth_code_class' => 'anAuthCodeClass',
61+
'model_manager_name' => null,
62+
'authorize' => [
63+
'form' => [
64+
'type' => 'fos_oauth_server_authorize',
65+
'handler' => 'fos_oauth_server.authorize.form.handler.default',
66+
'name' => 'fos_oauth_server_authorize_form',
67+
'validation_groups' => [
68+
'Authorize',
69+
'Default',
70+
],
71+
],
72+
],
6173
'service' => [
6274
'storage' => 'fos_oauth_server.storage.default',
6375
'user_provider' => null,
6476
'client_manager' => 'fos_oauth_server.client_manager.default',
6577
'access_token_manager' => 'fos_oauth_server.access_token_manager.default',
6678
'refresh_token_manager' => 'fos_oauth_server.refresh_token_manager.default',
6779
'auth_code_manager' => 'fos_oauth_server.auth_code_manager.default',
80+
'options' => [],
6881
],
6982
], $config);
7083
}
@@ -168,19 +181,32 @@ public function testShouldLoadCustomDriverConfig(): void
168181
],
169182
]]);
170183

171-
$this->assertArraySubset([
184+
$this->assertSame([
172185
'db_driver' => 'custom',
173186
'client_class' => 'aClientClass',
174187
'access_token_class' => 'anAccessTokenClass',
175188
'refresh_token_class' => 'aRefreshTokenClass',
176189
'auth_code_class' => 'anAuthCodeClass',
177190
'service' => [
178-
'storage' => 'fos_oauth_server.storage.default',
179-
'user_provider' => null,
180191
'client_manager' => 'a_client_manager_id',
181192
'access_token_manager' => 'an_access_token_manager_id',
182193
'refresh_token_manager' => 'a_refresh_token_manager_id',
183194
'auth_code_manager' => 'an_auth_code_manager_id',
195+
'storage' => 'fos_oauth_server.storage.default',
196+
'user_provider' => null,
197+
'options' => [],
198+
],
199+
'model_manager_name' => null,
200+
'authorize' => [
201+
'form' => [
202+
'type' => 'fos_oauth_server_authorize',
203+
'handler' => 'fos_oauth_server.authorize.form.handler.default',
204+
'name' => 'fos_oauth_server_authorize_form',
205+
'validation_groups' => [
206+
'Authorize',
207+
'Default',
208+
],
209+
],
184210
],
185211
], $config);
186212
}

Tests/Document/AuthCodeManagerTest.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
namespace FOS\OAuthServerBundle\Tests\Document;
1515

16-
use Doctrine\MongoDB\Query\Builder;
1716
use Doctrine\ODM\MongoDB\DocumentManager;
18-
use Doctrine\ODM\MongoDB\DocumentRepository;
19-
use Doctrine\ORM\AbstractQuery;
17+
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
18+
use Doctrine\ODM\MongoDB\Query\Builder;
19+
use Doctrine\ODM\MongoDB\Query\Query;
20+
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
2021
use FOS\OAuthServerBundle\Document\AuthCodeManager;
2122
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
23+
use MongoDB\Collection;
2224

2325
/**
2426
* @group time-sensitive
@@ -77,20 +79,14 @@ public function setUp(): void
7779
parent::setUp();
7880
}
7981

80-
public function testConstructWillSetParameters(): void
81-
{
82-
$this->assertAttributeSame($this->documentManager, 'dm', $this->instance);
83-
$this->assertAttributeSame($this->className, 'class', $this->instance);
84-
}
85-
8682
public function testGetClassWillReturnClassName(): void
8783
{
8884
$this->assertSame($this->className, $this->instance->getClass());
8985
}
9086

9187
public function testFindAuthCodeBy(): void
9288
{
93-
$randomResult = \random_bytes(10);
89+
$randomResult = new \stdClass();
9490
$criteria = [
9591
\random_bytes(10),
9692
];
@@ -188,11 +184,28 @@ public function testDeleteExpired(): void
188184
->willReturn($queryBuilder)
189185
;
190186

191-
$query = $this->getMockBuilder(AbstractQuery::class)
192-
->disableOriginalConstructor()
193-
->getMock()
187+
$data = [
188+
'n' => \random_bytes(10),
189+
];
190+
191+
$collection = $this->createMock(Collection::class);
192+
$collection->expects(self::once())
193+
->method('deleteMany')
194+
->willReturn($data)
194195
;
195196

197+
$query = new Query(
198+
$this->documentManager,
199+
$this->createMock(ClassMetadata::class),
200+
$collection,
201+
[
202+
'type' => Query::TYPE_REMOVE,
203+
'query' => null,
204+
],
205+
[],
206+
false
207+
);
208+
196209
$queryBuilder
197210
->expects($this->once())
198211
->method('getQuery')
@@ -202,17 +215,6 @@ public function testDeleteExpired(): void
202215
->willReturn($query)
203216
;
204217

205-
$data = [
206-
'n' => \random_bytes(10),
207-
];
208-
209-
$query
210-
->expects($this->once())
211-
->method('execute')
212-
->with()
213-
->willReturn($data)
214-
;
215-
216218
$this->assertSame($data['n'], $this->instance->deleteExpired());
217219
}
218220
}

Tests/Document/ClientManagerTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace FOS\OAuthServerBundle\Tests\Document;
1515

1616
use Doctrine\ODM\MongoDB\DocumentManager;
17-
use Doctrine\ODM\MongoDB\DocumentRepository;
17+
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
1818
use FOS\OAuthServerBundle\Document\ClientManager;
1919
use FOS\OAuthServerBundle\Model\ClientInterface;
2020

@@ -73,21 +73,14 @@ public function setUp(): void
7373
parent::setUp();
7474
}
7575

76-
public function testConstructWillSetParameters(): void
77-
{
78-
$this->assertAttributeSame($this->documentManager, 'dm', $this->instance);
79-
$this->assertAttributeSame($this->repository, 'repository', $this->instance);
80-
$this->assertAttributeSame($this->className, 'class', $this->instance);
81-
}
82-
8376
public function testGetClass(): void
8477
{
8578
$this->assertSame($this->className, $this->instance->getClass());
8679
}
8780

8881
public function testFindClientBy(): void
8982
{
90-
$randomResult = \random_bytes(5);
83+
$randomResult = new \stdClass();
9184
$criteria = [
9285
\random_bytes(5),
9386
];

0 commit comments

Comments
 (0)