Manual:PHP unit testing/Installing PHPUnit
|This page is a candidate for deletion. The given reason is: Most of these instructions are outdated and don't seem relevant anymore. I believe most (all?) developers are running |
This notice should remain for a minimum of 1 week after it was placed on the page. If discussion is still ongoing, it should remain until a consensus is reached, after which the page will either be deleted or this notice removed.
If you disagree with its deletion, please discuss your reasons on this page or on its associated talk page, as applicable.
Administrators: delete this pageLast edit by: KHarlan (WMF) (talk · contribs) · Last edited on: Sun, 18 Oct 2020 17:51:52 +0000
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.
Note the known issue below. The Debian/Ubuntu package is broken.
If you use Composer to manage your MediaWiki dependencies, it should install PHPUnit for you, although it installs PHPUnit specifically for the
tests/phpunit/phpunit.php script, not for general command-line use.
Testing your installation
$ which phpunit /some/path/to/bin/phpunit $ phpunit --version PHPUnit A.B.C by Sebastian Bergmann. $
- is the installation prefix which depends upon your distribution and the installation method used. Usually one of
- is the PHPUnit version
If you have something similar to
phpunit --version output above, you should be fine and can start running the unit tests.
Apt package for Ubuntu 11.10, 12.04 is broken
sudo apt-get install phpunit results in a broken installation missing "PHP/CodeCoverage/Filter.php" (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.
$ phpunit --version PHP Fatal error: Class 'File_Iterator' not found in /usr/share/php/File/Iterator/Factory.php on line 105
You will have to alter the PHPUnit source code shipped by Ubuntu:
- on line 44 add
(Or install using PEAR).
If that doesn't work, or you're on Windows-family operating systems, follow the installation instructions in the PHPUnit manual.
DiffHistoryBlobTest::testXdiffAdler32 test failing
DiffHistoryBlobTest::testXdiffAdler32 with data set #0 ('', 'Empty string') String is not zero-terminated ()
xdiff_string_diff() [tests/002.phpt], xdiff_string_patch() [tests/006.phpt] and xdiff_string_merge3() [tests/010.phpt] unit tests fail.
This is bug 35110 and PHP#bug 61358. This might happen when using version of pecl-xdiff PHP extension older than 1.5.2 with PHP 5.3.10+. To fix, please upgrade pecl-xdiff extension to version 1.5.2 or newer. The xdiff tool is not affected by this problem.
If you get a version error after installation, for example...
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.