Skip to content

Commit

Permalink
Merge pull request #50 from Bee-Lab/fix-build
Browse files Browse the repository at this point in the history
💚 fix CI build
  • Loading branch information
garak authored Mar 17, 2024
2 parents 637fa2d + 241400d commit e56a7fb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Recaptcha/RecaptchaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Recaptcha/RecaptchaVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
28 changes: 8 additions & 20 deletions tests/Recaptcha/RecaptchaVerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e56a7fb

Please sign in to comment.