diff --git a/.editorconfig b/.editorconfig index 257221d..5e9a93e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65c872d..c751d66 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,47 +1,32 @@ -name: build +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -on: [push, pull_request] + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' -env: - DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi" +name: build jobs: - phpunit: - name: PHP ${{ matrix.php }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + phpunit: + uses: yiisoft/actions/.github/workflows/phpunit.yml@master + with: + os: >- + ['ubuntu-latest'] + php: >- + ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer dependencies - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install dependencies - run: composer update $DEFAULT_COMPOSER_FLAGS - - name: Run unit tests with coverage - run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --colors=always - if: matrix.php == '7.1' - - name: Run unit tests without coverage - run: vendor/bin/phpunit --verbose --colors=always - if: matrix.php != '7.1' - - name: Upload code coverage - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover - if: matrix.php == '7.1' - continue-on-error: true # if is fork diff --git a/composer.json b/composer.json index 881d12f..2470f18 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,12 @@ } ], "require": { + "php": ">=7.3", "yiisoft/yii2": "~2.0.13", - "yiisoft/yii2-httpclient": "~2.0.5", - "paragonie/random_compat": ">=1" + "yiisoft/yii2-httpclient": "~2.0.5" }, "require-dev": { - "cweagans/composer-patches": "^1.7", - "phpunit/phpunit": "4.8.34" + "phpunit/phpunit": "^9.6" }, "suggest": { "web-token/jwt-checker": "required for JWS, JWT or JWK related flows like OpenIDConnect", @@ -49,20 +48,10 @@ "extra": { "branch-alias": { "dev-master": "2.0.x-dev" - }, - "patches": { - "phpunit/phpunit-mock-objects": { - "Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch" - }, - "phpunit/phpunit": { - "Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch", - "Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch" - } } }, "config": { "allow-plugins": { - "cweagans/composer-patches": true, "yiisoft/yii2-composer": true } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a2bff89..bdc64ca 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,27 @@ - - - - ./tests - - + + + + + + + + + ./tests + + + + + + ./src + + diff --git a/tests/AuthActionTest.php b/tests/AuthActionTest.php index a5524f3..c1df42a 100644 --- a/tests/AuthActionTest.php +++ b/tests/AuthActionTest.php @@ -7,7 +7,7 @@ class AuthActionTest extends TestCase { - protected function setUp() + protected function setUp(): void { $config = [ 'components' => [ @@ -65,7 +65,7 @@ public function testRedirect() $url = 'http://test.url'; $response = $action->redirect($url, true); - $this->assertContains($url, $response->content); + $this->assertStringContainsString($url, $response->content); } public function testGetClientId() diff --git a/tests/BaseClientTest.php b/tests/BaseClientTest.php index f9c7150..9cb482a 100644 --- a/tests/BaseClientTest.php +++ b/tests/BaseClientTest.php @@ -7,7 +7,7 @@ class BaseClientTest extends TestCase { - protected function setUp() + protected function setUp(): void { $this->mockApplication(); } @@ -227,4 +227,4 @@ public function testSetupStateStorage() $stateStorage = $client->getStateStorage(); $this->assertTrue($stateStorage instanceof SessionStateStorage, 'Unable to get default http client.'); } -} \ No newline at end of file +} diff --git a/tests/BaseOAuthTest.php b/tests/BaseOAuthTest.php index add36dd..1b70295 100644 --- a/tests/BaseOAuthTest.php +++ b/tests/BaseOAuthTest.php @@ -14,7 +14,7 @@ class BaseOAuthTest extends TestCase { use OAuthDefaultReturnUrlTestTrait; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -241,7 +241,7 @@ public function testSendRequest($responseStatusCode, $expectedException) $response->addHeaders(['http-code' => $responseStatusCode]); $response->setData('success'); - $request = $this->getMock(Request::className()); + $request = $this->createMock(Request::className()); $request ->expects($this->any()) ->method('send') diff --git a/tests/OAuth1Test.php b/tests/OAuth1Test.php index 7369496..86e7fb0 100644 --- a/tests/OAuth1Test.php +++ b/tests/OAuth1Test.php @@ -8,7 +8,7 @@ class OAuth1Test extends TestCase { - protected function setUp() + protected function setUp(): void { $config = [ 'components' => [ @@ -178,7 +178,7 @@ public function testBuildAuthUrl() $builtAuthUrl = $oauthClient->buildAuthUrl($requestToken); - $this->assertContains($authUrl, $builtAuthUrl, 'No auth URL present!'); - $this->assertContains($requestTokenToken, $builtAuthUrl, 'No token present!'); + $this->assertStringContainsString($authUrl, $builtAuthUrl, 'No auth URL present!'); + $this->assertStringContainsString($requestTokenToken, $builtAuthUrl, 'No token present!'); } } diff --git a/tests/OAuth2Test.php b/tests/OAuth2Test.php index ecacba9..49bf923 100644 --- a/tests/OAuth2Test.php +++ b/tests/OAuth2Test.php @@ -6,7 +6,7 @@ class OAuth2Test extends TestCase { - protected function setUp() + protected function setUp(): void { $config = [ 'components' => [ @@ -45,9 +45,9 @@ public function testBuildAuthUrl() $builtAuthUrl = $oauthClient->buildAuthUrl(); - $this->assertContains($authUrl, $builtAuthUrl, 'No auth URL present!'); - $this->assertContains($clientId, $builtAuthUrl, 'No client id present!'); - $this->assertContains(rawurlencode($returnUrl), $builtAuthUrl, 'No return URL present!'); + $this->assertStringContainsString($authUrl, $builtAuthUrl, 'No auth URL present!'); + $this->assertStringContainsString($clientId, $builtAuthUrl, 'No client id present!'); + $this->assertStringContainsString(rawurlencode($returnUrl), $builtAuthUrl, 'No return URL present!'); } public function testPkceCodeChallengeIsPresentInAuthUrl() @@ -61,7 +61,7 @@ public function testPkceCodeChallengeIsPresentInAuthUrl() $builtAuthUrl = $oauthClient->buildAuthUrl(); - $this->assertContains('code_challenge=', $builtAuthUrl, 'No code challenge Present!'); - $this->assertContains('code_challenge_method=S256', $builtAuthUrl, 'No code challenge method Present!'); + $this->assertStringContainsString('code_challenge=', $builtAuthUrl, 'No code challenge Present!'); + $this->assertStringContainsString('code_challenge_method=S256', $builtAuthUrl, 'No code challenge method Present!'); } } diff --git a/tests/OpenIdConnectTest.php b/tests/OpenIdConnectTest.php index 533c882..95a2c0f 100644 --- a/tests/OpenIdConnectTest.php +++ b/tests/OpenIdConnectTest.php @@ -8,7 +8,7 @@ class OpenIdConnectTest extends TestCase { - protected function setUp() + protected function setUp(): void { $config = [ 'components' => [ @@ -85,8 +85,8 @@ public function testBuildAuthUrl() $builtAuthUrl = $authClient->buildAuthUrl(); $this->assertNotEmpty($authClient->authUrl); - $this->assertContains($clientId, $builtAuthUrl, 'No client id present!'); - $this->assertContains(rawurlencode($returnUrl), $builtAuthUrl, 'No return URL present!'); + $this->assertStringContainsString($clientId, $builtAuthUrl, 'No client id present!'); + $this->assertStringContainsString(rawurlencode($returnUrl), $builtAuthUrl, 'No return URL present!'); } public function testNonce() diff --git a/tests/OpenIdTest.php b/tests/OpenIdTest.php index a27364d..95f7e47 100644 --- a/tests/OpenIdTest.php +++ b/tests/OpenIdTest.php @@ -6,7 +6,7 @@ class OpenIdTest extends TestCase { - protected function setUp() + protected function setUp(): void { $config = [ 'components' => [ diff --git a/tests/TestCase.php b/tests/TestCase.php index 95e03d7..ebe8da0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,7 +17,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase * Clean up after test. * By default the application created with [[mockApplication]] will be destroyed. */ - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->destroyApplication(); diff --git a/tests/TokenTest.php b/tests/TokenTest.php index 949c693..73141f7 100644 --- a/tests/TokenTest.php +++ b/tests/TokenTest.php @@ -29,7 +29,7 @@ public function testCreateWithIncorrectConfigOrder() 'tokenSecretParamKey' => 'test_token_secret_param_key', ]; $oauthToken = new OAuthToken($config); - $this->assertInternalType('object', $oauthToken, 'Unable to create access token!'); + $this->assertIsObject($oauthToken, 'Unable to create access token!'); foreach ($config as $name => $value) { $this->assertEquals($value, $oauthToken->$name, 'Unable to setup attributes by constructor!'); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 576b25b..8dc6802 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,5 +13,3 @@ Yii::setAlias('@yiiunit/extensions/authclient', __DIR__); Yii::setAlias('@yii/authclient', dirname(__DIR__) . '/src'); - -require_once(__DIR__ . '/compatibility.php'); \ No newline at end of file diff --git a/tests/clients/GoogleTest.php b/tests/clients/GoogleTest.php index 776164d..6048632 100644 --- a/tests/clients/GoogleTest.php +++ b/tests/clients/GoogleTest.php @@ -15,7 +15,7 @@ class GoogleTest extends TestCase { use OAuthDefaultReturnUrlTestTrait; - protected function setUp() + protected function setUp(): void { $config = [ 'components' => [ diff --git a/tests/compatibility.php b/tests/compatibility.php deleted file mode 100644 index f7fd3f2..0000000 --- a/tests/compatibility.php +++ /dev/null @@ -1,32 +0,0 @@ -setExpectedException($exception); - } - - /** - * @param string $message - */ - public function expectExceptionMessage($message) - { - $this->setExpectedException($this->getExpectedException(), $message); - } - } - } -}