在 Mac OS X 上安装 PHPUnit w/ XAMPP


Installing PHPUnit w/ XAMPP on Mac OS X

有谁知道如何在Mac OS X上安装PHPUnit(我使用的是XAMPP)。我尝试了以下命令,它说安装成功(没有错误)。现在,当我尝试在终端中运行 phpunit 命令时,我收到一个错误,指出找不到命令 phpunit。此外,运行"哪个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

谢谢。

通过 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

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

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"

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

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

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

我像@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"

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

希望它有帮助。