Skip to content

Commit

Permalink
feature #1217 Upgrade to Symfony 5.3 (javiereguiluz, nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the main branch.

Discussion
----------

Upgrade to Symfony 5.3

For now, it's Symfony 5.3 RC1, but we'll keep updating this branch until 5.3 stable.

-----

Things that I found while upgrading:

### Missing UPGRADE guide entry?

In the UPGRADE guide (https://github.com/symfony/symfony/blob/5.3/UPGRADE-5.3.md) we don't even mention `enable_csrf`, but this change is needed in `config/packages/security.yaml`:

Replace this:

```yaml
form_login:
    csrf_token_generator: security.csrf.token_manager
```

by this:

```yaml
form_login:
    enable_csrf: true
```

-----

### Unexpected failures

The upgrade guide mentions this:

```
PropertyInfo:

Deprecated the Type::getCollectionKeyType() and Type::getCollectionValueType() methods,
use Type::getCollectionKeyTypes() and Type::getCollectionValueTypes() instead
```

But we have these test failures:

```

App\Tests\Controller\Admin\BlogControllerTest::testAdminNewPost
Error: Call to undefined method Symfony\Component\PropertyInfo\Type::getCollectionValueTypes()

demo/vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php:122
demo/vendor/symfony/validator/Mapping/Loader/LoaderChain.php:54
demo/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php:101
demo/vendor/symfony/validator/Validator/RecursiveValidator.php:76
demo/vendor/symfony/validator/Validator/TraceableValidator.php:50
demo/vendor/symfony/form/Extension/Validator/ValidatorTypeGuesser.php:265
demo/vendor/symfony/form/Extension/Validator/ValidatorTypeGuesser.php:38
demo/vendor/symfony/form/FormTypeGuesserChain.php:47
demo/vendor/symfony/form/FormTypeGuesserChain.php:93
demo/vendor/symfony/form/FormTypeGuesserChain.php:48
demo/vendor/symfony/form/FormFactory.php:84
demo/vendor/symfony/form/FormBuilder.php:97
demo/vendor/symfony/form/FormBuilder.php:244
demo/vendor/symfony/form/FormBuilder.php:195
demo/vendor/symfony/form/FormFactory.php:28
demo/vendor/symfony/framework-bundle/Controller/AbstractController.php:359
demo/src/Controller/Admin/BlogController.php:78
demo/vendor/symfony/http-kernel/HttpKernel.php:157
demo/vendor/symfony/http-kernel/HttpKernel.php:79
demo/vendor/symfony/http-kernel/Kernel.php:196
demo/vendor/symfony/http-kernel/HttpKernelBrowser.php:63
demo/vendor/symfony/framework-bundle/KernelBrowser.php:159
demo/vendor/symfony/browser-kit/AbstractBrowser.php:402
demo/tests/Controller/Admin/BlogControllerTest.php:89
```

-----

### Unexpected direct deprecations

I see the following "direct deprecation" notices, but I don't know how they can be "direct deprecations". We don't use any of these in our code:

```
Remaining direct deprecation notices (7)

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\SodiumPasswordHasher" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface" class is deprecated, use "Symfony\Component\PasswordHasher\PasswordHasherInterface" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\SelfSaltingEncoderInterface" interface is deprecated, use "Symfony\Component\PasswordHasher\LegacyPasswordHasherInterface" on hasher implementations that deal with salts instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\Pbkdf2PasswordHasher" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\BasePasswordEncoder" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\CheckPasswordLengthTrait" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\MigratingPasswordEncoder" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\MigratingPasswordHasher" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command
```

-----

### Indirect deprecations to fix?

There are still these "indirect deprecations". Are we missing some dependency updates ... or are these really deprecations pending to be fixed?

```
Remaining indirect deprecation notices (24)

  19x: Since symfony/security-core 5.3: Not implementing method "loadUserByIdentifier()" in user provider "Symfony\Bridge\Doctrine\Security\User\EntityUserProvider" is deprecated. This method will replace "loadUserByUsername()" in Symfony 6.0.
    4x in BlogControllerTest::testAccessDeniedForRegularUsers from App\Tests\Controller\Admin
    4x in BlogControllerTest::testNewComment from App\Tests\Controller
    2x in BlogControllerTest::testAdminDeletePost from App\Tests\Controller\Admin
    2x in UserControllerTest::testEditUser from App\Tests\Controller
    2x in UserControllerTest::testChangePassword from App\Tests\Controller
    1x in BlogControllerTest::testAdminBackendHomePage from App\Tests\Controller\Admin
    1x in BlogControllerTest::testAdminNewPost from App\Tests\Controller\Admin
    1x in BlogControllerTest::testAdminNewDuplicatedPost from App\Tests\Controller\Admin
    1x in BlogControllerTest::testAdminShowPost from App\Tests\Controller\Admin
    1x in BlogControllerTest::testAdminEditPost from App\Tests\Controller\Admin

  4x: Since symfony/http-foundation 5.3: "Symfony\Component\HttpFoundation\RequestStack::getMasterRequest()" is deprecated, use "getMainRequest()" instead.
    4x in BlogControllerTest::testAccessDeniedForRegularUsers from App\Tests\Controller\Admin

  1x: The "DAMA\DoctrineTestBundle\Doctrine\DBAL\AbstractStaticDriverV2" class implements "Doctrine\DBAL\Driver\ExceptionConverterDriver" that is deprecated.
    1x in PHPUnitExtension::executeBeforeFirstTest from DAMA\DoctrineTestBundle\PHPUnit

Other deprecation notices (18)

  7x: Since symfony/security-bundle 5.3: The "security.password_encoder" service is deprecated, use "security.user_password_hasher" instead.
    2x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command
    2x in AddUserCommandTest::testCreateUserInteractive from App\Tests\Command
    2x in UserControllerTest::testChangePassword from App\Tests\Controller
    1x in UserControllerTest::testAccessDeniedForAnonymousUsers from App\Tests\Controller

  7x: Since symfony/security-bundle 5.3: The "security.encoder_factory.generic" service is deprecated, use "security.password_hasher_factory" instead.
    2x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command
    2x in AddUserCommandTest::testCreateUserInteractive from App\Tests\Command
    2x in UserControllerTest::testChangePassword from App\Tests\Controller
    1x in UserControllerTest::testAccessDeniedForAnonymousUsers from App\Tests\Controller

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\UserPasswordEncoder" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface" interface is deprecated, use "Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\EncoderFactory" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command

  1x: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface" class is deprecated, use "Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface" instead.
    1x in AddUserCommandTest::testCreateUserNonInteractive from App\Tests\Command
```

Commits
-------

2a9c975 Serializable is banned
58822bd composer up
b0f5db5 Update assets/
cfeb771 Update code for 5.3
a410db9 Better constraints
b6d91b2 Removed most deprecations
997ce81 Updated to Symfony 5.3 RC1
  • Loading branch information
javiereguiluz committed Jun 2, 2021
2 parents 4b8f9fa + 2a9c975 commit 6b03342
Show file tree
Hide file tree
Showing 105 changed files with 2,893 additions and 2,882 deletions.
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ APP_SECRET=2ca64f8d83b9e89f5f19d672841d6bb8

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a MySQL database, use: "mysql://db_user:[email protected]:3306/db_name"
# For a PostgreSQL database, use: "postgresql://db_user:[email protected]:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
DATABASE_URL=sqlite:///%kernel.project_dir%/data/database.sqlite
# DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7",
# DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
DATABASE_URL=sqlite:///%kernel.project_dir%/data/database_test.sqlite
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- name: "Composer install"
id: install
run: composer install --no-interaction --no-progress --no-scripts
run: composer install --no-interaction --no-progress

- name: Lint YAML files
if: always() && steps.install.outcome == 'success'
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin.js → assets/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../scss/admin.scss';
import './styles/admin.scss';
import 'eonasdan-bootstrap-datetimepicker';
import 'typeahead.js';
import Bloodhound from "bloodhound-js";
Expand Down
9 changes: 6 additions & 3 deletions assets/js/app.js → assets/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../scss/app.scss';
import './styles/app.scss';

// loads the Bootstrap jQuery plugins
import 'bootstrap-sass/assets/javascripts/bootstrap/transition.js';
Expand All @@ -9,7 +9,10 @@ import 'bootstrap-sass/assets/javascripts/bootstrap/modal.js';
import 'jquery'

// loads the code syntax highlighting library
import './highlight.js';
import './js/highlight.js';

// Creates links to the Symfony documentation
import './doclinks.js';
import './js/doclinks.js';

// start the Stimulus application
import './bootstrap';
11 changes: 11 additions & 0 deletions assets/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { startStimulusApp } from '@symfony/stimulus-bridge';

// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.(j|t)sx?$/
));

