Page MenuHomePhabricator

ComposerPhpunitXmlCoverageEdit is broken on PHPUnit 9
Closed, ResolvedPublic

Description

$ composer phpunit:coverage-edit -- extensions/CodeReview
> ComposerPhpunitXmlCoverageEdit::onEvent

In ComposerPhpunitXmlCoverageEdit.php line 40:
                                                         
  [Error]                                                
  Call to undefined method PHPUnit\Util\Xml::loadFile()  
                                                         

Exception trace:
  at /var/www/wiki/mediawiki/core/includes/composer/ComposerPhpunitXmlCoverageEdit.php:40
 ComposerPhpunitXmlCoverageEdit::onEvent() at phar:///usr/local/bin/composer-2/src/Composer/EventDispatcher/EventDispatcher.php:391
 Composer\EventDispatcher\EventDispatcher->executeEventPhpScript() at phar:///usr/local/bin/composer-2/src/Composer/EventDispatcher/EventDispatcher.php:248
 Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer-2/src/Composer/EventDispatcher/EventDispatcher.php:125
 Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/local/bin/composer-2/src/Composer/Command/ScriptAliasCommand.php:69
 Composer\Command\ScriptAliasCommand->execute() at phar:///usr/local/bin/composer-2/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer-2/vendor/symfony/console/Application.php:1015
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer-2/vendor/symfony/console/Application.php:299
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer-2/src/Composer/Console/Application.php:334
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer-2/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer-2/src/Composer/Console/Application.php:130
 Composer\Console\Application->run() at phar:///usr/local/bin/composer-2/bin/composer:83
 require() at /usr/local/bin/composer-2:29

phpunit:coverage-edit [--dev] [--no-dev] [--] [<args>...]

Event Timeline

The Xml class was refactored in PHPUnit 9, with methods being moved to the PHPUnit\Util\Xml\Loader class. However, I don't think we need to use it at all. That class is an internal PHPUnit utility that, as it doc comment says:

@internal This class is not covered by the backward compatibility promise for PHPUnit

Those methods are essentially wrappers around PHP's native DOMDocument class and related functionality. I suggest doing what I did as part of the upgrade: just rewrite it using native PHP abstractions. You can start off by copying PHPUnit's load file and removing everything we don't need for this specific use case.

Change 872494 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/core@master] Fix coverage edit script

https://gerrit.wikimedia.org/r/872494

The Xml class was refactored in PHPUnit 9, with methods being moved to the PHPUnit\Util\Xml\Loader class. However, I don't think we need to use it at all. That class is an internal PHPUnit utility that, as it doc comment says:

@internal This class is not covered by the backward compatibility promise for PHPUnit

Those methods are essentially wrappers around PHP's native DOMDocument class and related functionality. I suggest doing what I did as part of the upgrade: just rewrite it using native PHP abstractions. You can start off by copying PHPUnit's load file and removing everything we don't need for this specific use case.

@Physikerwelt fixed the immediate issue (thank you!), but there's still the point @Daimona made about removing our dependency on PHPUnit's internal class for XML loading.

Change 872494 merged by jenkins-bot:

[mediawiki/core@master] Fix phpunit:coverage-edit script

https://gerrit.wikimedia.org/r/872494

Those methods are essentially wrappers around PHP's native DOMDocument class and related functionality. I suggest doing what I did as part of the upgrade: just rewrite it using native PHP abstractions. You can start off by copying PHPUnit's load file and removing everything we don't need for this specific use case.

Sorry, I was unaware of this phab ticket. For that use case, it would be sufficient to use https://www.php.net/manual/en/domdocument.load.php. Adding error handling would probably be more confusing than helpful.

Change 875404 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/core@master] Make phpunit:coverage-edit script independent of phpunit

https://gerrit.wikimedia.org/r/875404

kostajh claimed this task.

Those methods are essentially wrappers around PHP's native DOMDocument class and related functionality. I suggest doing what I did as part of the upgrade: just rewrite it using native PHP abstractions. You can start off by copying PHPUnit's load file and removing everything we don't need for this specific use case.

Sorry, I was unaware of this phab ticket. For that use case, it would be sufficient to use https://www.php.net/manual/en/domdocument.load.php. Adding error handling would probably be more confusing than helpful.

Thanks @Physikerwelt!

Change 875404 merged by jenkins-bot:

[mediawiki/core@master] Make phpunit:coverage-edit script independent of phpunit

https://gerrit.wikimedia.org/r/875404