Upgrading to CakePHP 3.7.0

With the release of CakePHP 3.7.0 quickly approaching, I wanted to help validate the release candidates by upgrading a few of my sites and seeing how much work it was. I’d like to share the process I followed for my upgrades on Stickler CI, this site and a few others I maintain.

Read the Upgrade Guide

My first step in any upgrade is to read the release notes. Thankfully CakePHP publishes a pretty thorough migration guide which covers all the deprecations and new features.

Upgrade CakePHP

Next step is to update CakePHP. I’ll often use the development head so that I can easily update to the latest code if any fixes are made during the release candidates:

Show Plain Text
  1. php composer.phar require --update-with-dependencies "cakephp/cakephp:3.next-dev as 3.7.0"

This should bump up CakePHP. To fix several deprecation warnings you can also run:

Show Plain Text
  1. php composer.phar update cakephp/bake
  2. php composer.phar update cakephp/debug_kit

Update Deprecations and Fixture references

I then start running my test suites and fixing all the deprecation warnings that come up. When updating Stickler-CI I was having problems with my test suites crashing due to ‘duplicate index’ errors. I was able to solve this by normalizing all my fixture references to be CamelCased. For example:

Show Plain Text
  1. public $fixtures = [
  2.     'app.users',
  3.     'app.repositories_users',
  4. ];

Had to become:

Show Plain Text
  1. public $fixtures = [
  2.     'app.Users',
  3.     'app.RepositoriesUsers',
  4. ];

I was fortunate that my applications didn’t use many of the deprecated methods/features making my upgrade relatively simple. Updating Stickler which is ~10Kloc took one hour which feels very reasonable to me.

Comments

How do you deal with beforeDispatch in DispatchFilter , it was deprecated and Middleware is recommended to use instead. Howerver I’m was looking for an equivalent, in middleware but I really don’t know where to start. and I’m dealing trying to adapt your example “Using CakePHP and a Horizontally Sharded Database”

Agustin on 3/5/19

Agustin: I would make the shard selection into middleware. You would perform the shard selection logic before passing onto the @next@ middleware layer.

mark story on 5/18/19

Have your say: