Upgrading PHPUnit To Version 6

c9s
c9s
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();

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade