Environment: Ubuntu12.04 + PHP5.3 (for compilation and installation, refer to this article for the compilation and installation steps). Note that PHPUnit3.7 requires PHP5.3.3 (or a later version). We strongly recommend PHP5.5.1 (or a later version ). PHPUnit uses the PHP_CodeCoverage library to collect and process code coverage information. It depends on X
Environment: Ubuntu12.04 + PHP5.3 (for compilation and installation instructions, refer to this article)
Note:
PHPUnit 3.7 requires PHP 5.3.3 (or later) and is strongly recommended for PHP 5.5.1 (or later ).
PHPUnit uses the PHP_CodeCoverage library to collect and process code coverage information. It depends on Xdebug 2.0.5 (or later) and is strongly recommended for Xdebug 2.2.3 (or later ).
Directly run the PHP file package (PHAR)
To obtain PHPUnit, the easiest way is to download PHPUnit? PHP file package (PHAR), which binds all the dependent components (including some optional components) required by PHPUnit to a single file:
wget https://phar.phpunit.de/phpunit.pharchmod +x phpunit.pharmv phpunit.phar /usr/local/bin/phpunit
Of course, you can also download and directly use this PHAR:
wget https://phar.phpunit.de/phpunit.pharphp phpunit.phar
Use Composer dependency
If you use? Composer? To manage project dependencies, you only need to simply?composer.json
? Add a pair to the file?phpunit/phpunit
? . Below is a minimal?composer.json
? File example, only define a development-time dependency for PHPUnit 3.7:
{ "require-dev": { "phpunit/phpunit": "3.7.*" }}
To complete system-level installation through Composer, run:
composer global require 'phpunit/phpunit=3.7.*'
Make sure the path variable contains?~/.composer/vendor/bin/
.
Note:
Support for Composer and PHP archives (PHAR) is added in PHPUnit 3.7 (from PHPUnit 3.7.5 to stable. Earlier PHPUnit releases are unavailable on these distribution channels.
Install through PEAR
Use? To install PHPUnit by using the PEAR installer, you only need to execute the following two commands (may need?root
? Permission running ):
sudo pear config-set auto_discover 1sudo pear install pear.phpunit.de/PHPUnit
By default, phpunit will be installed in the bin subdirectory of the php installation directory. if you want to directly use the phpunit command in the terminal, you need to create a soft link, for example:
sudo ln -s /usr/local/php/bin/phpunit /usr/local/bin/phpunit
Be careful
Depending on your operating system version and PHP environment, you may need to install PEAR or update the installed PEAR before you can follow the instructions here.
Generally?sudo pear upgrade PEAR
? You can complete the upgrade of the installed PEAR. if you compile and install it at the time, you can use sudo pear upgrade to complete the upgrade.
Optional package
The following optional component packages are available:
-
DbUnit
-
The DbUnit transplanted to PHP/PHPUnit is used to provide support for database interaction testing. To install this package through PEAR, run the following command:
sudo pear install phpunit/DbUnit
To install this package through Composer, add the following?"require-dev"
? Dependency:
"phpunit/dbunit": ">=1.2"
-
PHP_Invoker
-
A tool class that can call callable content in a way with time-out restrictions. This package is required when the test timeout limit needs to be guaranteed in strict mode. To install this package, run the following command:
sudo pear install phpunit/PHP_Invoker
An error may be reported when the component is installed: you need to install the pcntl extension first. for details about how to install the pcntl extension, refer to: how to compile and install the pcntl extension in PHP and how to report an error
To install this package through Composer, add the following?"require-dev"
? Dependency:
"phpunit/php-invoker": "*"
-
PHPUnit_Selenium
-
Integrate Selenium RC into PHPUnit. To install this package through PEAR, run the following command:
sudo pear install phpunit/PHPUnit_Selenium
To install this component, you must first install curl. Otherwise, an error is returned. for the curl extension installation steps, refer to this article: PHP compilation and installation of curl steps and troubleshooting methods.
To install this package through Composer, add the following?"require-dev"
? Dependency:
"phpunit/phpunit-selenium": ">=1.2"
-
PHPUnit_Story
-
The story-based test runner used for behavior-driven development using PHPUnit. To install this package through PEAR, run the following command:
sudo pear install phpunit/PHPUnit_Story
To install this package through Composer, add the following?"require-dev"
? Dependency:
"phpunit/phpunit-story": "*"
-
PHPUnit_SkeletonGenerator
-
A tool used to generate a skeleton test class from the finished code class, or vice versa. To install this package, run the following command:
sudo pear install phpunit/PHPUnit_SkeletonGenerator
-
PHPUnit_TestListener_DBUS
-
A test listener (TestListener) that sends an event to the listener ). To install this package, run the following command:
sudo pear install phpunit/PHPUnit_TestListener_DBUS
-
PHPUnit_TestListener_XHProf
-
A test listener (TestListener) that uses XHProf to automatically analyze the tested code ). To install this package, run the following command:
sudo pear install phpunit/PHPUnit_TestListener_XHProf
-
PHPUnit_TicketListener_Fogbugz
-
A ticket listener for API interaction with the Fogbugz system. To install this package, run the following command:
sudo pear install phpunit/PHPUnit_TicketListener_Fogbugz
-
PHPUnit_TicketListener_GitHub
-
A ticket listener that interacts with the problematic API of the GitHub system. To install this package, run the following command:
sudo pear install phpunit/PHPUnit_TicketListener_GitHub
-
PHPUnit_TicketListener_GoogleCode
-
A ticket listener that interacts with the problematic API of the Google Code system. To install this package, run the following command:
sudo pear install phpunit/PHPUnit_TicketListener_GoogleCode
-
PHPUnit_TicketListener_Trac
-
A ticket listener that interacts with the problem API of the Trac system. To install this package, run the following command:
sudo pear install phpunit/PHPUnit_TicketListener_Trac
Upgrade
This section collects some minor backward compatibility issues that may occur when you upgrade from PHPUnit 3.6 to PHPUnit 3.7.
The upgrade should be very simple and will not encounter any problems, because this process has been tested for all major open-source frameworks and there are no problems. However, each project is different. if you have tried a candidate release and encountered problems, this document may be helpful.
-
Removed obsolete OutputTestCase
-
Class?
PHPUnit_Extensions_OutputTestCase
? Removed. In PHPUnit 3.6, an discard prompt is generated when this class is used.
-
The current working directory will be restored after each test case
-
If a test changes the current working directory (
cwd
), PHPUnit will encounter problems when generating code coverage reports. Now the current working directory will be restored after each test case, so it may be found that a test depends on another test that has changed the current working directory. This is not desirable and should be easily corrected.
-
The test listener triggers a call to autoload.
-
When a custom Test listener is used as described in the Test Listeners section, PHPUnit silently ignores the missing Test listener. For users, this issue is extremely difficult to debug. Now, an autoload call is triggered when you try to locate these classes. If the auto-loader you are using generates an error when the test listener cannot be found, you may encounter a problem here. To solve this problem, remove the listener or?
bootstrap.php
? To make sure that the class has been loaded.
-
No longer clone the mock object parameter
-
Previously, all parameters are cloned when an object is imitated (mock. This leads to a problem when trying to determine whether the parameter passed to the method is the same in the test. In addition, there are other problems when encountering an object that cannot be cloned. As a feature that has always been demanded by many people, this behavior has changed. Example 10.15 shows the benefits of the new implementation method. Example 10.16 shows how to switch back to the previous behavior mode.
-
addUncoveredFilesFromWhitelist
Removed,processUncoveredFilesFromWhitelist
Replace
-
When generating code coverage, if?
, PHPUnit will include all the files not covered. This is a problem for people who include executable code in these files. PHPUnit will now scan the file and try to guess which code is executable and which code is not executable without executing the include operation. This may lead to different code coverage reports. If you want to switch back to the old behavior mode, can you use?
. If you need to support both PHPUnit 3.6 and 3.7, you can use both settings.
-
cacheTokens
? The default value is changed?false
-
From PHPUnit?
3.7.2
? At the beginning, the cache for the files with the lexical analysis (tokenized) is disabled by default. When processing code coverage reports for large projects, this cache will consume a lot of memory, and due to changes in the whitelist behavior, it will be very problematic for those who have code based on thousands of classes. If the project is small or has enough memory?
phpunit.xml
? Add?
cacheTokens="true"
? To get the running
Returns on time.