darudaru

だるだるしてるエンジニア

MacにcomposerでPHPUnitをインストールする

MacにcomposerでPHPUnitをインストールした時の手順です。composerのglobalコマンドを使用してインストールしました。

環境

  • MacOS Sierra 10.12.2

composerでPHPUnitをインストールする

どのPHPUnitのバージョンを指定すべきかは公式サイトで確認しておきましょう。今回は公式サイトの指定通り、PHPUnitの5.5のバージョンを指定しています。

% composer global require "phpunit/phpunit=5.5.*" [~]

Changed current directory to /Users/xxxxx/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- phpunit/phpunit 5.5.7 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.6 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.5 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.4 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.3 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.2 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.1 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- phpunit/phpunit 5.5.0 requires php ^5.6 || ^7.0 -> your PHP version (5.4.45) does not satisfy that requirement.
- Installation request for phpunit/phpunit 5.5.* -> satisfiable by phpunit/phpunit[5.5.0, 5.5.1, 5.5.2, 5.5.3, 5.5.4, 5.5.5, 5.5.6, 5.5.7].

Installation failed, deleting ./composer.json.

パスを通す

zshを使っているので.zprofileに追加します。bash使っている人は.bash_profileに追記をすれば大丈夫です。

% vi .zprofile
export PATH=$HOME/.composer/vendor/bin:$PATH

追加したら.zprofileを再読み込みします。

% source .zprofile

PHPUnitのコマンドが実行できるか確認する

% phpunit -v
PHPUnit 5.5.7 by Sebastian Bergmann and contributors.

無事インストール完了です。