From 241400d76067d4220870f73218ec990e9f5d6656 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Sat, 16 Mar 2024 12:17:25 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9A=20fix=20CI=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yaml | 15 +++++++----- src/Recaptcha/RecaptchaException.php | 4 ++-- src/Recaptcha/RecaptchaVerifier.php | 4 ++-- tests/Recaptcha/RecaptchaVerifierTest.php | 28 +++++++---------------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 12c986b..813ecbb 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,7 +10,7 @@ jobs: name: PHPStan steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: PHPStan uses: docker://oskarstark/phpstan-ga env: @@ -22,7 +22,7 @@ jobs: name: PHP-CS-Fixer steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Fix CS uses: docker://oskarstark/php-cs-fixer-ga tests: @@ -31,15 +31,18 @@ jobs: fail-fast: false matrix: include: - - description: 'Symfony 6.2' + - description: 'Symfony 6.4' php: '8.1' composer_option: '--prefer-lowest' - - description: 'Symfony 6.3' + - description: 'Symfony 6.4' php: '8.2' symfony: 6.3.* - description: 'Symfony 7.0' - php: '8.2' - symfony: 7.0.*@dev + php: '8.3' + symfony: 7.0.* + - description: 'Symfony 7.1' + php: '8.3' + symfony: 7.1.*@dev name: PHP ${{ matrix.php }} tests (${{ matrix.description }}) steps: - name: Checkout diff --git a/src/Recaptcha/RecaptchaException.php b/src/Recaptcha/RecaptchaException.php index 6b9da8e..d24a3d8 100644 --- a/src/Recaptcha/RecaptchaException.php +++ b/src/Recaptcha/RecaptchaException.php @@ -6,8 +6,8 @@ final class RecaptchaException extends \Exception { - public function __construct(Response $response) + public function __construct(Response $response, ?\Throwable $previous = null) { - parent::__construct('ReCaptcha errors: '.\implode(', ', $response->getErrorCodes())); + parent::__construct('ReCaptcha errors: '.\implode(', ', $response->getErrorCodes()), previous: $previous); } } diff --git a/src/Recaptcha/RecaptchaVerifier.php b/src/Recaptcha/RecaptchaVerifier.php index bcbbb9f..36ca6bb 100644 --- a/src/Recaptcha/RecaptchaVerifier.php +++ b/src/Recaptcha/RecaptchaVerifier.php @@ -33,8 +33,8 @@ public function verify(?string $recaptchaValue = null): void if (empty($recaptchaValue) && $request->request->has(self::GOOGLE_DEFAULT_INPUT)) { try { $recaptchaValue = $request->request->get(self::GOOGLE_DEFAULT_INPUT); - } catch (BadRequestException) { - throw new RecaptchaException(new Response(false)); + } catch (BadRequestException $exception) { + throw new RecaptchaException(new Response(false), $exception); } } diff --git a/tests/Recaptcha/RecaptchaVerifierTest.php b/tests/Recaptcha/RecaptchaVerifierTest.php index 48b85fc..a082d5c 100644 --- a/tests/Recaptcha/RecaptchaVerifierTest.php +++ b/tests/Recaptcha/RecaptchaVerifierTest.php @@ -30,22 +30,14 @@ protected function setUp(): void public function testVerifyDisabled(): void { - if (\is_callable([$this->stack, 'getMainRequest'])) { - $this->stack->expects(self::never())->method('getMainRequest'); - } else { - $this->stack->expects(self::never())->method('getMasterRequest'); - } + $this->stack->expects(self::never())->method('getMainRequest'); $verifier = new RecaptchaVerifier($this->recaptcha, $this->stack, false); $verifier->verify('captcha-response'); } public function testVerifySuccess(): void { - if (\is_callable([$this->stack, 'getMainRequest'])) { - $this->stack->expects(self::once())->method('getMainRequest')->willReturn($this->request); - } else { - $this->stack->expects(self::once())->method('getMasterRequest')->willReturn($this->request); - } + $this->stack->expects(self::once())->method('getMainRequest')->willReturn($this->request); $this->request->expects(self::once())->method('getClientIp')->willReturn('127.0.0.1'); $response = $this->createMock(Response::class); $response->expects(self::once())->method('isSuccess')->willReturn(true); @@ -59,11 +51,7 @@ public function testVerifyFailure(): void { $this->expectException(RecaptchaException::class); - if (\is_callable([$this->stack, 'getMainRequest'])) { - $this->stack->expects(self::once())->method('getMainRequest')->willReturn($this->request); - } else { - $this->stack->expects(self::once())->method('getMasterRequest')->willReturn($this->request); - } + $this->stack->expects(self::once())->method('getMainRequest')->willReturn($this->request); $this->request->expects(self::once())->method('getClientIp')->willReturn('127.0.0.1'); $response = $this->createMock(Response::class); $response->expects(self::once())->method('isSuccess')->willReturn(false); @@ -76,16 +64,16 @@ public function testVerifyFailure(): void public function testVerifyRecaptchaValueSubmitted(): void { + if (PHP_VERSION_ID < 80200) { + self::markTestSkipped('Avoid notice.'); + } + $this->expectException(RecaptchaException::class); $request = new Request(); $request->request->set('g-recaptcha-response', []); - if (\is_callable([$this->stack, 'getMainRequest'])) { - $this->stack->expects(self::once())->method('getMainRequest')->willReturn($request); - } else { - $this->stack->expects(self::once())->method('getMasterRequest')->willReturn($request); - } + $this->stack->expects(self::once())->method('getMainRequest')->willReturn($request); $this->request->expects(self::never())->method('getClientIp'); $verifier = new RecaptchaVerifier($this->recaptcha, $this->stack);