Skip to content

Instantly share code, notes, and snippets.

@DavMorr
Last active February 23, 2018 20:40
Show Gist options
  • Save DavMorr/b01a365cae8a5b04196ac132ae97f9ce to your computer and use it in GitHub Desktop.
Save DavMorr/b01a365cae8a5b04196ac132ae97f9ce to your computer and use it in GitHub Desktop.
Installation instructions for some command line code review tools on Mac

CodeSniffer

via Composer (Drupal specific):

composer global require drupal/coder
composer global show -P  # should be equivalent to ~/.composer/vendor/drupal/coder
# Register Coder Standards: Drupal and DrupalPractice
composer global require drupal/coder:^8.2.12
composer global require dealerdirect/phpcodesniffer-composer-installer
# Review standards
phpcs -i

Manually:

curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
php phpcs.phar -h

curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
php phpcbf.phar -h

PHPUnit

Manually:

curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

via Composer:

Safer (project dependency):

In your project’s root directory use this command.

composer require --dev phpunit/phpunit ^6.0

This command adds PHPUnit to your project as a development dependency. This is the absolute best way to install PHPUnit. It is the best way because this way the version of PHPUnit does not change unless you change it. We specified ^6.0 as the version which means we’ll get all the updates to the 6.0 branch but not 6.1.

Harder (global dependency):

composer global require phpunit/phpunit ^6.0

On MacOS and Linux machines, this will install PHPUnit in ~/.composer/vendor/bin. If you add this directory to your path, then from any project, you can execute PHPUnit. However, as noted above, if you ever upgrade your globally installed packages then you will have problems.

composer global update

Run that when there is a new version of PHPUnit, it will be installed, regardless of whether this will break your existing unit tests on one or more of your projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment