简体   繁体   English

如何使用 WAMP 安装 PHPUnit?

[英]How to install PHPUnit with WAMP?

I'm a newbie programmer and I have tried for an embarrassingly long time to get PHPUnit set up and working with WAMP.我是一名新手程序员,我已经尝试了很长时间来设置 PHPUnit 并使用 WAMP。 I have read the documentation and went through various sites to see what I'm doing wrong, but I give up!我已经阅读了文档并浏览了各种网站以查看我做错了什么,但我放弃了! I need someone to explain this to me like I'm mildly retarded.我需要有人向我解释这一点,就像我是轻度智障一样。

I've probably seen all the guides on how to set it up, but feel free to link me to something you believe is foolproof!我可能已经看过有关如何设置它的所有指南,但请随时将我链接到您认为万无一失的东西!

Try this blog : http://nishutayaltech.blogspot.com/2011/04/installing-phpunit-on-windows.html试试这个博客: http : //nishutayaltech.blogspot.com/2011/04/installing-phpunit-on-windows.html

This setup is for Windows.此设置适用于 Windows。 Hope this will help you.希望这会帮助你。

Also check this out, may be useful http://www.mark-leong.com/installing-php-and-phpunit-on-windows-7/也检查一下,可能有用http://www.mark-leong.com/installing-php-and-phpunit-on-windows-7/

// adding required pear channels // 添加所需的梨通道

pear channel-update pear.php.net梨频道更新 pear.php.net

pear upgrade-all梨升级-所有

pear channel-discover pear.phpunit.de梨频道-发现 pear.phpunit.de

pear channel-discover components.ez.no pear channel-discover components.ez.no

pear channel-discover pear.symfony-project.com梨频道-发现 pear.symfony-project.com

pear update-channels梨更新频道

// performing install // 执行安装

pear install --alldeps --force phpunit/PHPUnit梨安装 --alldeps --force phpunit/PHPUnit

If everything ok, check whether phpunit have been installed by putting in command line如果一切正常,请在命令行中检查是否已安装 phpunit

phpunit -v phpunit -v

If you encountered any errors or interrupted installing如果您遇到任何错误或中断安装

pear clear-cache梨清除缓存

may be usefull in that case.在这种情况下可能有用。

1) download https://phar.phpunit.de/phpunit.phar 2) run it via php phpunit.phar 1) 下载https://phar.phpunit.de/phpunit.phar 2) 通过 php phpunit.phar 运行

Btw if that file ever goes away you can look at the original directions here: https://github.com/sebastianbergmann/phpunit顺便说一句,如果该文件消失了,您可以在此处查看原始说明: https : //github.com/sebastianbergmann/phpunit

I recommend using composer.我推荐使用作曲家。 It can be used per project, but also 'globally'.它可以用于每个项目,也可以“全局”使用。

Make a folder on your C drive called 'globalpackages', then cd into it from the command line.在 C 驱动器上创建一个名为“globalpackages”的文件夹,然后从命令行 cd 进入它。

run 'composer require phpunit/phpunit'运行“作曲家需要 phpunit/phpunit”

once that finishes run 'composer install'一旦完成运行'composer install'

once that finishes you can check the contents of C:\\globalpackages\\vendor\\phpunit' and should see two phpunit files, one of them a bat.完成后,您可以检查 C:\\globalpackages\\vendor\\phpunit' 的内容,应该会看到两个 phpunit 文件,其中一个是 bat。

Add C:\\globalpackages\\vendor\\phpunit to your system path and then you will be able to run phpuni from anywhere on your system.将 C:\\globalpackages\\vendor\\phpunit 添加到您的系统路径,然后您就可以从系统的任何位置运行 phpuni。

For me this is the fastests and easiest way.对我来说,这是最快和最简单的方法。

  1. Make sure you have wamp with WAMP with PHP 7 installed as phpunit requires PHP7 to work!确保你安装了 WAMP 和 PHP 7,因为 phpunit 需要 PHP7 才能工作! or at least 6.2或至少 6.2

  2. Go to folder wamp64\\bin\\php\\php7.0.10 (wherever you installed your wamp - BEWARE last folder is name of PHP version you have so it might be different then above )转到文件夹 wamp64\\bin\\php\\php7.0.10(无论您在哪里安装 wamp - 请注意最后一个文件夹是您拥有的 PHP 版本的名称,因此它可能与上面的不同)

