Introducing skid: stupid-simple unit testing for PHP

I have a confession to make: I’m tired of PHPUnit. It’s overly complex for what I want to do: assert that a piece of code either passes (returns true) or fails (returns false). $this->assertTrue(/*...*/); is pretty much the only assertion I ever use these days, because it’s a lot easier for me to write $this->assertTrue(array_key_exists($key, $array)); than to try to remember, “Okay, $this->assertKeyExists… no, that’s not it. Um, $this->assertArrayHasKey, got it.” And don’t even get me started on exception testing. How is this…

more expressive or less confusing than this?

So, I wrote my own. I call it skid (find it on github). It’s very simple and rough, but it does what it needs to: pass the script a file and it will run the test methods and tell you if the assertions passed or failed. Some things skid doesn’t do:

  • Class mocks. Just create a simple concrete class that extends the abstract class or interface that you want to test, with as much or little logic as you want in the implemented methods. Voila, you have yourself a mock.
  • Unnecessarily verbose assertion methods. In fact, there’s just one: ASSERT(). The script does a little voodoo so that it can display exactly what code was in the assert, because knowing that a bit of code returned false without an easy way to tell what the code was┬áisn’t very useful.

I wouldn’t really recommend putting skid to any kind of production use (like I said, very simple and rough); I consider it a proof of concept for a better world of unit testing, where unit tests actually HELP you with testing, instead of just adding MORE work to your already overloaded task list.

Maybe the way I look at unit testing is not for everyone. If you have something to add (or maybe if you just think I’m an idiot), use the comment box below!

Leave a Reply