Installing PHPUnit on MAMP 2.1.3 (Mountain Lion)

回眸只為那壹抹淺笑 提交于 2019-11-29 11:25:39

I'd recommend using composer. It's becoming a standard.

To start with, go to your project's root directory first and create a composer.json file there:

{
    "require-dev": {
        "phpunit/phpunit": "*"
    },
    "autoload": {
        "psr-0": {"": "src"}
    },
    "config": {
        "bin-dir": "bin"
    }
}

You can tune it to your needs later. You'll probably want to configure the autoloading if you'd like to leverage composer's autoloader (which I recomend).

Next download the composer:

curl -sS https://getcomposer.org/installer | php

The above script will not only download it but also verify your environment if it's suitable to run composer binary.

If everything goes well install your dependencies:

./composer.phar install --dev

PHPUnit binary will be installed in the bin directory (configured in composer.json):

./bin/phpunit --version

I've met this problem this morning and find this topic but no answer is helpful. After a couple of hours google search, I found this link, it helped me solve my problem http://www.startupcto.com/server-tech/macosx/installing-phpunit-on-mamp

My MAMP php version is 5.5.3 First, you'll probably need to update PEAR:

sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-update pear.php.net

sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear upgrade pear

After that, add the appropriate PEAR channels for PHPUnit:

sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-discover pear.phpunit.de
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-discover pear.symfony.com
sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear channel-discover components.ez.no

Finally, install PHPUnit:

sudo /Applications/MAMP/bin/php/php5.5.3/bin/pear install phpunit/PHPUnit

Test phpunit to make sure it was installed correctly:

/Applications/MAMP/bin/php/php5.5.3/bin/phpunit --version

Link phpunit to your path

sudo ln -s /Applications/MAMP/bin/php/php5.5.3/bin/phpunit /usr/local/bin/phpunit

Hope this help you and anyone meet this problem in the future!

You could try this solution from this site The php bin could vary from installation.

/Applications/MAMP/bin/php5/bin/pear channel-discover pear.phpunit.de
/Applications/MAMP/bin/php5/bin/pear channel-discover pear.symfony-project.com
/Applications/MAMP/bin/php5/bin/pear channel-discover components.ez.no
/Applications/MAMP/bin/php5/bin/pear install phpunit/PHPUnit
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!