We will be working in this folder during entire installation.我们将在整个安装过程中在此文件夹中工作。 So if I say edit file etc it means in this folder.因此,如果我说编辑文件等,则表示在此文件夹中。

  1. Download newest version of phpunit from https://phpunit.de/https://phpunit.de/下载最新版本的 phpunit

At the time of writing this I get version phpunit 6.2 and php7.0.10 4. Copy downloaded file to wamp64\\bin\\php\\php7.0.10 folder For me it's: phpunit-6.2.2.phar for you it might be different version.在写这篇文章的时候,我得到了 phpunit 6.2 和 php7.0.10 4. 将下载的文件复制到 wamp64\\bin\\php\\php7.0.10 文件夹对我来说: phpunit-6.2.2.phar 对你来说可能是不同的版本。

  1. Now change name of the phpunit-6.2.2.phar to phpunit.phar现在将phpunit-6.2.2.phar 的名称更改为 phpunit.phar

  2. Now make sure you have added your php to PATH in Environment Variables To do this on Windows 10 and Windows 8现在确保您已将 php 添加到环境变量中的 PATH 要在 Windows 10 和 Windows 8 上执行此操作

6a. 6a. In Search, search for and then select: System (Control Panel)在搜索中,搜索并选择:系统(控制面板)

6b. 6b. Click the Advanced system settings link.单击高级系统设置链接。

6c. 6c。 Click Environment Variables.单击环境变量。 In the section System Variables, find the PATH environment variable and select it.在 System Variables 部分,找到 PATH 环境变量并选择它。 Click Edit.单击编辑。 If the PATH environment variable does not exist, click New.如果 PATH 环境变量不存在,请单击新建。

6d. 6天。 In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable.在 Edit System Variable(或 New System Variable)窗口中,指定 PATH 环境变量的值。 Paste location of your PHP.粘贴 PHP 的位置。 For me it would be: D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10对我来说,它是:D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10

(if in PATH there was other command or path just add ";" at the end. For exmaple: (如果在 PATH 中有其他命令或路径,只需在末尾添加“;”即可。例如:

%someOtherCommand%; %someOtherCommand%; D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10) D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10)

6e. 6e。 Click OK.单击确定。 Close all remaining windows by clicking OK.单击确定关闭所有剩余的窗口。

  1. In cmd (to run cmd go to search in Windows and type cmd.exe and click Enter) go to folder wamp64\\bin\\php\\php7.0.10 (to go to folder type for example cd D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10 )在 cmd 中(要运行 cmd,请在 Windows 中搜索并输入 cmd.exe 并单击 Enter)转到文件夹 wamp64\\bin\\php\\php7.0.10(转到文件夹类型,例如cd D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10 )

  2. now once you are in this folder run this command in cmd: echo @php "%~dp0phpunit.phar" %* > phpunit.cmd现在一旦你在这个文件夹中,在 cmd 中运行这个命令: echo @php "%~dp0phpunit.phar" %* > phpunit.cmd

  3. now run this command:现在运行这个命令:

phpunit

you should get list of all commands available in phpunit你应该得到 phpunit 中所有可用命令的列表

now run this:现在运行这个:

phpunit --check-version

you will get info what phpunit version you have and if you are using the newest version.您将获得有关您拥有的 phpunit 版本以及是否使用最新版本的信息。

  1. if this doesn't work go to wamp64\\bin\\php\\php7.0.10如果这不起作用,请转到 wamp64\\bin\\php\\php7.0.10

  2. Edit file phpunit.bat编辑文件 phpunit.bat

  3. Add this line:添加这一行:

    ""%PHPBIN%" "D:\\AnyFolderYouInsalledWampTo\\wamp64\\bin\\php\\php7.0.10\\phpunit.phar" %*

  4. Repeat point 9.重复第 9 点。

  5. if it still doesn't work let me know.如果它仍然不起作用,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM