Setting up PHPUnit on OSX

梦想与她 提交于 2019-12-02 14:22:18
Andy

To install via terminal:

curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar

chmod +x phpunit.phar

mv phpunit.phar /usr/local/bin/phpunit

We can installed it using Homebrew

$ brew install phpunit

Via homebrew (only if you've installed php via homebrew as well):

brew tap josegonzalez/php
brew install phpunit

Ahhh.... OK ... I think I might have gotten it working now.

the answer was present in the PHPUnit documentation. http://www.phpunit.de/manual/3.4/en/installation.html

After the installation you can find the PHPUnit source files inside your local PEAR directory; the path is usually /usr/lib/php/PHPUnit.

The Mac version of PEAR that I was running, did install PHPUnit if I ran all the commands listed under the "SUDO" user eg:

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear upgrade-all

At this point, all the files are downloaded to /usr/local/pear but the command

phpunit

is looking to include files from /usr/lib/php/PHPUnit The solution? To copy the PHPUnit folder from

cp /usr/lib/pear/PHPUnit /usr/lib/php

OR

make a symlink

cd /usr/lib/php
ln -s /usr/lib/pear/PHPUnit PHPUnit

I've seen a lot of people with similar problems, but this particular solution hadn't come up in any of the threads I've seen. Hopefully of use to you :) -Alex

You can try installation with Composer. In this way you would isolate the PHPUnit version for the current project avoiding possible problems that might arise when using a single system-wide setup for different projects. As the PHPUnit documentation states (http://phpunit.de/manual/current/en/installation.html#installation.composer), installation is quite easy.

Add the dependency to your composer.json file:

  {
     "require-dev": {
        "phpunit/phpunit": "4.0.*"
      }
  }

Then update dependencies:

composer update

And PHPUnit is ready to use by running :

./vendor/bin/phpunit

Remember to adjust this path if you change the composer install path, which defaults to 'vendor'.

Install PHPUnit

curl https://phar.phpunit.de/phpunit.phar -o phpunit.phar

chmod +x phpunit.phar

mv phpunit.phar /usr/local/bin/phpunit

OR if you have already install PHPUnit then just try this line to update PHPUnit by terminal

 phpunit --self-update

this will update your phpunit.phar file.

Mohammed Jafar
  1. Download phpunit manually from: https://phar.phpunit.de/phpunit.phar
  2. Move to downloaded folder: $ cd /to/the/download/directory
  3. Rename downloaded phpunit to the phpunit.phar
  4. $ chmod +x phpunit.phar
  5. $ sudo mv phpunit.phar /usr/local/bin/phpunit
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!