// register any custom, 3rd party controllers here
// app.register('some_controller_name', SomeImportedController);
4 changes: 4 additions & 0 deletions assets/controllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"controllers": [],
"entrypoints": []
}
Empty file added assets/controllers/.gitignore
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion assets/js/search.js → assets/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './jquery.instantSearch.js';
import './js/jquery.instantSearch.js';

$(function() {
$('.search-field')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 7 additions & 33 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,15 @@

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;

if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

set_time_limit(0);
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

require dirname(__DIR__).'/vendor/autoload.php';
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
return new Application($kernel);
};
19 changes: 11 additions & 8 deletions bin/phpunit
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env php
<?php
if (file_exists(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
} else {
if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}
if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}

if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
42 changes: 22 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license": "MIT",
"type": "project",
"description": "Symfony Demo Application",
"minimum-stability": "stable",
"minimum-stability": "dev",
"prefer-stable": true,
"replace": {
"symfony/polyfill-php72": "*",
Expand All @@ -19,38 +19,39 @@
"erusev/parsedown": "^1.6",
"sensio/framework-extra-bundle": "^6.1",
"symfony/apache-pack": "^1.0",
"symfony/asset": "^5.2",
"symfony/console": "^5.2",
"symfony/dotenv": "^5.2",
"symfony/expression-language": "^5.2",
"symfony/asset": "^5.3",
"symfony/console": "^5.3",
"symfony/dotenv": "^5.3",
"symfony/expression-language": "^5.3",
"symfony/flex": "^1.1",
"symfony/form": "^5.2",
"symfony/framework-bundle": "^5.2",
"symfony/intl": "^5.2",
"symfony/mailer": "^5.2",
"symfony/form": "^5.3",
"symfony/framework-bundle": "^5.3",
"symfony/intl": "^5.3",
"symfony/mailer": "^5.3",
"symfony/monolog-bundle": "^3.1",
"symfony/polyfill-intl-messageformatter": "^1.12",
"symfony/security-bundle": "^5.2",
"symfony/string": "^5.2",
"symfony/translation": "^5.2",
"symfony/security-bundle": "^5.3",
"symfony/runtime": "^5.3",
"symfony/string": "^5.3",
"symfony/translation": "^5.3",
"symfony/twig-pack": "^1.0",
"symfony/validator": "^5.2",
"symfony/validator": "^5.3",
"symfony/webpack-encore-bundle": "^1.4",
"symfony/yaml": "^5.2",
"symfony/yaml": "^5.3",
"tgalopin/html-sanitizer-bundle": "^1.2",
"twig/intl-extra": "^3.0",
"twig/markdown-extra": "^3.0"
},
"require-dev": {
"dama/doctrine-test-bundle": "^6.2",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/browser-kit": "^5.2",
"symfony/css-selector": "^5.2",
"symfony/debug-bundle": "^5.2",
"symfony/browser-kit": "^5.3",
"symfony/css-selector": "^5.3",
"symfony/debug-bundle": "^5.3",
"symfony/maker-bundle": "^1.11",
"symfony/phpunit-bridge": "^5.2",
"symfony/stopwatch": "^5.2",
"symfony/web-profiler-bundle": "^5.2"
"symfony/phpunit-bridge": "^5.3",
"symfony/stopwatch": "^5.3",
"symfony/web-profiler-bundle": "^5.3"
},
"config": {
"platform": {
Expand Down Expand Up @@ -88,6 +89,7 @@
},
"extra": {
"symfony": {
"require": "5.3.*",
"allow-contrib": true
}
}
Expand Down
Loading

0 comments on commit 6b03342

Please sign in to comment.