-
Download https://github.com/bu-ist/sample-plugin/archive/master.zip
-
Copy everything (don't forget about hidden dot files like .travis.yml) into your plugin/theme except the following:
README.md
,sample-plugin.php
,.git
,.gitignore
. -
Update settings in the
tests/bootstrap.php
file to reflect your plugin/theme. -
Write tests.
-
If this is not the first run,cleanup from the files and database from prior runs:
ls /tmp/wordpress* rm -fr /tmp/wordpress* echo "drop database wordpress_test" | mysql -u root
-
Install WP tests:
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
-
Run phpunit in the plugin’s root directory
phpunit
If you run into problems with the phpunit
command reporting that it's unable to connect to your database, it could be the case that php is tying to use a socket that isn't available. This can happen when you installed mysql with homebrew, while using the default php installation on OSX. To debug this a issue, run the following commands to figure out which socket php is trying to use, and which socket your mysql server is using.
php -i | fgrep 'mysql.default_socket'
mysql -e 'show variables where variable_name = "socket"'
One potential fix for this specific scenario is to symlink the php default socket to the one used by the homebrew's mysql server.
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
To run code climate locally, grab an existing plugin or theme's .codeclimate.yml file:
- For plugins, use the one from the sample plugin repo.
- For themes, use the one from the responsive framework's child-starter.
Next, follow the instructions listed on the Code Climate repo, or continue by installing the prerequisites that are listed:
- Docker, or use Docker for Mac for macOS.
- Homebrew (only if on macOS)
Note: All of this information is available on the Code Climate repo. To continue, make sure you have Docker, or Docker for Mac for macOS.
To run Code Climate reports locally, the Docker image must be installed on your machine.
Run the following command in a Terminal session to pull down the Docker image:
docker pull codeclimate/codeclimate
This will download the Docker image that code climate will use to run its analysis tools.
After that finishes, code climate can now be run using the following example command:
docker run \
--interactive --tty --rm \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate help
But since that's a burden to type each time, it is preferred to use Code Climate's wrapper scripts.
The easiest way to install the codeclimate
command on macOS is with the homebrew
package manager. Install homebrew before continuing.
Otherwise, continue on to the next step.
In a Terminal session, run the following commands:
brew tap codeclimate/formulae
brew install codeclimate
If on Windows or another operating system, run the following commands:
curl -L https://github.com/codeclimate/codeclimate/archive/master.tar.gz | tar xvz
cd codeclimate-* && sudo make install
If using the wrapper scripts, the codeclimate
command should be available.
Test it by running codeclimate version
.
A list of commands is available on the Code Climate GitHub page. The following commands can be run in the root of your repository:
codeclimate analyze
codeclimate analyze includes/functions.php
codeclimate validate-config
You can debug and modify how your commands run by adding additional flags. See the Code Climate repo for official definitions of each flag. As an overview, these are the following known flags:
CODECLIMATE_DEBUG=1 codeclimate analyze
Prints additional information about the analysis steps, including any stderr produced by engines.
To increase the amount of time each engine container may run (default 15 min):
# 30 minutes
CONTAINER_TIMEOUT_SECONDS=1800 codeclimate analyze
You can also configure the default alotted memory with which each engine runs (default is 1,024,000,000 bytes):
# 2,000,000,000 bytes
ENGINE_MEMORY_LIMIT_BYTES=2000000000 codeclimate analyze
This could be due to a variety of factors:
- It could be hanging up on installing engines. Try running
codeclimate engines:install
first, before runningcodeclimate analyze
- There are a very large number of files in your repository that Code Climate
is trying to analyze at once. Be sure to specify all files and directories you
want Code Climate to skip using the
exclude_patterns
key in the yaml config file. - It could be hanging up on some assets that its trying to download in the
prepare
>fetch
key in the yaml config file. Make sure the repos are all public.