General Chicken answers a question from Quora.
Behavior Driven Development in WordPress
General Chicken answers a question from Quora.
General Chicken answers a question from Quora.
General Chicken answers a question from Quora.
General Chicken answers a question from Quora.
General Chicken answers a question from Quora.
BDD is the best way to communicate business requirements from stakeholders to developers. General Chicken explains what BDD is from a business POV.
A feature from the biz perspective
What is a feature?
A feature is an aspect of software that is useful. Anything you can express, that is possible, and that you can afford, can be a feature. A bug is an aspect of software that isn’t useful.
Since we’re talking about development, we’re discussing software features that don’t exist yet. These are features that we would like to build, or existing features that we would like to make better. Describe a feature with should statements:
The next statement you should create is the reason for the feature you are requesting. What is the business value of this feature? Describe the reason by using a “Because”, or “So that” or “In or that”
Alternatively, you can use Gherkin syntax for feature development.
To do Behavior Driven Development [BDD] in WordPress, you need to get the tools! Here is the stack you should use:
Ubuntu. I personally use an Ubuntu 20 development server on my MacBook Pro laptop. You can run Ubuntu on most machines with a USB memory stick, and it’s free. I use Ubuntu on the Amzaon AWS remote cloud servers and production servers. Ubuntu is a brand, but it’s just a Debian based Linux distro, so it’s future proof. If you stopped liking Ubuntu, you could switch to another distro without hassle.
You can also use Mac or Windows.
Many teams who do testing use virtualization like kubernetes or Docker. I don’t quite undertstand the rationale for this in 2020. An entire serve is virtually free, so why btoher with a server within a server? I prefer to use full blown, cloud based WordPress sites. Just use a dummy domain name.
Once you have a machine with Ubuntu running, you can load the entire development stack by running a single command:
source <(curl -s https://raw.githubusercontent.com/johndeebdd/Remote-BDD-Setup/master/installScripts/wordpress.sh)
Directions
Codeception with WordPress modules - PHPunit is the standard and default library for doing unit testing in PHP. CodeCeption INCLUDES PHPunit, as well as a whole series of libraries for doing BDD.
You should use the WPWebDriver and WPDb modules. You can use Selenium to drive a full browser. You can write your test in the Gherkin format, or in procedural PHP. Generally, I consider Gherkin cumbersome and not worth the candle.
Sample acceptance.yml
You should use the WPloader and WPQueries modules.
Sample unit.yml
Use a Git repo. Use Github for code that has a public face. Use Bitbucket for private repos [or pay Github for a private repo, either way].
First setup a few emails: freelancer1@yourdomain.com
, freelancer2@yourdomain.com
etc. These accounts are granted direct commit access to the repo. Give the outsourcer access to the email account. The repo itself can set a webhook to pull to the production server upon commit. When you want to freeze the outsourcer from the project, you just change the password on Github and email accounts. The project manager retains access to pull to production. The outsourcer can make a commit and it appears directly on the development server. When the commit is approved by the project manager, he does a manual pull to the production machine.
Some programmers will have their own IDE setups that they like and know how to use. Eclipse is the best free IDE, while PHPStorm is probably the best commercial IDE. If they know how to pull down from Github and run the code on a local host, great. If they don't know how to do that, setup a development server in the cloud for them. Our stack include the Codiad IDE, which is an open source IDE similar to PHPStorm. TO access it, just go to /codiad/ on your development server, it's all setup already.
cd /var/www/html/wp-content/plugins/{project dir}
bin/codecept run -vvv --html
They appear in the terminal, or at http://yourdomain.com/wp-content/plugins/{project dir}/tests/_output/
Usually in the terminal you can use the up arrow shortcut.
git add --all
git commit -m "some kind of message!"
git push origin master
You can log in by using the FastRegister plugin. Just enter an email in the sidebar form and viola! You're logged in as an admin.
The stack will preconfigured a user called "freelancer" with a password "password". Just SSH into the system without a pem file.
I created a template to mock a second function within a class that is being tested:
Stack Overflow: Mock method from the same class that tested method is using
acceptance tests
unit tests