PHPUnit 8 released

PHP PHPUnit unit testing

PHPUnit version 8 was just released, so I've just updated my PHPUnit course to reflect the changes made in this latest version.

Here's a summary of the changes you need to be aware of:

  • When using the various fixture methods like setUp, tearDown, setUpBeforeClass etc., as you're overriding a method in the parent class, you now need to include the return value type hint to avoid an error:
protected function setUp(): void
  • The assertInternalType assertion has been removed. To assert that a value is of a certain PHP type, you can use the various assertIs* methods, for example assertIsInt, assertIsString etc. There's a full list of assertions in the PHPUnit documentation.

  • The annotations for expecting exceptions and their attributes have now been removed - so you can no longer use @expectedException in a DocBlock to test for exceptions being thrown. Instead, you need to use the expectException method inside the test method. (Using the annotations wasn't recommended anyway)

  • The various assertAttibute* methods (e.g. assertAttributeEquals) that you could use to check the value of a public, protected, or private attribute of a class or object have been removed. Now, if you want to check the value of a non-public attribute, you have to use reflection. This is covered in section 7 of the course.

A full list of the changes in PHPUnit 8 is in the PHPUnit 8 changelog.

All affected videos and source code resources have been updated to reflect all these changes.

Access the course here on Udemy!