Skip to content

WIP: phpunit 7 upgrade

Robert Sinton requested to merge experiment/phpunit_7_upgrade into master

This MR is more of a basis for discussion for now, due to issues noted below. Not sure what would really be required around zon-core changes in order for any given solution to use phpunit 7.

What I did

  • Updated example project (Art Money, branch experiment/phpunit_upgrade) to use phpunit 7.x, dbunit 4.x
  • Updated zon-core to use phpunit 7.x, dbunit 4.x (see notes below)
  • In example project, replaced use of class name PHPUnit_Framework_TestCase in test suites with the newer, required, PHPUnit\Framework\TestCase
  • In example project, removed code coverage blacklist (no longer supported) and replaced with suggested whitelist.

Implications

  • Two of Art Money's test suites were written to extend zon-core's Zon\Core\Tests\Zon_Database_TestCase classs, but I don't think they were making use of it. Is it to do with supporting a different method of data loading? In any case, that class depends on dbunit, which is apparently no longer being maintained and no longer supported by phpunit. Would be keen to discuss. In the meantime I have made those test suites extend the standard phpunit TestCase class instead, and they work fine.

  • I originally updated zon-core's version of phpunit because of an error message that led me to find that the SebastianBergmann\Environment\Runtime class from zon-core was being used, causing an error because of the version mismatch with the newer phpunit version in the main project. Later I thought that this error would probably have been because of the use of Zon\Core\Tests\Zon_Database_TestCase as mentioned above. So after changing those suites to use the standard phpunit TestCase class I tried reverting to the standard zon-core (and running composer update in site/application/zon to revert back to earlier versions). This time I encountered a different problem:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to PHPUnit\Runner\BaseTestRunner::getTest() must be of the type string, object given, called in /var/www/vhosts/artmoney.dev/htdocs/www/site/_composer/phpunit/phpunit/src/TextUI/Command.php on line 183 and defined in /var/www/vhosts/artmoney.dev/htdocs/www/site/_composer/phpunit/phpunit/src/Runner/BaseTestRunner.php:59
Stack trace:
#0 /var/www/vhosts/artmoney.dev/htdocs/www/site/_composer/phpunit/phpunit/src/TextUI/Command.php(183): PHPUnit\Runner\BaseTestRunner->getTest(Object(PHPUnit\Framework\TestSuite), '', Array)
#1 /var/www/vhosts/artmoney.dev/htdocs/www/site/_composer/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#2 /var/www/vhosts/artmoney.dev/htdocs/www/site/_composer/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#3 {main}
  thrown in /var/www/vhosts/artmoney.dev/htdocs/www/site/_composer/phpunit/phpunit/src/Runner/BaseTestRunner.php on line 59
  • A later observation on the above: I also tried removing phpunit from zon-core altogether, and the entire AM project suite ran fine.

  • Before changing the Art Money classes to just use the standard phpunit TestCase class as mentioned above, I found that I needed to update their setUp() methods' definitions, to include a : void return type constraint, due to that being the case in the definition in the later version of dbunit.

Setup

composer update

How to test

  • Code review of commits in both this zon-core branch, and the Art Money branch experiment/phpunit_upgrade
  • Run test suites, e.g. all tests in that Art Money repo branch, commit fe35ca6a6dd10661a3196bc6ab8d9b448f6dc02c.
    • Note that you should expect 4 test failures in that branch, with reports of 201 errors, unless your IP is on the permitted-queriers whitelist for Art Money's Transunion account.
Edited by Robert Sinton

Merge request reports