Understanding WordPress Codeception configuration files

Doing proper Test Driven Development [TDD] in WordPress, is actually easier than cowboy coding the old way. What is quite difficult however, is understanding and setting up all the configuration files. This guide will help.

The Server

In order to run WP-Codeception, you have to have a working installation of WordPress running on a web server you have access to. This can be any type of server, be it an Ubuntu laptop running Apache-Tomcat, a cloud based server, a Windows machine with a Vagrant box, or whatever. You’ll need access to the command line via a shell, and you’ll need admin access and the ability to load software. You should have Git, and Composer installed globally and at least a rudimentary understanding of haow to use them. Most of this guide assumes an Ubuntu 16LTS server with Apache2, as this is what I use, and you can get one for free. If you have a Windows machine, you can install Ubuntu on a memory stick and turn a junk laptop into a high powered server. You can get a cloud based server from Amazon or Google for next to nothing.

Understanding DNS and subdomains

The Domain Name System [DNS] is the system your browser uses to resolve names like generalchicken.net to IP addresses like 34.197.171.101. A server connected to the internet generally has one IP address, usually one main domain, but it can also have many subdomains. For instance, this server hosts the domains generalchicken.net and another blog, messagetothefish.com. Both have the same IP address, but different domain names.
When an HTTP or HTTPS request is sent to this server, the request should have a header called the host which indicates to the server what domain a resonse is expected from.
Internally, the server sends each request to a particular directory, based on what subdomain is named in the host header. On most Ubuntu WordPress setups I have seen, the main domain the server hosts is usually set to:
/var/www/html/
and subdomains go from there
/var/www/html/sub1/
/var/www/html/sub2/

Understanding this is important because if you are setting up a local development version of WordPress, you are going to want to be able to set subdomains up.

The default setup on Ubuntu, is for the domain “localhost” to point to /var/www/html . Therefore, to access your local WordPress site, open a browser like Chrome, and got to http://localhost/ and you should get the WordPress install screen.

Another consideration is that most forms of testing work the best when you don’t have any state. That is, the database is either reset to a starting point, or totally scrubbed after each test. If you’re not used to this, you may accidentally delete anything you have on your site, especially if you’re using it for anything. My personal setup is that I use http://localhost/ for unit testing, and I have another WordPress install, called http://laptop.dev/ where I have a database that doesn’t reset.

Leave a Reply