Page MenuHomeDevCentral

Migrate tests to PHPUnit 8
Closed, ResolvedPublic

Description

PHPUnit classes are now in namespaces

The migration is generally a straightforward class replacement (they are now sorted in namespace):

$ find . -type f -name '*.php' | xargs -n 1 gsed -i 's@PHPUnitFrameworkTestCase@PHPUnit\\Framework\\TestCase@g';

Global state

But for the notifications center, we could need to check the global state:

Global State

Starting with PHPUnit 6, the global and super-global variables are no longer backed up before and restored after each test by default. In general, this functionality is not required for clean, modern, object-oriented PHP code. This functionality slows down the execution of the test suite and increases memory usage.

Simply use the --globals-backup commandline option or set backupGlobals="true" in your XML configuration file to enable the backup of global and super-global variables before each test and their restoring after each test.

Exceptions

Furthermore, the best practice to test exceptions has been shifted from @expectedException annotations to expectEception() method.

Reference: https://thephp.cc/news/2016/02/questioning-phpunit-best-practices

Related Objects

Event Timeline

dereckson renamed this task from Migrate tests to PHPUnit 6 to Migrate tests to PHPUnit 6/7.Mar 23 2018, 00:07
dereckson renamed this task from Migrate tests to PHPUnit 6/7 to Migrate tests to PHPUnit 8.Jan 13 2020, 01:46

The migration is generally a straightforward class replacement (they are now sorted in namespace)

Our tests classes actually extend Nasqueron\Notifications\Tests\TestCase,
which extends Illuminate\Foundation\Testing\TestCase.

Enjoy vertical inheritance instead of horizontal composition.