Page MenuHomePhabricator

Can't use phpunit.phar to invoke MediaWiki tests
Closed, ResolvedPublic

Description

PHPUnit's manual recommends the PHPUnit phar as the easiest way to obtain PHPUnit and its dependencies. Unfortunately, when PHPUnit is loaded via a phar file, there appears to be no way to use it to run MediaWiki's test suites. If you try to execute the tests by invoking the phar file, MediaWiki's environment is not set up. If you attempt to use MediaWiki's own tests/phpunit/phpunit.php, you find that there is no way to get MediaWiki to resolve its includes / requires using the phar file: --with-phpunitdir could presumably add the phar file to include_path (which is supported by PHP, AFAIK), but it currently chokes on anything that isn't an actual directory.


Version: 1.23.0
Severity: critical

Details

Reference
bz58881

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:20 AM
bzimport set Reference to bz58881.
bzimport added a subscriber: Unknown Object (MLST).

As of a week ago, PHPUnit is distributed as a PHAR by PEAR (see https://github.com/sebastianbergmann/phpunit/wiki/ChangeLog-for-PHPUnit-4.0).

So this is now a really big issue.

sebastian wrote:

The problem is that you are trying to include/require a source file of PHPUnit instead of relying on PHPUnit's class loader to load the class in question.

Change 118997 had a related patch set uploaded by Aude:
Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point

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

this is a workaround but think it would be better to have our phpunit.php or whatever be includable via phpunit's --bootstrap parameter.

Change 118997 had a related patch set uploaded by Aude:
Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point

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

Change 118997 had a related patch set uploaded by Aude:
Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point

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

my patch does not work correctly with the way MediaWiki extends PHPUnit_TextUI_Command in MediaWikiPHPUnitCommand. It only works if one specifies no additional non-phpunit options.

the phpunit.phar executes PHPUnit_TextUI_Command::main();

I think the way to go is to have a proper bootstrap to use with phpunit's --bootstrap option

question is...

if one extends PHPUnit_TextUI_Command (as phpunit source code suggests), then how is it recommended to have that work with phpunit.phar (which calls PHPUnit_TextUI_Command::main() )?

sebastian wrote:

That is a valid question. To be honest, I have always discouraged extensions to PHPUnit_TextUI_Command (maybe I was not vocal/verbose enough about it).

probably using the bootstrap option is the best approach then.

  • Bug 63690 has been marked as a duplicate of this bug. ***

Raising priority as this starts to cause real problems (eg. tests on travis no longer work for Wikibase due to this).

Some related changes starting to strip down MediaWikiPHPUnitCommand a bit..

https://gerrit.wikimedia.org/r/131448
https://gerrit.wikimedia.org/r/131450
https://gerrit.wikimedia.org/r/131454
https://gerrit.wikimedia.org/r/131456

The hardest thing to move / fix that I can see is the additional options that have been shoved into $additionalOptions

Also https://gerrit.wikimedia.org/r/#/c/131488 which removes MediaWikiPHPUnitCommand

https://gerrit.wikimedia.org/r/118997 should probably now be rebased on top of this chain

I have amended https://gerrit.wikimedia.org/r/#/c/118997/ and now the whole chain should be ready for review.

  • Bug 69048 has been marked as a duplicate of this bug. ***
  • Bug 64597 has been marked as a duplicate of this bug. ***

physik wrote:

I could reproduce the problem hashar describes in
https://gerrit.wikimedia.org/r/#/c/131466/6
there is no color in the output with the option --debug-tests.
This could become a separate bug, or just fixed in one of the follow up commits.
I tried.. but i did not manage to fix it in 30 minutes so I gave up.

Change 118997 merged by jenkins-bot:
Allow use of phpunit.phar with MediaWiki's phpunit.php test entry point

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

Change 151394 had a related patch set uploaded by JanZerebecki:
phpunit.php: Allow direct use of a PHPUnit PHAR file.

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

This bug as is, is resolved (you can now use the phpunit.phar for unit tests). If there are other issues (like using the phar is not nice, than create another bug, please).