Difference between revisions 3834436 and 4087081 on mediawikiwiki

{{TNT|Manual:PHP_unit_testing/navigation}}

You must have PHPUnit 3.7.0 (or later) installed to run the unit tests. Most developers use the very latest PHPUnit version, so there is no guarantee an older one will actually pass the tests we wrote. 

'''It seems that PHPUnit 7 does not work with MediaWiki at the moment. Use PHPUnit 6 instead.'''

== Install methods ==
Note the [[#Known issues|known issue below]]. The Debian/Ubuntu package is broken.

The [https://phpunit.readthedocs.io/en/8.4/installation.html recommended way to install PHPUnit] is by downloading a PHP Archive (PHAR file). With the resolution of [[bugzilla:58881|bug 58881]], this should work now.

If you use [[Composer]] to manage your MediaWiki dependencies, it should install PHPUnit for you, although it installs PHPUnit specifically for the <code>tests/phpunit/phpunit.php</code> script, not for general command-line use.

== Testing your installation ==

<syntaxhighlight lang="bashell-session">
$ which phpunit
/some/path/to/bin/phpunit
$ phpunit --version
PHPUnit A.B.C by Sebastian Bergmann.
$
</syntaxhighlight>
Where:
; /some/path/to : is the installation prefix which depends upon your distribution and the installation method used. Usually one of <code>/usr</code>, <code>/usr/local/</code> or <code>/opt/local/</code>.
; A.B.C: is the PHPUnit version

If you have something similar to <code>phpunit --version</code> output above, you should be fine and can start [[Manual:PHP unit testing/Running the unit tests|running the unit tests]].

== Known issues ==

=== Apt package for Ubuntu 11.10, 12.04 is broken ===
<kbd>sudo apt-get install phpunit</kbd> results in a broken installation missing "PHP/CodeCoverage/Filter.php" ([https://bugs.launchpad.net/ubuntu/+source/phpunit/+bug/770394 Ubuntu launchpad bug 770394]).

Try doing a manual installation instead.

=== Class File_Iterator not found ===
This might happen when trying to run PHPUnit under Ubuntu 11.04.
<syntaxhighlight lang="bashell-session">
$ phpunit --version
PHP Fatal error:  Class 'File_Iterator' not found in /usr/share/php/File/Iterator/Factory.php on line 105
</syntaxhighlight>


You will have to alter the PHPUnit source code shipped by Ubuntu:
* Edit <code>/usr/share/pear/File/Iterator/Factory.php</code>
(contracted; show full)
 PHPUnit 3.6.7 or later required, you have 3.5.15.
...this means that you probably have more than one version of PHPUnit installed on your machine. You may need to edit your include_path in your php.ini file to point to the location of the newer installation. You may also need to add this path to the PATH variable in your .profile.

If you get the error...
 This version of PHPUnit requires PHP 5.6.
...you either need to upgrade PHP or downgrade PHPUnit. PHPUnit 4.8 is compatible with PHP 5.5 and earlier.