Skip to content

Commit 4f7a106

Browse files
norkunaskarser
authored andcommitted
Allow Symfony 7
1 parent f2cc87e commit 4f7a106

File tree

6 files changed

+68
-55
lines changed

6 files changed

+68
-55
lines changed

.github/workflows/code_checks.yaml

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,65 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
php: ['7.1', '7.2', '7.4', '8.0', '8.1', '8.2']
18-
symfony: ['^3.4', '^4.0', '^5.0']
17+
php: ['7.1', '7.2', '7.4', '8.0', '8.1', '8.2', '8.3']
18+
symfony: ['^3.4', '^4.0', '^5.0', '^6.0', '^7.0']
1919
exclude:
2020
- symfony: ^5.0
2121
php: 7.1
22+
- symfony: ^6.0
23+
php: 7.1
24+
- symfony: ^6.0
25+
php: 7.2
26+
- symfony: ^6.0
27+
php: 7.4
28+
- symfony: ^7.0
29+
php: 7.1
30+
- symfony: ^7.0
31+
php: 7.2
32+
- symfony: ^7.0
33+
php: 7.4
34+
- symfony: ^7.0
35+
php: 8.0
36+
- symfony: ^7.0
37+
php: 8.1
2238
include:
2339
- symfony: ^6.0
2440
php: 8.0
2541
- symfony: ^6.0
2642
php: 8.1
2743
- symfony: ^6.0
2844
php: 8.2
45+
- symfony: ^7.0
46+
php: 8.2
47+
- symfony: ^7.0
48+
php: 8.3
2949
fail-fast: false
3050
name: PHPUnit (PHP ${{ matrix.php }}) (Symfony ${{ matrix.symfony }})
3151
steps:
3252

3353
- name: Checkout code
34-
uses: actions/checkout@v3
54+
uses: actions/checkout@v4
3555

3656
- name: Setup PHP
3757
uses: shivammathur/setup-php@v2
3858
with:
3959
php-version: ${{ matrix.php }}
60+
tools: flex
4061
coverage: none # disable xdebug, pcov
4162

42-
- name: Get Composer cache directory
43-
id: composer-cache
44-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
45-
46-
- name: Cache Composer
47-
uses: actions/cache@v3
48-
with:
49-
path: ${{ steps.composer-cache.outputs.dir }}
50-
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
51-
restore-keys: |
52-
${{ runner.os }}-php-${{ matrix.php }}-composer-
63+
- name: Validate composer.json
64+
run: composer validate --ansi --strict
5365

54-
- name: Restrict Symfony version
55-
if: matrix.symfony != ''
56-
run: |
57-
composer global require --no-progress --no-scripts --no-plugins "symfony/flex"
58-
composer global config --no-plugins allow-plugins.symfony/flex true
59-
composer config extra.symfony.require "${{ matrix.symfony }}"
66+
- name: Install PHP dependencies
67+
uses: ramsey/composer-install@v2
68+
env:
69+
SYMFONY_REQUIRE: ${{ matrix.symfony }}
6070

6171
# remove this after support for symfony 3 is dropped
6272
- name: Remove PhpUnit 10 support for old Symfony Versions
6373
if: matrix.symfony == '^3.4' || matrix.symfony == '^4.0'
6474
run: composer require --no-update "phpunit/phpunit:^7|^8|^9"
6575

66-
- name: Install PHP dependencies
67-
run: composer install --no-interaction
68-
69-
- name: Validate composer.json
70-
run: composer validate --ansi --strict
71-
7276
- name: Run tests
7377
run: vendor/bin/phpunit
7478

@@ -77,28 +81,16 @@ jobs:
7781
runs-on: ubuntu-latest
7882
steps:
7983
- name: Checkout code
80-
uses: actions/checkout@v3
84+
uses: actions/checkout@v4
8185

8286
- name: Setup PHP
8387
uses: shivammathur/setup-php@v2
8488
with:
85-
php-version: 7.4
89+
php-version: 8.3
8690
coverage: xdebug
8791

88-
- name: Get Composer cache directory
89-
id: composer-cache
90-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
91-
92-
- name: Cache Composer
93-
uses: actions/cache@v3
94-
with:
95-
path: ${{ steps.composer-cache.outputs.dir }}
96-
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
97-
restore-keys: |
98-
${{ runner.os }}-php-${{ matrix.php }}-composer-
99-
10092
- name: Install PHP dependencies
101-
run: composer install --no-interaction
93+
uses: ramsey/composer-install@v2
10294

10395
- name: Run code coverage
10496
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

Tests/FunctionalTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public function testFormJavascriptPresent_ifEnabled()
3838
$view = $template->render(['form' => $form->createView()]);
3939

4040
//THEN
41-
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]" />', $view);
41+
if (TestKernel::VERSION_ID >= 60400) {
42+
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]">', $view);
43+
} else {
44+
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]" />', $view);
45+
}
4246
self::assertStringContainsString('<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=key&hl=en&onload=recaptchaCallback_form_captcha" async defer nonce=""></script>', $view);
4347
self::assertStringContainsString('var recaptchaCallback_form_captcha', $view);
4448
self::assertStringContainsString("document.getElementById('form_captcha').value = token;", $view);
@@ -55,7 +59,11 @@ public function testHyphenConvertedToUnderscore()
5559
$view = $template->render(['form' => $form->createView()]);
5660

