單元測試是幾個現代敏捷開發方法的基礎,使得PHPUnit成為許多大型PHP專案的關鍵工具。這個工具也可以被Xdebug擴充用來產生程式碼覆蓋率報告 ,並且可以與phing整合來自動測試,最後它還可以和Selenium整合來完成大型的自動化整合測試。
Windows平台LAMP環境XAMPP 1.7.3下如何安裝PHPUnit呢?
首先,以管理員身分執行cmd,使用pear新增phpunit頻道:
D:xamppphp>pear channel-discover pear.phpunit.de
Channel "pear.phpunit.de" is already initialized
Channel "pear.phpunit.de" is already initialized
頻道加好,試試安裝PHPUnit:
D:xamppphp>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.s.com 🎜>Unknown remote channel: components.ez.no
Unknown remote channel: components.ez.no
phpunit/PHPUnit requires PEAR Installer (version >= 1.9.1), installed 7. phpunit/PHPUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "dbus"
Uniunphp re 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/PHP_CodeCoverage requires PEAR Installer (version >= 1.9.1), installed version 5. requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
phpunit/PHP_CodeCoverage requires package "phpunit/File_Iterator" (version >= 1.2.2)
phpunit/PHPUnit_MockObject requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
= 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
phpunStream/PHken_Tochand .ez.no/ConsoleTools" (version >= 1.6)
No valid packages found
install failed
從提示看出,需要安裝PEAR 1.9.1,而當前PEAR是1.9.0,那就要先升級PEAR版本。
pear list-upgrades可以列出当前可用的更新,
D:\xampp\php>pear.bat list-upgrades
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to
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) -
更新所有可用更新:
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/Console_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"
更新成功后,PEAR已经是1.9.1版了,现在可以放心地安装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 package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/DbUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHP_CodeCoverage 需要套件"channel://components.ez.no/ConsoleTools" (版本>= 1.6)
phpunit/PHP_CodeCoverage 可以選擇使用PHP 擴充"xdebug" (版本>= 2.0.5)
unit /PHP_TokenStream 需要套件「channel://components.ez.no/ConsoleTools」(版本>= 1.6)
正在下載File_Iterator-1.2.3.tgz ...
開始下載File_Iterator-1.2。 3.tgz(3,406 位元組)
....完成:3,406 位元組
正在下載PHPUnit_MockObject-1.0.3.tgz ...
開始下載PHPUnit_MockObject-1.0.3.tgz(17,333 字節)
...完成:17,333 位元組
正在下載PHPUnit_Selenium-1.0.1.tgz ...
開始下載PHPUnit_Selenium-1.0.1.tgz(15,285 位元組)
.. .完成:15,285 位元組
安裝好:channel://pear.phpunit.de/File_Iterator-1.2.3
安裝好:channel://pear.phpunit.de/PHPUnit_MockObject-1.0.3
安裝好:頻道: //pear.phpunit.de/PHPUnit_Selenium-1.0.1
上面資訊查看,還是沒有安裝成功,pear.symfony-project.com和components.ez.no兩個頻道還需要添加一下:
D:xamppphp>pear channel-discover pear.symfony-project.com
新增頻道「pear.symfony-project.com」成功
發現頻道「pear.symfony-project.com」成功
D :xamppphp>pear channel-discover Components.ez.no
新增頻道「components.ez.no」成功
發現頻道「components.ez.no」成功
再嘗試安裝PHPUnit:
D:xamppphp>pear install phpunit/PHPUnit
phpunit/PHPUnit 可以選擇使用PHP 擴充「dbus」
phpunit/PHP_CodeCoverage 可以選擇使用PHP 擴充「xde」(版本 phpunit/PHP_CodeCoverage 可以選擇使用PHP 擴充「xde」(版本.0.5) >下載中PHPUnit-3.5.5.tgz ...
開始下載PHPUnit-3.5.5.tgz(116,148 位元組)
................. ....完成:116,148 位元組
正在下載DbUnit-1.0.0.tgz ...
開始下載DbUnit-1.0.0.tgz(38,183 位元組)
...完成: 38,183 位元組
正在下載PHP_CodeCoverage -1.0.2.tgz ...
開始下載PHP_CodeCoverage-1.0.2.tgz(109,280 位元組)
...下載YAML-1.0.4.tgz ...
開始下載YAML-1.0.4.tgz(9,919 位元組)
...完成:9,919 位元組
正在下載ConsoleTools-1.6.1. tgz ...
開始下載ConsoleTools-1.6 .1.tgz(869,994 位元組)
...完成:869,994 位元組
正在下載PHP_TokenStream-1.0.1.tgz ...
正在下載PHP_TokenStream-1.0.1.tgz ...
開始下載PHP_TokenStream-1.0.1.tgz(7,250 位元組)
...完成:7,250 位元組
正在下載Base-1.8.tgz ...
開始下載Base-1.8.tgz(236,357位元組)
...完成:236,357 位元組
安裝好的:channel://pear.symfony-project.com/YAML-1.0.4
安裝好的:channel://components .ez.no/Base-1.8
安裝好的:channel://pear。 phpunit.de/DbUnit-1.0.0
安裝成功:channel://components.ez.no/ConsoleTools-1.6.1
安裝成功:channel://pear.phpunit.de/PHP_TokenStream-1.0。 1
安裝成功:channel://pear.phpunit.de/PHP_CodeCoverage-1.0.2
安裝成功:channel://pear.phpunit.de/PHPUnit-3.5.5
PHPUnit 安裝成功! ! !
以上就介紹了未聲明標識符 PHPUnit PHP 測試框架安裝方法,包括未聲明標識符方面的內容,希望對 PHP 教程有興趣的朋友有所幫助。