在 Mac OS X 上安装带 XAMPP 的 PHPUnit

发布于 2024-11-08 12:28:11 字数 537 浏览 4 评论 0原文

有谁知道如何在 Mac OS X 上安装 PHPUnit(我使用的是 XAMPP)。我尝试了以下命令,它说安装成功(没有错误)。现在,当我尝试在终端中运行 phpunit 命令时,出现错误,提示找不到命令 phpunit。另外,运行“which phpunit”不会返回任何内容。

我运行的命令:

    $sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.phpunit.de
    $sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.symfony-project.com
    $sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover components.ez.no
    $sudo /Applications/XAMPP/xamppfiles/bin/pear install -a phpunit/PHPUnit

谢谢。

Does anyone know how to install PHPUnit on Mac OS X (I'm using XAMPP). I tried the following commands and it said installation succeeded (no errors). Now, when I try to run a phpunit command in Terminal, I get an error that the command phpunit could not be found. Also, running "which phpunit" returns nothing.

The commands I ran:

    $sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.phpunit.de
    $sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover pear.symfony-project.com
    $sudo /Applications/XAMPP/xamppfiles/bin/pear channel-discover components.ez.no
    $sudo /Applications/XAMPP/xamppfiles/bin/pear install -a phpunit/PHPUnit

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哭了丶谁疼 2024-11-15 12:28:11

通过 XAMPP 安装 PHPunit 几乎让我发疯,一个错误告诉我我的 xdebug 版本太旧,无法安装 PHPunit 所需的 Coverage lib,三秒后另一个错误告诉我一切都很好,但没有安装 phpunit 命令。

我选择通过在系统级别(XAMPP 之外)安装 phpunit 来绕过该问题。

cd /tmp
curl http://pear.php.net/go-pear.phar > go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar

这应该安装 pear (并告诉你在哪里,默认是在你家里)。

cd ~/pear/bin
sudo ./pear channel-discover pear.phpunit.de
sudo ./pear channel-discover pear.symfony-project.com
sudo ./pear channel-discover components.ez.no
sudo ./pear install -a phpunit/PHPUnit

./phpunit 现在应该返回一些东西(在我的例子中,它显示一些未满足的导入。

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in ~/pear/share/pear/PHPUnit/Autoload.php on line 45

Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:') in ~/pear/share/pear/PHPUnit/Autoload.php on line 45

如果您没有 /etc/php.ini,请创建它:

sudo cp /etc/php.ini.default /etc/php.ini

然后编辑 /etc/php.ini 并设置正确的路径:

include_path = ".:/php/includes:/Users/YOURUSERNAME/pear/share/pear"

然后在你的 pear bin 目录中调用 ./phpunit 应该可以工作...与 Ubuntu 上的一些 aptitude 和 pear 调用相比,这是相当痛苦的,但它可以让你在 OSX 上工作,你应该仍然可以使用 XAMPP 作为网络服务器。但请记住XAMPP 使用其内置 PHP 环境,phpunit 将使用您的系统之一。

Installing PHPunit through XAMPP almost drove me mad, an error was telling me that my xdebug version was to old to install the Coverage lib required for PHPunit, three seconds later another was telling me that everything was fine but no phpunit command was installed.

I've chosen to bypass that problem by installing phpunit at system level (outside of XAMPP).

cd /tmp
curl http://pear.php.net/go-pear.phar > go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar

This should install pear (and tell you where, default is in your home).

cd ~/pear/bin
sudo ./pear channel-discover pear.phpunit.de
sudo ./pear channel-discover pear.symfony-project.com
sudo ./pear channel-discover components.ez.no
sudo ./pear install -a phpunit/PHPUnit

./phpunit should now return you something (in my case it's displaying that some import where unmet.

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in ~/pear/share/pear/PHPUnit/Autoload.php on line 45

Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:') in ~/pear/share/pear/PHPUnit/Autoload.php on line 45

If you don't have a /etc/php.ini, create it:

sudo cp /etc/php.ini.default /etc/php.ini

Then edit /etc/php.ini and set the right path:

include_path = ".:/php/includes:/Users/YOURUSERNAME/pear/share/pear"

Then calling ./phpunit in your pear bin directory should work... It's quite a pain comparing to a few aptitude and pear call on Ubuntu, but it let you work on OSX. You should be able to still use XAMPP as a webserver but remember that XAMPP uses its buildin PHP environment, phpunit will use the one of your system.

神回复 2024-11-15 12:28:11

AsTeR 的方法对我有用,因为使用旧的 PHP 5.3.1 当前 PHPUnit 版本会抱怨,因为缺少函数 stream_resolve_include_path

所以我最终将解决方案与这个答案一起使用: https://stackoverflow.com/a/8249291

AsTeR's method worked for me though because being stuck with old PHP 5.3.1 current PHPUnit versions will complain because function stream_resolve_include_path is missing.

So I ended up used the solution together with this answer: https://stackoverflow.com/a/8249291

薄荷港 2024-11-15 12:28:11

我按照@trent-scott 的做法做了,并得到了同样的错误。

Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:')

您可以注意到有一个空的包含路径 (include_path='.:')..

转到您的 php.ini 文件。通过在终端“php --ini”中执行此操作来找出哪个。

确保文件中的某处有与此类似的内容(请务必替换用户名):

include_path=".:/Users/hfossli/pear/share/pear"

它应该足够了,但由于某种原因我得到了这个(请务必替换用户名):

include_path=".:/Applications/XAMPP/xamppfiles/lib/php/pear:/Applications/XAMPP/xamppfiles/lib/php/pear:/Users/hfossli/pear/share/pear"

I did as @trent-scott did and got same error.

Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:')

As you can notice there is an empty include path (include_path='.:')..

Go to your php.ini file. Figure out which by doing this in terminal 'php --ini'.

Make sure you've got something similar to this somewhere in the file (be sure to replace username):

include_path=".:/Users/hfossli/pear/share/pear"

It should be sufficient, but I for some reason got this (be sure to replace username):

include_path=".:/Applications/XAMPP/xamppfiles/lib/php/pear:/Applications/XAMPP/xamppfiles/lib/php/pear:/Users/hfossli/pear/share/pear"
撕心裂肺的伤痛 2024-11-15 12:28:11

我资助了另一个对我有用的临时解决方案。不要直接在 Xampp 应用程序中使用 pear 命令,而是尝试使用 pear 可执行文件的完整路径,例如: /Applications/XAMPP/xamppfiles/bin/pear

希望它有所帮助。

I fund an other temporary solution that worked for me. Instead of using the pear command directly within your Xampp app, try using the full path to pear executable like : /Applications/XAMPP/xamppfiles/bin/pear

hope it helped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文