|
| 1 | +.. index:: |
| 2 | + single: Upgrading; Major Version |
| 3 | + |
| 4 | +Upgrading a Major Version (e.g. 2.7.0 to 3.0.0) |
| 5 | +=============================================== |
| 6 | + |
| 7 | +Every few years, Symfony releases a new major version release (the first number |
| 8 | +changes). These releases are the trickiest to upgrade, as they are allowed to |
| 9 | +contain BC breaks. However, Symfony tries to make this upgrade process as |
| 10 | +smooth as possible. |
| 11 | + |
| 12 | +This means that you can update most of your code before the major release is |
| 13 | +actually released. This is called making your code *future compatible*. |
| 14 | + |
| 15 | +There are a couple of steps to upgrading a major version: |
| 16 | + |
| 17 | +#. :ref:`Make your code deprecation free <upgrade-major-symfony-deprecations>`; |
| 18 | +#. :ref:`Update to the new major version via Composer <upgrade-major-symfony-composer>`. |
| 19 | +#. :ref:`Update your code to work with the new version <upgrade-major-symfony-after>` |
| 20 | + |
| 21 | +.. _upgrade-major-symfony-deprecations: |
| 22 | + |
| 23 | +1) Make your Code Deprecation Free |
| 24 | +---------------------------------- |
| 25 | + |
| 26 | +During the lifecycle of a major release, new features are added and method |
| 27 | +signatures and public API usages are changed. However, |
| 28 | +:doc:`minor versions </cookbook/upgrade/minor_version>` should not contain any |
| 29 | +backwards compatibility changes. To accomplish this, the "old" (e.g. functions, |
| 30 | +classes, etc) code still works, but is marked as *deprecated*, indicating that |
| 31 | +it will be removed/changed in the future and that you should stop using it. |
| 32 | + |
| 33 | +When the major version is released (e.g. 3.0.0), all deprecated features and |
| 34 | +functionality are removed. So, as long as you've updated your code to stop |
| 35 | +using these deprecated features in the last version before the major (e.g. |
| 36 | +2.8.*), you should be able to upgrade without a problem. |
| 37 | + |
| 38 | +To help you with this, the last minor releases will trigger deprecated notices. |
| 39 | +For example, 2.7 and 2.8 trigger deprecated notices. When visiting your |
| 40 | +application in the :doc:`dev environment </cookbook/configuration/environments>` |
| 41 | +in your browser, these notices are shown in the web dev toolbar: |
| 42 | + |
| 43 | +.. image:: /images/cookbook/deprecations-in-profiler.png |
| 44 | + |
| 45 | +Deprecations in PHPUnit |
| 46 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 47 | + |
| 48 | +By default, PHPUnit will handle deprecation notices as real errors. This means |
| 49 | +that all tests are aborted because it uses a BC layer. |
| 50 | + |
| 51 | +To make sure this doesn't happen, you can install the PHPUnit bridge: |
| 52 | + |
| 53 | +.. code-block:: bash |
| 54 | +
|
| 55 | + $ composer require symfony/phpunit-bridge |
| 56 | +
|
| 57 | +Now, your tests execute normally and a nice summary of the deprecation notices |
| 58 | +is displayed at the end of the test report: |
| 59 | + |
| 60 | +.. code-block:: text |
| 61 | +
|
| 62 | + $ phpunit |
| 63 | + ... |
| 64 | +
|
| 65 | + OK (10 tests, 20 assertions) |
| 66 | +
|
| 67 | + Remaining deprecation notices (6) |
| 68 | +
|
| 69 | + The "request" service is deprecated and will be removed in 3.0. Add a typehint for |
| 70 | + Symfony\Component\HttpFoundation\Request to your controller parameters to retrieve the |
| 71 | + request instead: 6x |
| 72 | + 3x in PageAdminTest::testPageShow from Symfony\Cmf\SimpleCmsBundle\Tests\WebTest\Admin |
| 73 | + 2x in PageAdminTest::testPageList from Symfony\Cmf\SimpleCmsBundle\Tests\WebTest\Admin |
| 74 | + 1x in PageAdminTest::testPageEdit from Symfony\Cmf\SimpleCmsBundle\Tests\WebTest\Admin |
| 75 | +
|
| 76 | +.. _upgrade-major-symfony-composer: |
| 77 | + |
| 78 | +2) Update to the New Major Version via Composer |
| 79 | +----------------------------------------------- |
| 80 | + |
| 81 | +If your code is deprecation free, you can update the Symfony library via |
| 82 | +Composer by modifying your ``composer.json`` file: |
| 83 | + |
| 84 | +.. code-block:: json |
| 85 | +
|
| 86 | + { |
| 87 | + "...": "...", |
| 88 | +
|
| 89 | + "require": { |
| 90 | + "symfony/symfony": "3.0.*", |
| 91 | + }, |
| 92 | + "...": "...", |
| 93 | + } |
| 94 | +
|
| 95 | +Next, use Composer to download new versions of the libraries: |
| 96 | + |
| 97 | +.. code-block:: bash |
| 98 | +
|
| 99 | + $ composer update symfony/symfony |
| 100 | +
|
| 101 | +.. include:: /cookbook/upgrade/_update_all_packages.rst.inc |
| 102 | + |
| 103 | +.. _upgrade-major-symfony-after: |
| 104 | + |
| 105 | +3) Update your Code to Work with the New Version |
| 106 | +------------------------------------------------ |
| 107 | + |
| 108 | +There is a good chance that you're done now! However, the next major version |
| 109 | +*may* also contain new BC breaks as a BC layer is not always a possibility. |
| 110 | +Make sure you read the ``UPGRADE-X.0.md`` (where X is the new major version) |
| 111 | +included in the Symfony repository for any BC break that you need to be aware |
| 112 | +of. |
0 commit comments