Skip to content

Commit

Permalink
Update CI and fix tests (markitosgv#361)
Browse files Browse the repository at this point in the history
* Fix PHP 8.2 compat issue in uses of DateTime::modify()

* Update CI and fix tests
  • Loading branch information
mbabker authored Jul 1, 2023
1 parent a74722e commit 4952a1d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
symfony: ['4.4.*', '5.4.*', '6.0.*']
php: ['7.4', '8.0', '8.1', '8.2']
symfony: ['4.4.*', '5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*']
composer-flags: ['--prefer-stable']
can-fail: [false]
extensions: ['curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip']
Expand All @@ -23,15 +23,27 @@ jobs:
exclude:
- php: '7.4'
symfony: '6.0.*'
- php: '7.4'
symfony: '6.1.*'
- php: '7.4'
symfony: '6.2.*'
- php: '7.4'
symfony: '6.3.*'
- php: '8.0'
symfony: '6.1.*'
- php: '8.0'
symfony: '6.2.*'
- php: '8.0'
symfony: '6.3.*'

name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

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

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-symfony-${{ matrix.symfony }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-flags-${{ matrix.composer-flags }}
Expand All @@ -52,7 +64,7 @@ jobs:
topology: server

- name: Remove Guard
if: matrix.symfony == '6.0.*'
if: contains(fromJSON('["6.0.*", "6.1.*", "6.2.*", "6.3.*"]'), matrix.symfony)
run: composer remove --dev --no-update symfony/security-guard

- name: Install dependencies
Expand Down
8 changes: 7 additions & 1 deletion Model/AbstractRefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ abstract class AbstractRefreshToken implements RefreshTokenInterface
public static function createForUserWithTtl(string $refreshToken, UserInterface $user, int $ttl): RefreshTokenInterface
{
$valid = new \DateTime();
$valid->modify('+'.$ttl.' seconds');

// Explicitly check for a negative number based on a behavior change in PHP 8.2, see https://github.com/php/php-src/issues/9950
if ($ttl > 0) {
$valid->modify('+'.$ttl.' seconds');
} elseif ($ttl < 0) {
$valid->modify($ttl.' seconds');
}

$model = new static();
$model->setRefreshToken($refreshToken);
Expand Down
9 changes: 8 additions & 1 deletion Security/Http/Authenticator/RefreshTokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public function authenticate(Request $request): Passport

if ($this->options['ttl_update']) {
$expirationDate = new \DateTime();
$expirationDate->modify(sprintf('+%d seconds', $this->options['ttl']));

// Explicitly check for a negative number based on a behavior change in PHP 8.2, see https://github.com/php/php-src/issues/9950
if ($this->options['ttl'] > 0) {
$expirationDate->modify(sprintf('+%d seconds', $this->options['ttl']));
} elseif ($this->options['ttl'] < 0) {
$expirationDate->modify(sprintf('%d seconds', $this->options['ttl']));
}

$refreshToken->setValid($expirationDate);

$this->refreshTokenManager->save($refreshToken);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Request/Extractor/RequestBodyExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function createMockRequest(?string $contentType, ?array $jsonBodyData =

$request
->expects($this->atLeastOnce())
->method('getContentType')
->method(method_exists(Request::class, 'getContentTypeFormat') ? 'getContentTypeFormat' : 'getContentType')
->willReturn($contentType);

if (is_array($jsonBodyData)) {
Expand Down
5 changes: 0 additions & 5 deletions Tests/bootstrap.php

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"symfony/security-http": "^4.4|^5.4|^6.0"
},
"require-dev": {
"doctrine/annotations": "^1.13|^2.0",
"doctrine/cache": "^1.11|^2.0",
"doctrine/mongodb-odm": "^2.2",
"doctrine/orm": "^2.7",
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="Tests/bootstrap.php"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
>
<testsuites>
Expand All @@ -18,7 +18,6 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./spec</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
Expand Down

0 comments on commit 4952a1d

Please sign in to comment.