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
PHPUnit
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.
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
Testing methods that redirect with PHPUnit
Having mastered the ability to cause time to stand still, the next challenge I faced while writing what are probably technically not unit tests, was a lack of direction, or rather too much direction. Consider something like this: So far so good, if the user has the correct capabilities they can view the page. If … Continue reading Testing methods that redirect with PHPUnit
Overriding time() when unit testing with PHPUnit
Over the last year or so, I've discovered the wonderful world of Unit Testing. In a slightly verbose nutshell, Unit Testing involves: Trying to get PHPUnit installed (considerably easier for me on VVV than XAMPP btw) Finally getting it to work, but not quite being sure how. Reading some tutorials that get you up to … Continue reading Overriding time() when unit testing with PHPUnit