This document describes how to setup your development environment, so that it is ready to develop and test the ConvertKit WordPress Libraries.
Suggestions are provided for the LAMP/LEMP stack and Git client are for those who prefer the UI over a command line and/or are less familiar with WordPress, PHP, MySQL and Git - but you're free to use your preferred software.
Any Apache/nginx, PHP 7.x+ and MySQL 5.8+ stack running WordPress. For example, but not limited to:
- Local by Flywheel (recommended)
- Docker
- MAMP
- WAMP
- VVV
If Composer is not installed on your local environment, enter the following commands at the command line to install it:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
Confirm that installation was successful by entering the composer
command at the command line
Using your preferred Git client or command line, clone this repository into the wp-content/plugins/
folder of your local WordPress installation.
If you prefer to clone the repository elsewhere, and them symlink it to your local WordPress installation, that will work as well.
If you're new to this, use GitHub Desktop or Tower
Create a blank test
database in MySQL, with a MySQL user who can read and write to it.
Copy the .env.example
file to .env.testing
in the root of this repository, changing folder and database credentials as necessary:
TEST_SITE_DB_DSN=mysql:host=localhost;dbname=test
TEST_SITE_DB_HOST=localhost
TEST_SITE_DB_NAME=test
TEST_SITE_DB_USER=root
TEST_SITE_DB_PASSWORD=root
TEST_SITE_TABLE_PREFIX=wp_
TEST_SITE_ADMIN_USERNAME=admin
TEST_SITE_ADMIN_PASSWORD=password
TEST_SITE_WP_ADMIN_PATH=/wp-admin
WP_ROOT_FOLDER="/Users/tim/Local Sites/convertkit-github/app/public"
TEST_DB_NAME=test
TEST_DB_HOST=localhost
TEST_DB_USER=root
TEST_DB_PASSWORD=root
TEST_TABLE_PREFIX=wp_
TEST_SITE_WP_URL=http://convertkit.local
TEST_SITE_WP_DOMAIN=convertkit.local
TEST_SITE_ADMIN_EMAIL=wordpress@convertkit.local
CONVERTKIT_OAUTH_ACCESS_TOKEN=
CONVERTKIT_OAUTH_REFRESH_TOKEN=
CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=
CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=
CONVERTKIT_OAUTH_CLIENT_ID=
CONVERTKIT_OAUTH_REDIRECT_URI=
CONVERTKIT_API_FORM_ID="2765139"
CONVERTKIT_API_SEQUENCE_ID="1030824"
CONVERTKIT_API_TAG_ID="2744672"
CONVERTKIT_API_SUBSCRIBER_EMAIL="optin@n7studios.com"
CONVERTKIT_API_SUBSCRIBER_ID="1579118532"
Create a codeception.yml
file in the root of the repository, with the following contents:
params:
- .env.testing
This tells Codeception to read the above .env.testing
file when testing on the local development enviornment.
Copy the phpstan.neon.example
file to phpstan.neon
in the root of this repository, changing the scanDirectories
to point to your
local WordPress installation:
# PHPStan configuration for local static analysis.
# Include PHPStan for WordPress configuration.
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
# Parameters
parameters:
# Paths to scan
paths:
- src/
# Location of WordPress Plugins for PHPStan to scan, building symbols.
scanDirectories:
- /Users/tim/Local Sites/convertkit-github/app/public/wp-content/plugins
# Should not need to edit anything below here
# Rule Level: https://phpstan.org/user-guide/rule-levels
level: 5
In the Plugin's directory, at the command line, run composer install
.
This will install packages used in the process of development (i.e. testing, coding standards):
- wp-browser
- Codeception
- PHPStan
- PHPUnit
- PHP_CodeSniffer
How to use these is covered later on, and in the Testing Guide
In a Terminal window, build and run the tests to make sure there are no errors and that you have correctly setup your environment:
vendor/bin/codecept build
vendor/bin/codecept run wpunit
Don't worry if you don't understand these commands; if your output looks similar to the above screenshot, and no test is prefixed with E
,
your environment is setup successfully.
In the Plugin's directory, run the following command to run PHP_CodeSniffer, which will check the code meets WordPress' Coding Standards:
vendor/bin/phpcs ./ -v -s
Again, don't worry if you don't understand these commands; if your output looks similar to the above screenshot, with no errors, your environment is setup successfully.
In the Plugin's directory, run the following command to run PHPStan, which will perform static analysis on the code, checking it meets required standards, that PHP DocBlocks are valid, WordPress action/filter DocBlocks are valid etc:
vendor/bin/phpstan --memory-limit=1G
Again, don't worry if you don't understand these commands; if your output looks similar to the above screenshot, with no errors, your environment is setup successfully.
With your development environment setup, you'll probably want to start development, which is covered in the Development Guide