【问题标题】:Installing Phing & PHPUnit on MAMP在 MAMP 上安装 Phing 和 PHPUnit
【发布时间】:2011-08-01 02:38:54
【问题描述】:

我在 OS X 10.6 上的 MAMP 下运行 phpunit 时遇到问题。我已经通过 PEAR 安装了 phpunit,它存在于 MAMP 目录中,但是当我在终端中运行 phpunit 时没有任何反应。我猜这是一个路径问题,但作为一个 os x 新手,我不知道如何解决它。当我尝试从 /Applications/MAMP/bin/php5.3/bin 运行它时会发生这种情况

$ phpunit
-bash: /usr/bin/phpunit: No such file or directory
$ ./phpunit
$

这个问题看起来与How to Install phpunit 3.5 on mac with MAMP 非常相似,但那里的解决方案到目前为止还没有奏效。以下是更多系统信息:

phpunit 在 MAMP 中的位置

$ sudo find / -name "phpunit"
/Applications/MAMP/bin/php5.3/bin/phpunit
/Applications/MAMP/bin/php5.3/lib/php/PEAR/phing/tasks/ext/phpunit
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

可能是这里的问题

$ which php
/usr/bin/php
$ which phpunit
$ which pear
$ which ./pear
./pear
$ which ./phpunit
./phpunit

我的 php.ini 来自 /Applications/MAMP/conf/php5.3/php.ini

include_path = ".:/Applications/MAMP/bin/php5.3/lib/php:/Applications/MAMP/bin/php5.3/lib/php/PEAR/"

在尝试运行或访问 phing 时会出现同样的问题。

再说一次,我猜问题出在路径设置上,但我不知道如何解决这个问题。

谢谢

戴夫

更新

感谢您的回复。 我的梨是1.9.2 pear config 显示列表

$ ./pear config-show
Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          /Applications/MAMP/bin/php5.3/bin
PEAR documentation directory   doc_dir          /Applications/MAMP/bin/php5.3/lib/php/doc
PHP extension directory        ext_dir          /Applications/MAMP/bin/php5.3/lib/php/extensions
PEAR directory                 php_dir          /Applications/MAMP/bin/php5.3/lib/php/PEAR
PEAR Installer cache directory cache_dir        /tmp/pear/cache
PEAR configuration file        cfg_dir          /Applications/MAMP/bin/php5.3/lib/php/cfg
directory
PEAR data directory            data_dir         /Applications/MAMP/bin/php5.3/lib/php/data
PEAR Installer download        download_dir     /tmp/pear/cache
directory
PHP CLI/CGI binary             php_bin          /Applications/MAMP/bin/php5.3/bin/php
php.ini location               php_ini          /Applications/MAMP/conf/php5.3/php.ini
--program-prefix passed to     php_prefix       <not set>
PHP's ./configure
--program-suffix passed to     php_suffix       <not set>
PHP's ./configure
PEAR Installer temp directory  temp_dir         /tmp/pear/temp
PEAR test directory            test_dir         /Applications/MAMP/bin/php5.3/lib/php/test
PEAR www files directory       www_dir          /Applications/MAMP/bin/php5.3/lib/php/www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            22
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          /usr/local/bin/gpg
Signature Key Directory        sig_keydir       /Applications/MAMP/conf/php5.3/pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         /Users/dave/.pearrc
System Configuration File      Filename         /Applications/MAMP/conf/php5.3/pear.conf'

ls -al of /Applications/MAMP/bin/php5.3/bin 列出了 phpunit 等

-rwxr-xr-x   1 dave  admin       920  6 Apr 19:55 phing
-r-xr-xr--@  1 dave  admin  57583340 16 Feb 16:08 php
-rwxr-xr-x   1 dave  admin      2169  6 Apr 19:48 phpunit

如上所述,php.ini 似乎列出了正确的位置并 echo $PATH 生成

$ echo $PATH
/Applications/MAMP/bin/php5.3/bin:/Applications/MAMP/bin/php5.3/lib/php:/Applications/MAMP/bin/php5.3/lib/php/PEAR/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

