Unit testing is the basis of several modern agile development methods, making PHPUnit a key tool for many large PHP projects. This tool can also be used by the Xdebug extension to generate code coverage reports, and can be integrated with phing for automatic testing. Finally, it can be integrated with Selenium to complete large-scale automated integration testing.
In Windows LAMP environment XAMPP 1.7.3, how does one install PHPUnit?
Run cmd as an administrator and use pear to add the phpunit channel:
D: \ xampp \ php> pear channel-discover pear.phpunit.de
Channel "pear.phpunit.de" is already initialized
After adding channels, try to install PHPUnit:
D: \ xampp \ php> pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: components. ez. no
Unknown remote channel: components. ez. no
Phpunit/PHPUnit requires PEAR Installer (version> = 1.9.1), installed version is 1.9.0
Phpunit/PHPUnit requires package "channel: // pear.symfony-project.com/YAML" (version> = 1.0.2)
Phpunit/PHPUnit can optionally use PHP extension "plugin"
Phpunit/DbUnit requires PEAR Installer (version> = 1.9.1), installed version is1.9.0
Phpunit/DbUnit requires package "channel: // pear.symfony-project.com/YAML" (version> = 1.0.2)
Phpunit/File_Iterator requires PEAR Installer (version> = 1.9.1), installed version is 1.9.0
Phpunit/PHP_CodeCoverage requires PEAR Installer (version> = 1.9.1), installed version is 1.9.0
Phpunit/PHP_CodeCoverage requires package "channel: // components. ez. no/leletools" (version >=1.6)
Phpunit/PHP_CodeCoverage requires package "phpunit/File_Iterator" (version> = 1.2.2)
Phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version> = 2.0.5)
Phpunit/PHPUnit_MockObject requires PEAR Installer (version> = 1.9.1), installed version is 1.9.0
Phpunit/PHPUnit_Selenium requires PEAR Installer (version> = 1.9.1), installed version is 1.9.0
Phpunit/PHP_TokenStream requires PEAR Installer (version> = 1.9.1), installed version is 1.9.0
Phpunit/PHP_TokenStream requires package "channel: // components. ez. no/leletools" (version >=1.6)
No valid packages found
Install failed
We can see from the prompt that you need to install PEAR 1.9.1, and the current PEAR is 1.9.0, You need to upgrade PEAR first.
Pear list-upgrades can list currently available updates,
D: \ xampp \ php> pear. bat list-upgrades
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net"
Update
D: \ xampp \ php> pear channel-update pear.php.net
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
D: \ xampp \ php> pear. bat list-upgrades
PEAR. PHP. net available upgrades (STABLE ):
========================================================== =
CHANNEL PACKAGE LOCAL REMOTE SIZE
Pear.php.net Archive_Tar 1.3.3 (stable) 1.3.7 (stable) 17.2kB
Pear.php.net Console_Getargs 1.3.4 (stable) 1.3.5 (stable) 17.8kB
Pear.php.net Mail 1.1.14 (stable) 1.2.0 (stable) 23kB
Pear.php.net Mail_Mime 1.5.2 (stable) 1.8.1 (stable) 31kB
Pear.php.net Mail_mimeDecode 1.5.1 (stable) 1.5.5 (stable) 11.4kB
Pear.php.net Net_SMTP 1.3.4 (stable) 1.4.4 (stable) 12.1kB
Pear.php.net Net_Socket 1.0.9 (stable) 1.0.10 (stable) 5.3kB
Pear.php.net PEAR 1.9.0 (stable) 1.9.1 (stable) 287kB
Pear.php.net Structures_Graph 1.0.3 (stable) 1.0.4 (stable) 30kB
Channel pear.phpunit.de: No upgrades available
ZEND. GOOGLECODE. COM/svn available upgrades (STABLE ):
========================================================== ================
CHANNEL PACKAGE LOCAL REMOTE SIZE
Zend.googlecode.com/svn zend 1.9.6 (stable) 1.11.1 (stable )-
Update all available updates:
D: \ xampp \ php> pear upgrade-all
Will upgrade channel: // pear.php.net/archive_tar
Will upgrade channel: // pear.php.net/console_getargs
Will upgrade channel: // pear.php.net/mail
Will upgrade channel: // pear.php.net/mail_mime
Will upgrade channel: // pear.php.net/mail_mimedecode
Will upgrade channel: // pear.php.net/net_smtp
Will upgrade channel: // pear.php.net/net_socket
Will upgrade channel: // pear.php.net/pear
Will upgrade channel: // pear.php.net/structures_graph
Will upgrade channel: // zend.googlecode.com/svn/zend
Did not download optional dependencies: pear/Auth_SASL, use -- alldeps to download automatically
Pear/Net_SMTP can optionally use package "pear/Auth_SASL"
Downloading Archive_Tar-1.3.7.tgz...
Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes)
...... Done: 17,610 bytes
Downloading Console_Getargs-1.3.5.tgz...
Starting to download Console_Getargs-1.3.5.tgz (18,207 bytes)
... Done: 18,207 bytes
Downloading Mail-1.2.0.tgz...
Starting to download Mail-1.2.0.tgz (23,214 bytes)
... Done: 23,214 bytes
Downloading Mail_Mime-1.8.1.tgz...
Starting to download Mail_Mime-1.8.1.tgz (31,530 bytes)
... Done: 31,530 bytes
Downloading Mail_mimeDecode-1.5.5.tgz...
Starting to download Mail_mimeDecode-1.5.5.tgz (11,554 bytes)
... Done: 11,554 bytes
Downloading Net_SMTP-1.4.4.tgz...
Starting to download Net_SMTP-1.4.4.tgz (12,264 bytes)
... Done: 12,264 bytes
Downloading Net_Socket-1.0.10.tgz...
Starting to download Net_Socket-1.0.10.tgz (5,429 bytes)
... Done: 5,429 bytes
Downloading PEAR-1.9.1.tgz...
Starting to download PEAR-1.9.1.tgz (293,587 bytes)
... Done: 293,587 bytes
Downloading Structures_Graph-1.0.4.tgz...
Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes)
... Done: 30,318 bytes
Downloading Zend-1.11.1.tgz...
Starting to download Zend-1.11.1.tgz (3,638,888 bytes)
... Done: 3,638,888 bytes
Upgrade-all OK: channel: // pear.php.net/Archive_Tar-1.3.7
Upgrade-all OK: channel: // pear.php.net/lele_getargs-1.3.5
Upgrade-all OK: channel: // pear.php.net/Mail-1.2.0
Upgrade-all OK: channel: // pear.php.net/Mail_Mime-1.8.1
Upgrade-all OK: channel: // pear.php.net/Net_Socket-1.0.10
Upgrade-all OK: channel: // pear.php.net/Structures_Graph-1.0.4
Upgrade-all OK: channel: // zend.googlecode.com/svn/Zend-1.11.1
Upgrade-all OK: channel: // pear.php.net/Mail_mimeDecode-1.5.5
Upgrade-all OK: channel: // pear.php.net/Net_SMTP-1.4.4
Upgrade-all OK: channel: // pear.php.net/PEAR-1.9.1
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR # featurename"
After the update is successful, PEAR is already in version 1.9.1. Now you can install PHPUnit with confidence:
D: \ xampp \ php> pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: components. ez. no
Unknown remote channel: components. ez. no
Phpunit/PHPUnit requires package "channel: // pear.symfony-project.com/YAML" (version> = 1.0.2)
Phpunit/PHPUnit can optionally use PHP extension "plugin"
Phpunit/DbUnit requires package "channel: // pear.symfony-project.com/YAML" (version> = 1.0.2)
Phpunit/PHP_CodeCoverage requires package "channel: // components. ez. no/leletools" (version >=1.6)
Phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version> = 2.0.5)
Phpunit/PHP_TokenStream requires package "channel: // components. ez. no/leletools" (version >=1.6)
Downloading File_Iterator-1.2.3.tgz...
Starting to download File_Iterator-1.2.3.tgz (3,406 bytes)
... Done: 3,406 bytes
Downloading PHPUnit_MockObject-1.0.3.tgz...
Starting to download PHPUnit_MockObject-1.0.3.tgz (17,333 bytes)
... Done: 17,333 bytes
Downloading PHPUnit_Selenium-1.0.1.tgz...
Starting to download PHPUnit_Selenium-1.0.1.tgz (15,285 bytes)
... Done: 15,285 bytes
Install OK: channel: // pear.phpunit.de/File_Iterator-1.2.3
Install OK: channel: // pear.phpunit.de/PHPUnit_MockObject-1.0.3
Install OK: channel: // pear.phpunit.de/PHPUnit_Selenium-1.0.1
The above information, or not installed successfully, pear.symfony-project.com and components. ez. no two channels also need to add a bit:
D: \ xampp \ php> pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded
D: \ xampp \ php> pear channel-discover components. ez. no
Adding Channel "components. ez. no" succeeded
Discovery of channel "components. ez. no" succeeded
Try to install PHPUnit again:
D: \ xampp \ php> pear install phpunit/PHPUnit
Phpunit/PHPUnit can optionally use PHP extension "plugin"
Phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version> = 2.0.5)
Downloading PHPUnit-3.5.5.tgz...
Starting to download PHPUnit-3.5.5.tgz (116,148 bytes)
...... Done: 116,148 bytes
Downloading DbUnit-1.0.0.tgz...
Starting to download DbUnit-1.0.0.tgz (38,183 bytes)
... Done: 38,183 bytes
Downloading PHP_CodeCoverage-1.0.2.tgz...
Starting to download PHP_CodeCoverage-1.0.2.tgz (109,280 bytes)
... Done: 109,280 bytes
Downloading YAML-1.0.4.tgz...
Starting to download YAML-1.0.4.tgz (9,919 bytes)
... Done: 9,919 bytes
Downloading ConsoleTools-1.6.1.tgz...
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)
... Done: 869,994 bytes
Downloading PHP_TokenStream-1.0.1.tgz...
Starting to download PHP_TokenStream-1.0.1.tgz (7,250 bytes)
... Done: 7,250 bytes
Downloading Base-1.8.tgz...
Starting to download Base-1.8.tgz (236,357 bytes)
... Done: 236,357 bytes
Install OK: channel: // pear.symfony-project.com/YAML-1.0.4
Install OK: channel: // components. ez. no/Base-1.8
Install OK: channel: // pear.phpunit.de/DbUnit-1.0.0
Install OK: channel: // components. ez. no/ConsoleTools-1.6.1
Install OK: channel: // pear.phpunit.de/PHP_TokenStream-1.0.1
Install OK: channel: // pear.phpunit.de/PHP_CodeCoverage-1.0.2
Install OK: channel: // pear.phpunit.de/PHPUnit-3.5.5
PHPUnit is successfully installed !!!