It is often the case when an application shows a Bug, not present in previous revisions, involving a function not really new but quite used.

So it may be useful to own the code revision history to search the exact moment, or Commit, when the regression was introduced. Git has a useful command for the purpose: "bisect". It searches, through a binary search algorithm, when a particular regression was introduced in the source code history. 

The command checks out the different moments of your code history, and you need to state the bisection tool if the bug was present in a given Commit. So the Bisect command is able to identify the exact moment when the bug was introduced, providing an exact image and all available information of the moment when the issue raised.

Particularly useful is the option to have an automated bug search via your test framework, PHPUnit in our case. In fact the following command

git bisect

runs a check script to verify if the code is OK, based upon the returned value. If the value returned by the script is 0, then the code is correct, otherwise it is bad.

For example, if you run PHPUnit Tests, they will return 0 value if all test cases are successful, 1 otherwise. So you only need to run the check via PHPUnit, specifying that you want to run only 1 Test, and you will have an automated regression search.

git bisect start 1.2.8 1.0.3
git bisect run bin/phpunit tests/Hotfix/OneTest.php

The first command states that you want to start a bisection process, where the 1.2.8 version of your code is considered Bad, while the 1.0.3 version of the same code is “Good”. So the Run command will execute a code Checkout at different points, running an automated code Test: in a few moments the system will indicate the first commit presenting the problem.

Comments

comments powered by Disqus

cloudparty

Follow Us