From 699ae491ada0449c72ce83c8281446c344cfd61a Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Fri, 13 Dec 2024 00:34:22 +0100 Subject: [PATCH 1/4] Update dependencies --- assets/icons/symfony.svg | 1 + config/packages/csrf.yaml | 11 ++++++++++ symfony.lock | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 assets/icons/symfony.svg create mode 100644 config/packages/csrf.yaml diff --git a/assets/icons/symfony.svg b/assets/icons/symfony.svg new file mode 100644 index 000000000..93fb329cc --- /dev/null +++ b/assets/icons/symfony.svg @@ -0,0 +1 @@ + diff --git a/config/packages/csrf.yaml b/config/packages/csrf.yaml new file mode 100644 index 000000000..40d40405e --- /dev/null +++ b/config/packages/csrf.yaml @@ -0,0 +1,11 @@ +# Enable stateless CSRF protection for forms and logins/logouts +framework: + form: + csrf_protection: + token_id: submit + + csrf_protection: + stateless_token_ids: + - submit + - authenticate + - logout diff --git a/symfony.lock b/symfony.lock index a62528ae2..bcefff799 100644 --- a/symfony.lock +++ b/symfony.lock @@ -125,6 +125,37 @@ ".env" ] }, + "symfony/form": { + "version": "7.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "7.2", + "ref": "7d86a6723f4a623f59e2bf966b6aad2fc461d36b" + }, + "files": [ + "config/packages/csrf.yaml" + ] + }, + "symfony/framework-bundle": { + "version": "7.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "7.2", + "ref": "87bcf6f7c55201f345d8895deda46d2adbdbaa89" + }, + "files": [ + "config/packages/cache.yaml", + "config/packages/framework.yaml", + "config/preload.php", + "config/routes/framework.yaml", + "config/services.yaml", + "public/index.php", + "src/Controller/.gitignore", + "src/Kernel.php" + ] + }, "symfony/mailer": { "version": "7.2", "recipe": { @@ -239,6 +270,18 @@ "templates/base.html.twig" ] }, + "symfony/ux-icons": { + "version": "2.22", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "2.17", + "ref": "803a3bbd5893f9584969ab8670290cdfb6a0a5b5" + }, + "files": [ + "assets/icons/symfony.svg" + ] + }, "symfony/ux-live-component": { "version": "2.20", "recipe": { From 95c1cc0bcbf2fa791122575b1ac676983745894d Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Thu, 12 Dec 2024 17:08:28 +0100 Subject: [PATCH 2/4] Remove PhpunitBridge and install PHPunit 11 --- .github/workflows/lint.yaml | 4 ---- .github/workflows/tests.yaml | 11 +---------- .gitignore | 5 +++++ composer.json | 2 +- phpstan.neon.dist | 2 -- symfony.lock | 14 ++++++++++++++ 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d748c5969..0d93f4a37 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -58,10 +58,6 @@ jobs: - name: "Install dependencies" run: composer install --ansi --no-interaction --no-progress - - name: Install PHPUnit - id: install - run: vendor/bin/simple-phpunit install - - name: Lint YAML files if: always() && steps.install.outcome == 'success' run: ./bin/console lint:yaml config --parse-tags diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 3346852b4..c7ec70cc4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,9 +8,6 @@ on: env: fail-fast: true - PHPUNIT_FLAGS: "-v" - SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit" - SYMFONY_DEPRECATIONS_HELPER: 'max[indirect]=52' permissions: contents: read @@ -68,11 +65,5 @@ jobs: php bin/console sass:build php bin/console asset-map:compile - - name: "Install PHPUnit" - run: vendor/bin/simple-phpunit install - - - name: "PHPUnit version" - run: vendor/bin/simple-phpunit --version - - name: "Run tests" - run: vendor/bin/simple-phpunit ${{ env.PHPUNIT_FLAGS }} + run: bin/phpunit diff --git a/.gitignore b/.gitignore index 113ba2717..bf562e923 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,8 @@ ###> phpstan/phpstan ### phpstan.neon ###< phpstan/phpstan ### + +###> phpunit/phpunit ### +/phpunit.xml +.phpunit.result.cache +###< phpunit/phpunit ### diff --git a/composer.json b/composer.json index c0cad52e6..7fc61ad5a 100644 --- a/composer.json +++ b/composer.json @@ -58,11 +58,11 @@ "phpstan/phpstan": "^1.2", "phpstan/phpstan-doctrine": "^1.3", "phpstan/phpstan-symfony": "^1.2", + "phpunit/phpunit": "^11.3", "symfony/browser-kit": "^7", "symfony/css-selector": "^7", "symfony/debug-bundle": "^7", "symfony/maker-bundle": "^1.36", - "symfony/phpunit-bridge": "^7", "symfony/stopwatch": "^7", "symfony/web-profiler-bundle": "^7", "twbs/bootstrap": "^5" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5676dc5d6..58888bc58 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,8 +6,6 @@ parameters: paths: - src - tests - bootstrapFiles: - - vendor/bin/.phpunit/phpunit/vendor/autoload.php doctrine: objectManagerLoader: tests/object-manager.php symfony: diff --git a/symfony.lock b/symfony.lock index bcefff799..6af16e9a9 100644 --- a/symfony.lock +++ b/symfony.lock @@ -62,6 +62,20 @@ "phpstan.dist.neon" ] }, + "phpunit/phpunit": { + "version": "11.5", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "9.6", + "ref": "7364a21d87e658eb363c5020c072ecfdc12e2326" + }, + "files": [ + ".env.test", + "phpunit.xml.dist", + "tests/bootstrap.php" + ] + }, "symfony/apache-pack": { "version": "1.0", "recipe": { From f714211285eaf078c8704ae64db96ecc6cb6de06 Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Fri, 13 Dec 2024 00:32:35 +0100 Subject: [PATCH 3/4] Update code for PHPUnit 11 --- phpunit.xml.dist | 27 ++++++++----------- ...ndTest.php => AbstractCommandTestCase.php} | 2 +- tests/Command/AddUserCommandTest.php | 14 +++++----- tests/Command/ListUsersCommandTest.php | 8 +++--- tests/Controller/Admin/BlogControllerTest.php | 7 +++-- tests/Controller/DefaultControllerTest.php | 11 ++++---- tests/Controller/UserControllerTest.php | 7 +++-- 7 files changed, 34 insertions(+), 42 deletions(-) rename tests/Command/{AbstractCommandTest.php => AbstractCommandTestCase.php} (96%) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1eeeb906b..fed3d0109 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,20 +1,18 @@ - + - - - - - - + + + + @@ -23,22 +21,19 @@ - + src - - - - + - + - + diff --git a/tests/Command/AbstractCommandTest.php b/tests/Command/AbstractCommandTestCase.php similarity index 96% rename from tests/Command/AbstractCommandTest.php rename to tests/Command/AbstractCommandTestCase.php index 4777376bf..b2f279336 100644 --- a/tests/Command/AbstractCommandTest.php +++ b/tests/Command/AbstractCommandTestCase.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -abstract class AbstractCommandTest extends KernelTestCase +abstract class AbstractCommandTestCase extends KernelTestCase { /** * This helper method abstracts the boilerplate code needed to test the diff --git a/tests/Command/AddUserCommandTest.php b/tests/Command/AddUserCommandTest.php index 240c2497e..d8f20e2a9 100644 --- a/tests/Command/AddUserCommandTest.php +++ b/tests/Command/AddUserCommandTest.php @@ -13,9 +13,10 @@ use App\Command\AddUserCommand; use App\Repository\UserRepository; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; -final class AddUserCommandTest extends AbstractCommandTest +final class AddUserCommandTest extends AbstractCommandTestCase { /** * @var string[] @@ -35,11 +36,10 @@ protected function setUp(): void } /** - * @dataProvider isAdminDataProvider - * * This test provides all the arguments required by the command, so the * command runs non-interactively and it won't ask for any argument. */ + #[DataProvider('isAdminDataProvider')] public function testCreateUserNonInteractive(bool $isAdmin): void { $input = $this->userData; @@ -52,13 +52,13 @@ public function testCreateUserNonInteractive(bool $isAdmin): void } /** - * @dataProvider isAdminDataProvider - * * This test doesn't provide all the arguments required by the command, so * the command runs interactively and it will ask for the value of the missing * arguments. - * See https://symfony.com/doc/current/components/console/helpers/questionhelper.html#testing-a-command-that-expects-input + * + * @see https://symfony.com/doc/current/components/console/helpers/questionhelper.html#testing-a-command-that-expects-input */ + #[DataProvider('isAdminDataProvider')] public function testCreateUserInteractive(bool $isAdmin): void { $this->executeCommand( @@ -76,7 +76,7 @@ public function testCreateUserInteractive(bool $isAdmin): void * This is used to execute the same test twice: first for normal users * (isAdmin = false) and then for admin users (isAdmin = true). */ - public function isAdminDataProvider(): \Generator + public static function isAdminDataProvider(): \Generator { yield [false]; yield [true]; diff --git a/tests/Command/ListUsersCommandTest.php b/tests/Command/ListUsersCommandTest.php index 78fb50951..4726901b8 100644 --- a/tests/Command/ListUsersCommandTest.php +++ b/tests/Command/ListUsersCommandTest.php @@ -12,14 +12,14 @@ namespace App\Tests\Command; use App\Command\ListUsersCommand; +use PHPUnit\Framework\Attributes\DataProvider; -final class ListUsersCommandTest extends AbstractCommandTest +final class ListUsersCommandTest extends AbstractCommandTestCase { /** - * @dataProvider maxResultsProvider - * * This test verifies the amount of data is right according to the given parameter max results. */ + #[DataProvider('maxResultsProvider')] public function testListUsers(int $maxResults): void { $tester = $this->executeCommand( @@ -30,7 +30,7 @@ public function testListUsers(int $maxResults): void $this->assertSame($emptyDisplayLines + $maxResults, mb_substr_count($tester->getDisplay(), "\n")); } - public function maxResultsProvider(): \Generator + public static function maxResultsProvider(): \Generator { yield [1]; yield [2]; diff --git a/tests/Controller/Admin/BlogControllerTest.php b/tests/Controller/Admin/BlogControllerTest.php index 7f3618da2..3714b7df5 100644 --- a/tests/Controller/Admin/BlogControllerTest.php +++ b/tests/Controller/Admin/BlogControllerTest.php @@ -14,6 +14,7 @@ use App\Entity\User; use App\Repository\PostRepository; use App\Repository\UserRepository; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\Response; @@ -49,9 +50,7 @@ protected function setUp(): void $this->client->loginUser($user); } - /** - * @dataProvider getUrlsForRegularUsers - */ + #[DataProvider('getUrlsForRegularUsers')] public function testAccessDeniedForRegularUsers(string $httpMethod, string $url): void { $this->client->getCookieJar()->clear(); @@ -67,7 +66,7 @@ public function testAccessDeniedForRegularUsers(string $httpMethod, string $url) $this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN); } - public function getUrlsForRegularUsers(): \Generator + public static function getUrlsForRegularUsers(): \Generator { yield ['GET', '/en/admin/post/']; yield ['GET', '/en/admin/post/1']; diff --git a/tests/Controller/DefaultControllerTest.php b/tests/Controller/DefaultControllerTest.php index 0aa01bacd..2d5573d75 100644 --- a/tests/Controller/DefaultControllerTest.php +++ b/tests/Controller/DefaultControllerTest.php @@ -13,6 +13,7 @@ use App\Entity\Post; use Doctrine\Bundle\DoctrineBundle\Registry; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\Response; @@ -32,9 +33,8 @@ final class DefaultControllerTest extends WebTestCase * PHPUnit's data providers allow to execute the same tests repeated times * using a different set of data each time. * See https://symfony.com/doc/current/testing.html#testing-against-different-sets-of-data. - * - * @dataProvider getPublicUrls */ + #[DataProvider('getPublicUrls')] public function testPublicUrls(string $url): void { $client = static::createClient(); @@ -69,9 +69,8 @@ public function testPublicBlogPost(): void * The application contains a lot of secure URLs which shouldn't be * publicly accessible. This tests ensures that whenever a user tries to * access one of those pages, a redirection to the login form is performed. - * - * @dataProvider getSecureUrls */ + #[DataProvider('getSecureUrls')] public function testSecureUrls(string $url): void { $client = static::createClient(); @@ -84,14 +83,14 @@ public function testSecureUrls(string $url): void ); } - public function getPublicUrls(): \Generator + public static function getPublicUrls(): \Generator { yield ['/']; yield ['/en/blog/']; yield ['/en/login']; } - public function getSecureUrls(): \Generator + public static function getSecureUrls(): \Generator { yield ['/en/admin/post/']; yield ['/en/admin/post/new']; diff --git a/tests/Controller/UserControllerTest.php b/tests/Controller/UserControllerTest.php index 5ec58d0f6..bd729f32c 100644 --- a/tests/Controller/UserControllerTest.php +++ b/tests/Controller/UserControllerTest.php @@ -13,6 +13,7 @@ use App\Entity\User; use App\Repository\UserRepository; +use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\Response; @@ -33,9 +34,7 @@ */ final class UserControllerTest extends WebTestCase { - /** - * @dataProvider getUrlsForAnonymousUsers - */ + #[DataProvider('getUrlsForAnonymousUsers')] public function testAccessDeniedForAnonymousUsers(string $httpMethod, string $url): void { $client = static::createClient(); @@ -48,7 +47,7 @@ public function testAccessDeniedForAnonymousUsers(string $httpMethod, string $ur ); } - public function getUrlsForAnonymousUsers(): \Generator + public static function getUrlsForAnonymousUsers(): \Generator { yield ['GET', '/en/profile/edit']; yield ['GET', '/en/profile/change-password']; From 716299109554076b4289517d135b7a0e86131885 Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Fri, 13 Dec 2024 00:33:02 +0100 Subject: [PATCH 4/4] Fail on direct deprecations --- phpunit.xml.dist | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fed3d0109..4bebe2cc4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ - + src + + trigger_deprecation + Doctrine\Deprecations\Deprecation::trigger + Doctrine\Deprecations\Deprecation::delegateTriggerToBackend +