5761
//THEN
58-
self::assertStringContainsString('<input type="hidden" id="form_capt-cha" name="form[capt-cha]" />', $view);
62+
if (TestKernel::VERSION_ID >= 60400) {
63+
self::assertStringContainsString('<input type="hidden" id="form_capt-cha" name="form[capt-cha]">', $view);
64+
} else {
65+
self::assertStringContainsString('<input type="hidden" id="form_capt-cha" name="form[capt-cha]" />', $view);
66+
}
5967
self::assertStringContainsString('<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=key&hl=en&onload=recaptchaCallback_form_capt_cha" async defer nonce=""></script>', $view);
6068
self::assertStringContainsString('var recaptchaCallback_form_capt_cha', $view);
6169
self::assertStringContainsString("document.getElementById('form_capt-cha').value = token;", $view);
@@ -72,7 +80,11 @@ public function testFormJavascriptAbsent_ifDisabled()
7280
$view = $template->render(['form' => $form->createView()]);
7381

7482
//THEN
75-
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]" />', $view);
83+
if (TestKernel::VERSION_ID >= 60400) {
84+
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]">', $view);
85+
} else {
86+
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]" />', $view);
87+
}
7688
self::assertStringNotContainsString('<script src="https://www.google.com/recaptcha/api.js?render=key"></script>', $view);
7789
self::assertStringNotContainsString("document.getElementById('form_captcha').value = token;", $view);
7890
}
@@ -193,7 +205,11 @@ public function testFormJavascriptNoncePresent_ifSet()
193205
$view = $template->render(['form' => $form->createView()]);
194206

195207
//THEN
196-
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]" />', $view);
208+
if (TestKernel::VERSION_ID >= 60400) {
209+
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]">', $view);
210+
} else {
211+
self::assertStringContainsString('<input type="hidden" id="form_captcha" name="form[captcha]" />', $view);
212+
}
197213
self::assertStringContainsString('<script type="text/javascript" nonce="csp_nonce">', $view);
198214
self::assertStringContainsString('<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=key&hl=en&onload=recaptchaCallback_form_captcha" async defer nonce="csp_nonce"></script>', $view);
199215
self::assertStringContainsString('var recaptchaCallback_form_captcha', $view);

Tests/Validator/Constraints/Recaptcha3ValidatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3Validator;
99
use PHPUnit\Framework\MockObject\MockObject;
1010
use Symfony\Component\Validator\Constraint;
11+
use Symfony\Component\Validator\ConstraintValidatorInterface;
1112
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1213
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
1314

@@ -20,11 +21,12 @@ class Recaptcha3ValidatorTest extends ConstraintValidatorTestCase
2021

2122
public function setUp(): void
2223
{
23-
$this->resolver = $this->getMockBuilder(IpResolverInterface::class)->getMock();
24+
$this->resolver = $this->createMock(IpResolverInterface::class);
25+
2426
parent::setUp();
2527
}
2628

27-
protected function createValidator()
29+
protected function createValidator(): ConstraintValidatorInterface
2830
{
2931
$this->recaptcha = new RecaptchaMock();
3032
return new Recaptcha3Validator($this->recaptcha, $enabled = true, $this->resolver);

Tests/fixtures/config/symfony6.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
framework:
2+
http_method_override: false
23
session:
34
storage_factory_id: session.storage.factory.mock_file

Validator/Constraints/Recaptcha3.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ final class Recaptcha3 extends Constraint
1313
{
1414
const INVALID_FORMAT_ERROR = '7147ffdb-0af4-4f7a-bd5e-e9dcfa6d7a2d';
1515

16-
protected static $errorNames = [
16+
protected const ERROR_NAMES = [
1717
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
1818
];
1919

20+
protected static $errorNames = self::ERROR_NAMES;
21+
2022
public $message = 'Your computer or network may be sending automated queries';
2123
public $messageMissingValue = 'The captcha value is missing';
2224

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@
3737
"require": {
3838
"php": ">=7.1",
3939
"google/recaptcha": "^1.2",
40-
"symfony/form": "^3.4|^4.0|^5.0|^6.0",
41-
"symfony/framework-bundle": "^3.4.26|^4.2.7|^5.0|^6.0",
42-
"symfony/expression-language": "^3.4|^4.0|^5.0|^6.0",
43-
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0",
44-
"symfony/validator": "^3.4|^4.0|^5.0|^6.0",
45-
"symfony/twig-bundle": "^3.4|^4.0|^5.0|^6.0",
40+
"symfony/form": "^3.4|^4.0|^5.0|^6.0|^7.0",
41+
"symfony/framework-bundle": "^3.4.26|^4.2.7|^5.0|^6.0|^7.0",
42+
"symfony/expression-language": "^3.4|^4.0|^5.0|^6.0|^7.0",
43+
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0|^7.0",
44+
"symfony/validator": "^3.4|^4.0|^5.0|^6.0|^7.0",
45+
"symfony/twig-bundle": "^3.4|^4.0|^5.0|^6.0|^7.0",
4646
"twig/twig": "^2.9|^3.0"
4747
},
4848
"require-dev": {
4949
"phpunit/phpunit": "^7|^8|^9|^10",
50-
"symfony/http-client": "^4.3|^5.0|^6.0"
50+
"symfony/http-client": "^4.3|^5.0|^6.0|^7.0"
5151
},
5252
"autoload": {
5353
"psr-4": {

0 commit comments

Comments
 (0)