2011-04-07 83 views
1

我在运行OS X 10.6上的MAMP下运行phpunit时出现问题。我已经通过PEAR安装了phpunit,它存在于MAMP目录中,但是当我在终端中运行phpunit时,什么都没有发生。我猜这是一个路径问题,但作为一个OS X新手,我不知道如何解决它。这是当我尝试从/Applications/MAMP/bin/php5.3/bin在MAMP上安装Phing和PHPUnit

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

问题看起来非常相似,这How to Install phpunit 3.5 on mac with 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/ PHPUnit的位置php.ini

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

尝试运行或访问phing时会发生同样的问题。

所以再次,我猜这个问题是一个路径设置,但我不知道如何解决这个问题。

感谢

戴夫

UPDATE

感谢您的答复。 我的梨就是1.9.2 梨配置节目单

$ ./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的/Applications/MAMP/bin/php5.3/bin列出的PHPUnit除其他

-rwxr-xr-x 1 dave admin  920 6 Apr 19:55 phing 
[email protected] 1 dave admin 57583340 16 Feb 16:08 php 
-rwxr-xr-x 1 dave admin  2169 6 Apr 19:48 phpunit 

如上所述,在php.ini似乎列出正确的位置和回声$ 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 

回答

3

让我尝试了我就来的东西“通用PHPUnit的安装故障排除清单”。 (之前从来没有写过,所以我不能将你链接到任何东西)。

首先确保

pear version 

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

任何有关您所需的通道升级的消息都很重要,您应该执行建议的命令。

试图后:

pear install phpunit/phpunit --force --alldeps 

和重复,直到它停止抱怨缺少通道或通道升级。

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

重新安装梨

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


仍然没有运气?

pear config-show 

,并寻找“可执行目录”

如果没有“PHPUnit的”在该目录中二进制复检的安装工作,如果它没有告诉我们有关错误信息:)

二进制是有,但which phpunit不起作用

确保可执行目录中您的$ PATH或使用绝对路径,看看它是否工作

它执行了,但还有约缺少组件

确保PEAR directoryphp_dir)错误是你的php.ini的include_path


如果遇到更多麻烦,请让我/我们知道出了什么问题,然后我会尝试修改答案。

+0

感谢您的回复。 – Dave 2011-04-08 10:10:28

+0

它工作了吗?任何问题? – edorian 2011-04-08 10:23:04

+0

没有没有工作。我已经更新了上面的一些终端输出。 '哪个phpunit'和'哪个phing'都给出正确的位置'/ Applications/MAMP/bin/php5.3/bin/phpunit',但是当我输入phpunit --version时,我只是得到一个新的终端提示符。啊! – Dave 2011-04-08 10:34:13

1

我在没有PEAR的MAMP上安装了PHPUnit,我认为它可行。这是如何:

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

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

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。通常情况下,为include_path MAMP是这样的:

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.batinclude_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?

+0

处理include路径的另一种方法是将每个那些路径中的文件夹(丑陋路径但较少应对)。非常好的和详细的手动安装答案! – edorian 2011-04-08 17:02:14

+0

谢谢你们。我只是无法让它工作,所以unintalled mamp,启用了osx的php5.3并手动安装了pear。最后让phpunit以这种方式工作。 – Dave 2011-04-12 06:31:57

0

我确实有类似的问题,这要感谢我设法修复它的这个线程。 这是我如何做的: 其次edorian建议:

重新安装梨

我发现角落找寻那唯一的办法是 要通过重新安装保存 http://pear.php.net/go-pear.phar到 盘“另存为...”并运行PHP 去-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 

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

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

之后,我的phpunit再次工作! 感谢大家:)