Improving your Code with PHPUnit and Test Driven Development: Part 2

Recap: In an effort to change the coding world for the better, make new friends and drink so much amazing free Truth coffee that I could see through time, I presented a workshop on Improving Code with PHPUnit and TDD at WordCamp Cape Town 2018. As the caffeine hasn't yet left my system, and because … Continue reading Improving your Code with PHPUnit and Test Driven Development: Part 2

Advertisements

Improving your Code with PHPUnit and Test Driven Development: Part 1

Last week I had the pleasure of attending WordCamp Cape Town 2018 and hosting a workshop on PHPUnit and Test Driven Development. I find reviewing slides from talks to be too abstract to be of much help (unless you're reviewing slides in a panic a week before you are due to present and need to … Continue reading Improving your Code with PHPUnit and Test Driven Development: Part 1

Writing Tests for a Class that Uses the ArrayAccess Interface

I am currently involved in a project that utilises the WordPress REST API. As a follower of the principles of Test Driven Development (TDD) the project comes complete with extensive unit and integration tests that were all written prior to even conceptualising any code. Some times. As an aside, I'd place my current level of … Continue reading Writing Tests for a Class that Uses the ArrayAccess Interface

Rock Out With Your Mock Out: Using the PHPUnit at() Method

Having established how to create mock methods with stubs that run multiple times, I was pretty certain that I had finally slain the unit testing dragon, was king of the PHPUnit castle and a lifetime of finely tested code and buxom wenches awaited me (because buxom wenches go weak at the knees for well tested … Continue reading Rock Out With Your Mock Out: Using the PHPUnit at() Method

PHPUnit stubs methods that run more than once.

Another day, another PHPUnit revelation. Yesterday some code started returning an internal server error. In true developer fashion, I ran the same process several times and was absolutely staggered to find that the same thing happened every time. No amount of hard refreshing or cache clearing would help. I considered phoning the server hosting company … Continue reading PHPUnit stubs methods that run more than once.

Parsing $_POST variables and arrays with filter_input_array, filter input and FILTER_CALLBACK

Another day, another PHP Codesniffer induced solution to some code that worked fine before, but I just couldn't leave it alone once Codesniffer scolded me. This time it was: Detected access of super global var $_POST, probably needs manual inspection No problem. I've used filter_input before, lets do this. First problem, I'm dealing with an … Continue reading Parsing $_POST variables and arrays with filter_input_array, filter input and FILTER_CALLBACK

Testing values filtered with filter_input with PHPUnit

In an attempt to shape myself into a poster boy for "Best Practice WordPress Development", I've faithfully installed, Vagrant, I write unit tests and I run Codesniffer on all the new code I write (and am painstakingly refactoring old code at the same time). On a recent job, a quick run of Codesniffer produced (among … Continue reading Testing values filtered with filter_input with PHPUnit