Installing Phing & PHPUnit on MAMP

回眸只為那壹抹淺笑 提交于 2019-12-30 05:35:10

问题


I'm having problems running phpunit under MAMP on OS X 10.6. I've installed phpunit via PEAR and it is exists in the MAMP directory but when I run phpunit in terminal nothing happens. I'm guessing that this is a path problem but as a os x newbie, I don't know how to fix it. This is what happens when I try to run it from /Applications/MAMP/bin/php5.3/bin

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

The problem looks very similar to this How to Install phpunit 3.5 on mac with MAMP but the solutions there haven't worked so far. Here is some more system info:

Location of phpunit in 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

Possibly the problem here

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

My php.ini from /Applications/MAMP/conf/php5.3/php.ini

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

The same issues happen when trying to run or access phing.

So again, I'm guessing the problem is a path setting but I'm not sure how to fix this.

Thanks

Dave

UPDATE

thanks for your response. My pear is 1.9.2 pear config show lists

$ ./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 lists phpunit amongst others

-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

As noted above, the php.ini seems to list the correct location and echo $PATH generates

$ 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

回答1:


Let my try with what I've come to thing of the "generic phpunit install troubleshooting list". (Never written that down before so i can't link you to anything).

First of make sure that

pear version

reports at least pear 1.9.2. If not: pear install --force pear/pear and check again. If that doesn't work the only Idea I've got left is to reinstall pear. See below.

Any messages about "needed channel upgrades" you will get in the process are important and you should execute the suggested commands.

After that try:

pear install phpunit/phpunit --force --alldeps

and repeat that until it stops complaining about missing channels or channel upgrades.

It still might complain about needing PEAR 1.9.2 even when pear version shows 1.9.2. I could only solve this by reinstalling pear.

Reinstalling pear

The only way i found arround that is To reinstall save http://pear.php.net/go-pear.phar to disk via 'Save as...' and run php go-pear.phar


Still no luck?

pear config-show 

and look for the "executable directory"

If there is no "phpunit" binary in that directory recheck that the installing worked and if it didn't tell us about the error message :)

Binary is there but which phpunit doesn't work

Make sure that executable directory is in your $PATH or use the absolute path to see if it works

It executes but there are errors about missing components

Make sure the PEAR directory (php_dir) is your php.ini's include_path


If you run into any more troubles let me/us know what went wrong and I'll try to adapt the answer.




回答2:


I installed PHPUnit on MAMP without PEAR, I think it works. Here's how:

Chances are, you have git installed already. If not, http://help.github.com/mac-set-up-git/

Follow the instructions on this github page: https://github.com/sebastianbergmann/phpunit/ - copying from that page (8 April 2010):

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

Copy and paste that to terminal. That should give you a phpunit folder with phpunit and all the dependencies inside. The next instruction is to copy all the folders into your php include_path. Find out where your include_path is in your php.ini file. You're using MAMP, so it should be something like /Applications/MAMP/conf/php5.3/php.ini. Usually the include_path for MAMP is this:

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

However you cannot just copy and paste the folder, you have to tediously figure out which folder to copy. You can know this by reading the package.xml file of each folder. Start with 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>

So you copy the the PHPUnit folder, LICENSE, README.markdown, phpunit.php, phpunit.bat to your include_path. After this, move to dbunit folder, php-file-iterator folder, and so on and so forth. It's a bit tedious.

Make sure you DON'T REPLACE ANY FOLDER, OSX really replaces each folder (instead of merging like any sane person would), so if the folder already exists, it copy only the new folder/files. You should be able to figure out which folder to copy easily by a bit of logic.

After this, copy phpunit.php to any folder, then edit the first line:

#!/usr/bin/env php

to:

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

Change the permission of phpunit.php so that we can execute it:

chmod 744 phpunit.php

You should be able to run it like this:

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

Hope this helps.


If you wanted to upgrade PEAR or learn something about it's quirkiness when used in MAMP OSX, there's a good discussion here:

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


Old discussion on installing PHPUnit without PEAR:

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




回答3:


I did have a similar issue, thanks to this thread I managed to fix it. Here is how I did it : Followed edorian suggestion :

Reinstalling pear

The only way i found arround that is To reinstall save http://pear.php.net/go-pear.phar to disk via 'Save as...' and run php go-pear.phar

Then called pear config-show to see this :

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

I could see there was two config files one for the system and one for the user (see a the bottom of the config-show.

I backed up my user conf file and replaced it by the system one. Then I needed to set the php_ini setting to /Applications/MAMP/conf/php5.3/php.ini (seemed to be absent from the system config file).

After that my phpunit worked again! Thanks to everyone :)



来源:https://stackoverflow.com/questions/5588613/installing-phing-phpunit-on-mamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!