PHP Meetup December 7, 2017 – TDD / BDD with Codeception

John talks at the Inevation Center in Las Vegas.

Topic: TDD / BDD with Codeception

Git Repo

What is TDD/ BDD?

  • Devops methodology for creating quality software
  • automated tests – Software that tests other software
  • make the test first
  • short cycles, single responsibility, loosely coupled
  • Red, green, re-factor!

TDD becomes sensible…

  • When you don’t know what to do
  • When the project becomes complex
  • When there are bugs
  • When you are performing code rescue
  • When multiple people with varying skill levels are invovled
  • When you care about costs and efficiency

Testing vesus Development

  • Vocabulary is wrong

BDD should statements

  • itShouldDoSomethingUseful(){}
  • itShouldHaveSomeKindOfProperty(){}

Codeception toolkit

  • PHPunit
  • Behat
  • Webdriver
  • Selenium
  • PhantomJS
  • WP-Codeception
  • DB interfaces
  • Framework interfaces

Codception architecture

  • YML files
  • PSR-4 namespaces
  • Suites, groups, environments, grid

The Feature

A feature from the biz perspective

What is a feature?
A feature is any aspect of your software that is useful to you. Anything you can express, that is possible, and that you an afford, can be a feature. A bug is a feature that isn’t useful.

Since we’re talking about development, we’re discussing software features that don’t exist yet, that we’d like to build [or existing features we’d like to make better]. Often we can describe these things with should statements:

  • It should email all the clients once a month.
  • It should have a setting page in the admin area.
  • It should have a custom post type called GPS coordinates for each subscriber.
  • It should show a timeline of Civil War battles in the footer area.

The bottom line, at some point you have to have a conception of what you want in your mind. This thing is called a feature, and it’s what you want your developer to build you.

Understanding DNS and localhost [vis-a-vi WP-BDD]

The Domain Name System [DNS] is the system a browser uses to resolve domain names like to IP addresses like 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 and another blog, Both have the same IP address, but different domain names.
When an HTTP or HTTPS request is sent to the server, the request should include the host header which indicates to the server what domain a resonse is expected from. A browser like Chrome or Firefox does this automatically for the user.
Internally, once the request is received by the server, a web server, like Apache, sends each request to a particular directory, based on what subdomain is named in the host header. From there, a file is activated, and in our case, passed to the PHP parser. For WordPress, it is called index.php. On most Ubuntu WordPress setups, the main domain root directory is usually set to:
and subdomains go from there:

These are the directories [for their respective domains], which will contain the WordPress root files, especially the index.php, the wp-config.php files, and the other directories like:

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. Normally, you’ll have a sepearte wp-config.php file for each domain, specifying which database the domain points to.

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 where I have a database that doesn’t reset.

Directions: Setting up virtual hosts on Ubuntu 16.04 LTS.

Types of WordPress automated tests

state browser database SUT
WP Acceptance tests carries from test to test assumed headfull JS browser [ie. Selenium with Chrome] not reset after each test entire WP application executed with each browser call
Stateless acceptance tests tests run in isolation assumed headless JS browser [ie. PhantomJS] reset after each test entire WP application executed with each browser call
WP Unit tests tests run in isolation assume no browser or only cURL reset after each test WP application NOT executed
WP API tests tests run in isolation cURL only reset after each test WP application is executed

Live MasterMind BDD Group

Sign up to learn Behavior Driven Development in WordPress!

Hi! I’m John Dee. I’m the BDFL here at WordPress BDD. We have a MasterMind group to meet and do BDD in WP!

As a member of the MMG, you will have an opportunity to learn BDD in WordPress, and even get some free work done for your own projects. We take turns building classes and tests for each member of the MMG, so bring your development issues and we’ll solve them, the devops way!

We do a live screencast on Google Hangouts anytime I get 5 people who want to do TDD.


  • Setting up CodeCeption for WordPress in the cloud
  • acceptance testing in WordPress
  • unit testing in WordPress
  • Gherkin feature files

Contact John to sign up!

sms. (702)748-5491

Web Scraper

I made a web crawler for Craigslist, that uses Selenium / Codeception to defeat their JS CACHPAs. It’s super useful for a FEW people, there isn’t a commercial application here. I’m using it to get freelance work. Ask me an I’ll give you a password to check it out.

I’m selling access to this software. Try it for free. Tell me how to monetize it somehow.

  • You can use it if you pay me cash. I will only allow 5 people/companies to use it.
  • If you’re a DESIGNER, and want to use it, you may use it if you also get me freelance programming work. In other words any tech person who’s skills don’t overlap mine can use it.
  • You can use it if you can get me freelance work. I am an expert BDD / WordPress / PHP developer
  • You can have the source if you hire me full time. $100k/year, $5000 signing if you want me to move.
  • You can have the source code for $1000

Contact me!

Setup SSL on your website for $50/year

Get a Secure Sockets Layer (SSL) certificate INSTALLED for $50 a year.

CRG will setup, and manage, a Secure Sockets Layer (SSL) certificate on your website for only $50 a year. We use premium Electronic Frontier Foundation (EFF) certificates, just like the one on this website. Does it say “Secure” in green with a padlock next to your domain name, when you open it in a browser like Chrome or Firefox? If not, contact us right away. We can have you green in an hour!