PHPUnit 5 in PhpStorm 9.5

PHPUnit 5 has been released, and brings a number of improvements to the most widely used testing framework in PHP. All of the new features and improvements in PHPUnit 5 are supported by PhpStorm 9.5. Let’s take a look at what’s new!

PHPUnitThe big news is that PHPUnit 5 will no longer support versions of PHP lower than 5.6; but it will support PHP 7. This is great news for those who can push forward their PHP versions, but not such good news for those who are locked onto a specific version of PHP. PhpStorm 9.5 already fully supports PHP 5.6, and most PHP 7 features.

Features marked as deprecated in the latter releases of PHPUnit 4 have now been fully removed in 5. These include some assertions (SelectCountSelectRegExpSelectEqualsTagNotTag), some configuration relating to Selenium integration, and the --strict command line argument. Strict mode should now be invoked via a configuration file setting.

There have also been a number of improvements. The way @depends works has been changed – expectations for mock objects that are passed by @depends are evaluated in the test, which is useful in those places where you expect mocked methods to be called in every dependent test.

Tests marked as @small (the default for tests that aren’t size marked) can also be marked as risky if they perform I/O. This should help avoid tests timing out when they perform I/O as the default timeout for small tests is 1 second. Test failures can now be sorted in reverse, and most usefully, a new convenience method getMockWithoutInvokingTheOriginalConstructor was added to quickly create a test double without invoking the original constructor. This will be a useful addition since many developers will be creating mocks without the constructor in lots of tests.

A new --whitelist command line argument has been added which allows you to configure a whitelist of classes for code coverage analysis (using Xdebug).

Finally, a number of new assertions have been added:

  1. assertInfinite – checks that given value is infinite (see is_infinite)
  2. assertFinite – checks that the given value is a finite value (i.e. not infinite)
  3. assertNan – checks that the given value is not a number (see is_nan)

Support for all the new and improved features of PHPUnit 5 is already included in PhpStorm 9.5, and the team at PHPUnit have added a new test result logger into PHPUnit 5 that allows integration with PhpStorm to be even more seamless!

Develop with pleasure!
– JetBrains PhpStorm Team

About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature. Bookmark the permalink.