Installing Phing & PHPUnit on MAMP

I am having problems running phpunit in MAMP on OS X 10.6. I installed phpunit via PEAR and it exists in the MAMP directory, but when I run phpunit in the terminal, nothing happens. I am guessing this is a path problem, but as an os x newbie, I don't know how to fix this. This is what happens when I try to run it from / Applications / MAMP / bin / php 5.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's some more information about the system:

Phpunit location 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

      

Maybe the problem is here

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

      

My php.ini is from / Applications / MAMP / conf / php 5.3 / php.ini

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

      

The same problems occur when trying to run or access phing.

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

thank

Dave

UPDATE

thanks for your reply. 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 ./configure
--program-suffix passed to     php_suffix       <not set>
PHP ./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 lists phpunit among 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 php.ini seems to point to 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


source to share


3 answers


Let me try with what I came up with is a "universal phpunit installation troubleshooting kit". (Never wrote this down before, so I can't link you to anything).

First make sure

pear version

      

reports no less pear 1.9.2

. If not: pear install --force pear/pear

and check again. If that doesn't work, the only idea I left behind is to reinstall the pear. See below.

Any "required channel updates" messages you receive along the way are important and you must follow the commands provided.

After that try:

pear install phpunit/phpunit --force --alldeps

      

and repeat this until it stops complaining about missing channels or channel updates.

It may still complain about the need for PEAR 1.9.2, even when it pear version

shows 1.9.2. I could only fix this problem by reinstalling the pear.

Reinstalling the pear

The only way I've found arround is to reinstall the save http://pear.php.net/go-pear.phar to disk with "Save As ..." and runphp go-pear.phar




Not lucky yet?

pear config-show 

      

and find "executable directory"

If there are no phpunit binaries in that directory, check that the job was done and if it didn't tell us a bug :)

Binary is there but which phpunit

doesn't work

Make sure the executable is in your PATH or uses an absolute path to see if it works

Running, but errors for missing components

Make sure PEAR directory

( php_dir

) is your php.ini include_path


If you have any problems, let me / us understand what went wrong and I will try to adapt the answer.

+3


source


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

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

Follow the instructions on this github page: https://github.com/sebastianbergmann/phpunit/ - copy from this page (April 8, 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 this into terminal. This should give you a phpunit folder with phpunit and all dependencies inside. The next instruction is to copy all folders to your php include_path

. Find out where yours is include_path

in your file php.ini

. You are using MAMP, so it should be something like /Applications/MAMP/conf/php5.3/php.ini

. Usually include_path

for MAMP:

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

      

However, you cannot just copy and paste a folder, you will have to tediously figure out which folder to copy. You can know this by reading the file in package.xml

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, copy the folder phpunit

, LICENSE

, README.markdown

, phpunit.php

, phpunit.bat

in include_path

. After that go to folder dbunit

, folder php-file-iterator

, etc. Etc. It's a little tedious.

Make sure you DO NOT REPLACE ANY FOLDER, OSX does indeed replace every folder (instead of merging like any sane person), so if the folder already exists, it only copies the new folder / files. You should be able to figure out which folder will be copied easily with some logic.

After that copy phpunit.php

to any folder, then edit the first line:

#!/usr/bin/env php

      

in



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

      

Change the resolution phpunit.php

so we can execute it:

chmod 744 phpunit.php

      

You should be able to run it like this:

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

      

Hope it helps.


If you are looking to update PEAR or find out something about this quirk when used on MAMP OSX, there is a good discussion here:

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


Old discussion about installing PHPUnit without PEAR:

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

+1


source


I had a similar problem, thanks to this thread I managed to fix it. This is how I did it: The following edorian suggestion:

Reinstalling the pear

The only way I've found arround is to Reinstall saving http://pear.php.net/go-pear.phar to disk via "Save As ..." and run php go-pear.phar

Then it is 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 ./configure
--program-suffix passed to     php_suffix       <not set>
PHP ./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 that there were two config files for the system, one for the system and one for the user (see the bottom of config-show.

I backed up my conf file and replaced it with the system one. Then I needed to set the php_ini parameter in / Applications / MAMP / conf / php 5.3 / php.ini (seemed to be missing from the system config file).

After that my phpunit works again! Thanks everyone :)

0


source







All Articles