Upgrading PHPUnit To Version 6
Jul 23, 2017 · 1 min read
Here are some quick tricks for fixing the phpunit test cases in your project.
Replace TestCase Class names
I usually run a small perl script to fix the class names:
find src -type f -iname "*.php" | xargs -I{} perl -i -pe 's/PHPUnit_Framework_TestCase/PHPUnit\\Framework\\TestCase/g' {}Call to undefined ::setExpectedException
This was deprecated and removed in phpunit6, simply replace it with “expectException” will fix this issue.
Call to undefined method ::getMock
If you were upgrading phpunit to version6 and encountered this error, simply replace your “getMock()” with “getMockBuilder()” + “getMock()”, e.g.,
$foo = $this->getMockBuilder('\Foo')
->getMock();