【问题讨论】:

    标签: macos osx-snow-leopard phpunit mamp phing


    【解决方案1】:

    让我尝试一下“通用 phpunit 安装故障排除列表”中的内容。 (以前从未写下,所以我无法将您链接到任何内容)。

    首先确定

    pear version
    

    至少报告pear 1.9.2。如果不是:pear install --force pear/pear 并再次检查。如果这不起作用,我剩下的唯一想法就是重新安装梨。见下文。

    您将在此过程中收到有关“需要频道升级”的任何消息,您应该执行建议的命令。

    之后尝试:

    pear install phpunit/phpunit --force --alldeps
    

    并重复此操作,直到它不再抱怨缺少频道或频道升级。

    仍然可能会抱怨需要 PEAR 1.9.2,即使 pear version 显示 1.9.2。我只能通过重新安装 pear 来解决这个问题。

    重新安装梨

    我发现的唯一方法是通过“另存为...”将http://pear.php.net/go-pear.phar 重新安装到磁盘并运行php go-pear.phar


    还是没有运气?

    pear config-show 
    

    并寻找“可执行目录”

    如果该目录中没有“phpunit”binary,请重新检查安装是否正常,如果它没有告诉我们错误消息:)

    二进制文件存在,但 which phpunit 不起作用

    确保可执行目录在您的 $PATH 中或使用绝对路径查看它是否有效

    它执行了,但是有关于缺少组件的错误

    确保PEAR directory (php_dir) 是您的 php.ini 的 include_path


    如果您遇到更多麻烦,请告诉我/我们出了什么问题,我会尝试调整答案。

    【讨论】:

    • No 没有用。我已经更新了上面的一些终端输出。 which phpunitwhich phing 都给出了正确的位置 /Applications/MAMP/bin/php5.3/bin/phpunit 但是当我输入 phpunit --version 时,我只是得到一个新的终端提示。啊!
    • @Dave:尝试发出phpunit 的完整路径。因此,不要尝试phpunit --version,而是尝试/Applications/MAMP/bin/php5.3/bin/phpunit --version --verbose。此外,请确保该文件顶部的 PHP 二进制文件路径正确(默认为 #!/usr/bin/php)...
    • @Dave 我试着让更多的人来这里(比如 ircmaxell),但我不知道为什么你只是得到一个新的终端提示。对不起。
    • 大家好,这是我得到的 => 什么都没有! $ /Applications/MAMP/bin/php5.3/bin/phpunit --version --verbose $ 非常感谢您的帮助,但我完全被难住了!
    • 一旦我将 pear 配置正确指向 MAMP,我就可以找到 phpunit 二进制文件,但仍然有错误。然后我不得不卸载 phpunit 并从 pear 重新安装它,所以 pear uninstall phpunit/PHPUnit 然后是 pear install phpunit/PHPUnit 然后一切都很好
    【解决方案2】:

    我在没有 PEAR 的 MAMP 上安装了 PHPUnit,我认为它可以工作。方法如下:

    很有可能,你已经安装了 git。如果没有,http://help.github.com/mac-set-up-git/

    按照此 github 页面上的说明进行操作:https://github.com/sebastianbergmann/phpunit/ - 从该页面复制(2010 年 4 月 8 日):

    mkdir phpunit && cd phpunit
    git clone git://github.com/sebastianbergmann/phpunit.git
    git clone git://github.com/sebastianbergmann/dbunit.git
    git clone git://github.com/sebastianbergmann/php-file-iterator.git
    git clone git://github.com/sebastianbergmann/php-text-template.git
    git clone git://github.com/sebastianbergmann/php-code-coverage.git
    git clone git://github.com/sebastianbergmann/php-token-stream.git
    git clone git://github.com/sebastianbergmann/php-timer.git
    git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
    git clone git://github.com/sebastianbergmann/phpunit-selenium.git
    

    复制并粘贴到终端。这应该会给你一个 phpunit 文件夹,里面有 phpunit 和所有依赖项。下一条指令是将所有文件夹复制到您的 php include_path 中。找出您的include_path 在您的php.ini 文件中的位置。您正在使用 MAMP,所以它应该类似于 /Applications/MAMP/conf/php5.3/php.ini。通常 MAMP 的 include_path 是这样的:

    include_path = ".:/Applications/MAMP/bin/php5.3/lib/php"
    

    但是您不能只是复制和粘贴文件夹,您必须繁琐地找出要复制的文件夹。您可以通过阅读每个文件夹的package.xml 文件来了解这一点。以phpunit开头:

    <dir name="/">
        <dir name="PHPUnit">
        ...
        </dir>
        <file baseinstalldir="/" name="ChangeLog.markdown" role="doc"/>
        <file baseinstalldir="/" name="LICENSE" role="doc"/>
        <file baseinstalldir="/" name="README.markdown" role="doc"/>
        <file baseinstalldir="/" name="phpunit.php" role="script">
            ...
        </file>
        <file baseinstalldir="/" name="phpunit.bat" role="script">
            ...
        </file>
    </dir>
    

    因此,您将PHPUnit 文件夹、LICENSEREADME.markdownphpunit.phpphpunit.bat 复制到您的include_path。在此之后,移动到dbunit 文件夹、php-file-iterator 文件夹等等。这有点乏味。

    确保不要替换任何文件夹,OSX 真的 替换每个文件夹(而不是像任何理智的人那样合并),所以如果文件夹已经存在,它只复制新的文件夹/文件。您应该能够通过一些逻辑轻松确定要复制哪个文件夹。

    之后,将phpunit.php复制到任意文件夹,然后编辑第一行:

    #!/usr/bin/env php
    

    到:

    #!/usr/bin/env /Applications/MAMP/bin/php5.3/bin/php
    

    更改phpunit.php的权限,以便我们执行:

    chmod 744 phpunit.php
    

    你应该可以这样运行它:

    ./path/to/phpunit.php testCase.php
    

    希望这会有所帮助。


    如果你想升级 PEAR 或了解它在 MAMP OSX 中使用时的古怪之处,这里有一个很好的讨论:

    https://serverfault.com/questions/184741/upgrading-pear-from-1-9-0-to-1-9-1-fails


    关于不带 PEAR 安装 PHPUnit 的旧讨论:

    How do you install PHPUnit without using PEAR on Mac OS X 10.5?

    【讨论】:

    • 另一种处理包含路径的方法是将这些文件夹中的每一个放在路径中(路径更丑但应对更少)。手动安装的很好很详细的回答!
    • 谢谢大家。我只是无法让它工作如此 unintalled mamp,启用 osx 的 php5.3 并手动安装 pear。终于让 phpunit 以这种方式工作了。
    【解决方案3】:

    我确实遇到了类似的问题,感谢这个帖子我设法解决了它。 这是我的做法: 遵循edorian的建议:

    重新安装梨

    我发现的唯一方法是 重新安装保存 http://pear.php.net/go-pear.phar 到 通过“另存为...”磁盘并运行 php go-pear.phar

    然后打电话给pear config-show 看到这个:

    Configuration (channel pear.php.net):
    =====================================
    Auto-discover new Channels     auto_discover    <not set>
    Default Channel                default_channel  pear.php.net
    HTTP Proxy Server Address      http_proxy       <not set>
    PEAR server [DEPRECATED]       master_server    pear.php.net
    Default Channel Mirror         preferred_mirror pear.php.net
    Remote Configuration File      remote_config    <not set>
    PEAR executables directory     bin_dir          /Users/mbritto/pear/bin
    PEAR documentation directory   doc_dir          /Users/mbritto/pear/docs
    PHP extension directory        ext_dir          /Applications/MAMP/bin/php5.3/lib/php/extensions
    PEAR directory                 php_dir          /Users/mbritto/pear/share/pear
    PEAR Installer cache directory cache_dir        /tmp/pear/cache
    PEAR configuration file        cfg_dir          /Users/mbritto/pear/cfg
    directory
    PEAR data directory            data_dir         /Users/mbritto/pear/data
    PEAR Installer download        download_dir     /tmp/pear/install
    directory
    PHP CLI/CGI binary             php_bin          /Applications/MAMP/bin/php5.3/bin/php
    php.ini location               php_ini          /Applications/MAMP/conf/php5.3/php.ini
    --program-prefix passed to     php_prefix       <not set>
    PHP's ./configure
    --program-suffix passed to     php_suffix       <not set>
    PHP's ./configure
    PEAR Installer temp directory  temp_dir         /tmp/pear/install
    PEAR test directory            test_dir         /Users/mbritto/pear/tests
    PEAR www files directory       www_dir          /Users/mbritto/pear/www
    Cache TimeToLive               cache_ttl        3600
    Preferred Package State        preferred_state  stable
    Unix file mask                 umask            22
    Debug Log Level                verbose          1
    PEAR password (for             password         <not set>
    maintainers)
    Signature Handling Program     sig_bin          /usr/local/bin/gpg
    Signature Key Directory        sig_keydir       /Applications/MAMP/conf/php5.3/pearkeys
    Signature Key Id               sig_keyid        <not set>
    Package Signature Type         sig_type         gpg
    PEAR username (for             username         <not set>
    maintainers)
    User Configuration File        Filename         /Users/mbritto/.pearrc
    System Configuration File      Filename         /Applications/MAMP/conf/php5.3/pear.conf
    

    我可以看到有两个配置文件,一个用于系统,一个用于用户(请参阅配置显示的底部。

    我备份了我的用户配置文件并将其替换为系统配置文件。然后我需要将 php_ini 设置设置为 /Applications/MAMP/conf/php5.3/php.ini (系统配置文件中似乎没有)。

    在那之后我的 phpunit 又工作了! 谢谢大家:)

    【讨论】: