Background: It is often the case that our project has dependencies under development. If a new version of a dependency is released on packagist and introduces a BC break that you are not aware of then things can happen. You don’t want to become aware of this problems after you deploy!
Breaks of your application due to these dependency BC breaks can be detected writing good integration tests. In addition, you want to find out when these BC breaks were introduced and lock your good versions right before.
Here we show you an example on how to tackle this problem. We will use a silex app called Fazer with with a package dependency found in packagist, namely TodoList (cordoval/todolist).
First instantiate the project:
composer create-project cordoval/fazer /path/to/project/fazer cd /path/to/project/fazer ~/path/to/project/fazer$
Second copy bisect.sh script to a location outside of the project. The reason why copying the latest version is that you may have versioned this script and earlier versions could be different. To measure whether a version is good or not we need a fix standard rather than a moving target.
~/path/to/project/fazer$ cp bisect.sh ../bisect.sh
Next, start the BC detection:
~/path/to/project/fazer$ git bisect start ~/path/to/project/fazer$
Next mark the current commit as bad (project shows already broken == tests fail):
~/path/to/project/fazer$ git bisect bad
Next mark the last known good commit (using good criteria and memory):
~/path/to/project/fazer$ git bisect good ee55ec2
Next run the script to bisect and find the last good commit right before the BC dependency break:
~/path/to/project/fazer$ git bisect run ../bisect.sh
The script bisect.sh will install cleanly the dependency versions at the time the commit was current in order to find when was the last time that everything worked ok. It will use composer for this and will run after every install the tests provided as shown here:
rm -rf vendor rm composer.lock composer install phpunit -c phpunit.xml.dist
The process will start:
running ../bisect.sh Installing dependencies - Installing pimple/pimple (dev-master) Cloning 86cae5c9e85cd02f1703c774ddf12f2448a5938c ... PHPUnit 3.6.4 by Sebastian Bergmann. Configuration read from /home/cordoval/sites-2/fazer/phpunit.xml.dist . Time: 0 seconds, Memory: 5.25Mb OK (1 test, 2 assertions) Bisecting: 0 revisions left to test after this (roughly 0 steps)
And will finish finding the last good commit:
running ../bisect.sh Installing dependencies - Installing pimple/pimple (dev-master) Cloning 86cae5c9e85cd02f1703c774ddf12f2448a5938c ... PHPUnit 3.6.4 by Sebastian Bergmann. Configuration read from /home/cordoval/sites-2/fazer/phpunit.xml.dist E Time: 0 seconds, Memory: 4.75Mb There was 1 error: 1) Fazer\Tests\FazerTest::testBisect Missing argument 2 for Fazer\TodoList::__construct(), called in /home/cordoval/sites-2/fazer/src/controllers.php on line 36 and defined ... FAILURES! Tests: 1, Assertions: 0, Errors: 1. 9235d39bdeb0317d4f098bb4f8300f0a7f4e2920 is the first bad commit commit 9235d39bdeb0317d4f098bb4f8300f0a7f4e2920 Author: Luis Cordova <firstname.lastname@example.org> Date: Sat Jun 30 16:52:21 2012 -0500 update vendors :100644 100644 42534fd95ab08a782f1df71af131a00f515f2427 c8aed6e4d61aae84b8e8693f348fbb6519f85941 M composer.json bisect run success
Finally issue a `bisect reset` to go back to your former branch and continue work to do the corresponding fixes.
If you have reached this far, congratulations! I hope it was useful.
I thank the Lord Jesus for His undeserved grace given to me so far for enjoying leaning these things. Thanks Raul for hanging out.
Again if you would like to support me to attend symfonyLive event on San Francisco and this blog post has helped you please do consider donating towards the fund raising of $1800 for the air ticket.
I would really appreciate your help!
More blog posts coming! Please tweet to your friends and spread the word!