Official CakePHP Upgrade Tool
As CakePHP Book states, CakePHP 4 adopts strict mode and uses more typehinting, there are many backwards incompatible changes concerning method signatures and file renames. To help expedite fixing these changes the team have implemented an upgrade CLI tool.
# Install the upgrade tool
git clone https://github.com/cakephp/upgrade.git
cd upgrade
git checkout 4.x
composer install --no-dev
Renaming Locales and Templates
Now we have the tool installed we can rename locales
and templates
files in our app:
# Rename locale files
bin/cake upgrade file_rename locales <path/to/app>
# Rename template files
bin/cake upgrade file_rename templates <path/to/app>
Note: Execute those commands for each internal plugin in the plugins
folder.
Rector Refactorings
The next step with Upgrade Tool is applying rector refactorings to fix deprecations.
bin/cake upgrade rector --verbose --rules phpunit80 <path/to/app/tests>
bin/cake upgrade rector --verbose --rules cakephp40 <path/to/app/src>
Sometimes you will get an error running these commands. Fix them manually in the specific files and run them again.
Congratulations! We are ready with upgrade tool.