Manual talk:PHP unit testing/Running the tests

Latest comment: 1 year ago by Novem Linguae in topic Is `phpunit:entrypoint` only for integration tests?

Outdated instructions

edit

The terminal instructions suggests "make databaseless" to prepare tests. Here the results. --Dereckson (talk) 02:55, 10 January 2013 (UTC)Reply

/home/dereckson/dev/mediawiki/bench/core/tests/phpunit ] make databaseless
php phpunit.php --configuration /suite.xml  --exclude-group Broken,ParserFuzz,Destructive,Database,Stub
Could not read "/suite.xml".
*** Error code 1
Stop in /usr/home/dereckson/dev/mediawiki/bench/core/tests/phpunit.
Actually, this is a UNIX-compliance issue in Makefile: $(shell command) is a GNU-only Make extension.
$PWD would work everywhere.
Reported at Bugzilla:43808 --Dereckson (talk) 03:03, 10 January 2013 (UTC)Reply

How to run tests without a foo.suite.xml?

edit

Most extensions don't have a foo.suite.xml file, yet somehow their tests run. Developers need to know how to run existing PHP tests without faffing about with .xml files. There are no instructions for this, and pointing phpunit.php at a particular test fails for me

% cd tests/phpunit
% php phpunit.php ../../extensions/AbuseFilter/tests/legacyParserTest.php
PHP Notice:  Constant MEDIAWIKI already defined in /home/spage/projects/core/maintenance/Maintenance.php on line 526
...
Notice: Undefined variable: IP in /home/spage/projects/core/maintenance/doMaintenance.php on line 57
...
Warning: require_once(/includes/AutoLoader.php): failed to open stream: No such file or directory in /home/spage/projects/core/maintenance/doMaintenance.php on line 57

Is `phpunit:entrypoint` only for integration tests?

edit

cc @Daimona Eaytoy. Saw your email about phpunit, thanks for that. Is phpunit:entrypoint only for integration tests, or does it also run unit tests? In my opinion this documentation page is a bit unclear about that. Also are there any other entry points besides :entrypoint and :unit? Thanks. Novem Linguae (talk) 20:27, 12 July 2023 (UTC)Reply

Hi! phpunit:entrypoint is meant to be used with unit tests, just like the previous phpunit.php script. For unit tests you should use composer phpunit:unit. That said, you can also run unit tests using :entrypoint (or phpunit.php) if you wish, but this is not officially supported and you may get different behaviour than running them with :unit. HTH! Daimona Eaytoy (talk) 23:35, 12 July 2023 (UTC)Reply
Daimona Eaytoy. Thanks for the reply. I am still confused though. If I want to run every phpunit test of any type, what is the correct command? The documentation makes it seem like `composer phpunit:entrypoint` only runs MediaWikiIntegrationTestCase classes. Is that correct? Is there a complete list of suffixes somewhere (e.g. :unit, :entrypoint, others?) and what they run? Thank you. Novem Linguae (talk) 02:27, 13 July 2023 (UTC)Reply
If you want to run all tests you would use :entrypoint, yes. This has a caveat though: some unit tests may run with all the config loaded, which could in theory produce a different result than using the :unit command. That's why CI runs these tests separately, unit tests first and then integration tests. The only up-to-date list of composer commands is in the composer.json file itself. Once T227900 is resolved I will send a new email to wikitech-l with the final test configuration, which will hopefully be a bit simpler than the current one. Daimona Eaytoy (talk) 12:41, 13 July 2023 (UTC)Reply
Got it. Thanks! Novem Linguae (talk) 21:16, 13 July 2023 (UTC)Reply
Return to "PHP unit testing/Running the tests" page.