-
Notifications
You must be signed in to change notification settings - Fork 24
Testing Locally
A great way for us to keep this project running and limit the number of bugs is through testing. This project runs a travis-ci
build for every pull request made against master. That build runs a suite of unit tests as well as a linter check. If you are contributing to this repository you should try and write a test around your change in order to codify the behavior your are expecting. In order to run either the linter or unit tests you will need to install the require-dev
dependencies for this project. This is traditionally done through the composer update
command.
This project uses phpunit
to power its unit tests. Once you have installed all of the require-dev
dependencies for this project, you can run the entire suite of unit tests from the project root directory using the following command:
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/
Assuming no tests fail you should see output like this:
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
............................................................... 63 / 136 ( 46%)
............................................................... 126 / 136 ( 92%)
.......... 136 / 136 (100%)
Time: 89 ms, Memory: 8.00MB
OK (136 tests, 142 assertions)
Should you want to run only certain tests you can follow the instructions listed here in the phpunit docs: https://phpunit.de/getting-started/phpunit-7.html
During the PR process linting will be run against altered files in the src/
directory in an attempt to keep the code-base to a standard. If you want to run the linter locally for the entire project you will need to install the require-dev
dependencies for this project and then from the project root run the following command:
./vendor/bin/phpcs --standard=PSR12 src/
Should there be no style issues then there will be no output for this command. However should the linter finds a style issue you might see output similar to the following:
FILE: /home/hutch/Desktop/Projects/MailChimp-API/src/Resources/Account.php
--------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------
31 | ERROR | [x] Expected 1 blank line at end of file; 2 found
--------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------
Time: 299ms; Memory: 8Mb
You will note that output states that the marked violation can be fixed using phpcbf
if you wish for the linter to correct any marked violations, you can run the following:
./vendor/bin/phpcbf --standard=PSR12 src/
The repository along with it documentation for the linter can be found at this link: https://github.com/squizlabs/PHP_CodeSniffer