Skip to content

bu-ist/sample-plugin

 
 

Repository files navigation

Travis CI Build Status CircleCI

Running Tests

  1. Download https://github.com/bu-ist/sample-plugin/archive/master.zip

  2. 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.

  3. Update settings in the tests/bootstrap.php file to reflect your plugin/theme.

  4. Write tests.

  5. 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
    
  6. Install WP tests:

    bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
    
  7. Run phpunit in the plugin’s root directory

    phpunit
    

Trouble Shooting

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

Running Code Climate locally

Prerequisites

To run code climate locally, grab an existing plugin or theme's .codeclimate.yml file:

Next, follow the instructions listed on the Code Climate repo, or continue by installing the prerequisites that are listed:

Installation

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.

Install script for macOS using Homebrew

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:

  1. brew tap codeclimate/formulae
  2. brew install codeclimate

Install script for any os (Windows, Linux, etc)

If on Windows or another operating system, run the following commands:

  1. curl -L https://github.com/codeclimate/codeclimate/archive/master.tar.gz | tar xvz
  2. cd codeclimate-* && sudo make install

Example commands

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:

Analyze the entire repo

codeclimate analyze

Analyze just one file

codeclimate analyze includes/functions.php

Validate the contents of your codeclimate file

codeclimate validate-config

Code Climate Troubleshooting

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:

Run codeclimate in debug mode:

CODECLIMATE_DEBUG=1 codeclimate analyze

Prints additional information about the analysis steps, including any stderr produced by engines.

Increase timeout

To increase the amount of time each engine container may run (default 15 min):

# 30 minutes
CONTAINER_TIMEOUT_SECONDS=1800 codeclimate analyze

Increase memory

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

The analyze script is taking forever to run

This could be due to a variety of factors:

  • It could be hanging up on installing engines. Try running codeclimate engines:install first, before running codeclimate 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.

About

Example plugin, generated using `wp scaffold plugin sample-plugin`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 65.8%
  • PHP 19.3%
  • JavaScript 14.9%