php 在 windows 上安装 phpunit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12655136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install phpunit on windows
提问by Dmitry
How to install phpunit?
如何安装phpunit?
I read documentation https://github.com/sebastianbergmann/phpunit, but have an error:
我阅读了文档https://github.com/sebastianbergmann/phpunit,但有一个错误:
>pear upgrade PEAR
Nothing to upgrade
>pear config-set auto_discover 1
config-set succeeded
>pear install pear.phpunit.de/PHPUnit
No releases available for package "pear.phpunit.de/PHPUnit"
install failed
How can I fix this error?
我该如何解决这个错误?
回答by Satya
Try the following instructions:
请尝试以下说明:
- In the command prompt, switch to the directory that you installed PHP to by running
cd C:\php\ - Then install PEAR by running
php go-pear.phar - Press Enter to accept the default when it asks you “Are you installing a system-wide PEAR or a local copy?”
- Press Enter again to accept the file layout.
- Press Enter to finish.
- Run the following commands (they may take a while to update, be patient):
pear channel-update pear.php.netpear upgrade-allpear channel-discover pear.phpunit.depear channel-discover components.ez.nopear channel-discover pear.symfony-project.compear update-channels
- Clear your pear cache
pear clear-cache - To install PHPUnit, run
pear install --alldeps --force phpunit/PHPUnit - To test that PHPUnit was successfully installed, run
phpunit -v
- 在命令提示符下,通过运行切换到您安装 PHP 的目录
cd C:\php\ - 然后通过运行安装 PEAR
php go-pear.phar - 当它询问您“您是安装系统范围的 PEAR 还是本地副本?”时,按 Enter 接受默认设置。
- 再次按 Enter 接受文件布局。
- 按 Enter 完成。
- 运行以下命令(更新可能需要一段时间,请耐心等待):
pear channel-update pear.php.netpear upgrade-allpear channel-discover pear.phpunit.depear channel-discover components.ez.nopear channel-discover pear.symfony-project.compear update-channels
- 清除你的梨缓存
pear clear-cache - 要安装 PHPUnit,请运行
pear install --alldeps --force phpunit/PHPUnit - 要测试 PHPUnit 是否已成功安装,请运行
phpunit -v
回答by Dmitry
Old answer (2014):
It's said that phpunit will not be available via PEAR since December 2014.
So it's easy to install it using composer:
旧答案(2014 年):据说自 2014 年 12 月起 phpunit 将无法通过 PEAR 使用。
因此使用composer安装它很容易:
composer global require "phpunit/phpunit=4.1.*"
Update 2019: it should be installed as a local (for your project) development package:
2019 年更新:它应该安装为本地(对于您的项目)开发包:
composer require --dev phpunit/phpunit ^8
回答by Suraj
As said by @Wilt Installation via pear doesn't works any longer. Follow below steps instead
正如@Wilt 所说,通过梨安装不再有效。请按照以下步骤操作
Step I: Create a directory named bin in C drive.
第一步:在C盘创建一个名为bin的目录。
Step II: Now add the path C:\bin to your environment.
第二步:现在将路径 C:\bin 添加到您的环境中。
- To do this click on Windows icon and right click on Computer and then select Properties.
- Then click on Advanced system settings -> Advanced -> Environment Variables.
- In the System variables section scroll down and select the line where the Variable column value is Path. Click on Edit.
- Now add (append at the end)
;C:\binat the end.
- 为此,请单击 Windows 图标并右键单击“计算机”,然后选择“属性”。
- 然后点击高级系统设置 -> 高级 -> 环境变量。
- 在系统变量部分向下滚动并选择变量列值为路径的行。单击编辑。
- 现在在最后添加(在最后追加)
;C:\bin。
Step III: Download phpunit phar file to C:\bin folder.
第三步:将 phpunit phar 文件下载到 C:\bin 文件夹。
- If you are PHP 7 then download the phar file from https:// phar.phpunit.de/phpunit-6.2.phar. Else if you are using PHP 5.6 then download the phar file from https:// phar.phpunit.de/phpunit-5.7.phar.
- Once downloaded rename the
file to
phpunit.pharand move it to C:\bin folder.
- 如果您是 PHP 7,则从 https://phar.phpunit.de/phpunit-6.2.phar 下载 phar 文件。否则,如果您使用的是 PHP 5.6,则从 https://phar.phpunit.de/phpunit-5.7.phar 下载 phar 文件。
- 下载后,将文件重命名为
phpunit.phar并将其移动到 C:\bin 文件夹。
Step IV: Create a batch script phpunit.cmd
第四步:创建批处理脚本phpunit.cmd
Open command prompt. Type cd C:\bin and hit enter.
Then type
echo @php "%~dp0phpunit.phar" %* > phpunit.cmdand hit enter.
打开命令提示符。键入 cd C:\bin 并按回车键。
然后输入
echo @php "%~dp0phpunit.phar" %* > phpunit.cmd并按回车键。
To verify PHPUnit has been installed type phpunit --versionin command prompt. You should get something like PHPUnit x.y.z by Sebastian Bergmann and contributors.
要验证 PHPUnit 是否已安装,请phpunit --version在命令提示符中键入。你应该得到类似的东西PHPUnit x.y.z by Sebastian Bergmann and contributors。
回答by Luis Riego
Try this in Windows Subsystem for Linux (wsl):
在适用于 Linux 的 Windows 子系统 (wsl) 中试试这个:
sudo apt install phpunit
回答by reclining
I use Windows XP.
我使用 Windows XP。
I wasted a lot of time trying to use pear (the proscribed method to get MakeGood working with Eclipse IDE), only to discover the repository for phpunit is no longer available. This information should be nearer the top of this page so people do not waste their time too.
我浪费了很多时间尝试使用 pear(使 MakeGood 与 Eclipse IDE 一起工作的被禁止的方法),却发现 phpunit 的存储库不再可用。此信息应靠近此页面的顶部,这样人们也不会浪费时间。
I installed phpunit via the download at https://phpunit.de/and following the accompanying instructions. By adding the path to the command file to PATH I can now run phpunit from the command line. I have not however got phpunit running in MakeGood/Eclipse. Much of the information on that is out-of-date as it requires pear.
我通过https://phpunit.de/上的下载并按照随附的说明安装了 phpunit 。通过将命令文件的路径添加到 PATH 我现在可以从命令行运行 phpunit。然而,我还没有在 MakeGood/Eclipse 中运行 phpunit。很多关于这方面的信息已经过时,因为它需要梨。

