Sharpen your saw
After a couple of months of only minor maintenance of our php codebases, I have dived deeper into php coding this week. And two things reallly annoyed me (apart from the fact that I was back coding php).
My testing workflow from working with ruby did not work
I could not remember any of the assertions for phpunit
When I work with ruby I have one keybinding to run all tests, and one keybinding to run either the testfile I am in (if I am in one), or the last testfile I have run (if I am in a non-testfile). This combined with the fact that I have tests running in no time, and in a tmux pane instead of removing my editor ui, makes me run tests every few seconds when I am in flow.
I really needed this in php as well.
My original vim setup for ruby editing was copied from Gary Bernhardts dotfiles. They were - at the time I copied them anyway - hardcoded for use in ruby (actually maybe even rails) applications.
I needed something a bit more configurable, without needing to make to many changes every time I work with a new project.
I decided to use an hour to modify my test running setup in vim. And now with very few changes I can run phpunit tests just like I run my rspec tests in ruby.
On top of that, I have modified the run all tests binding, to ensure that I can run tests with npm test, grunt test, karma test - and many more - if the files needed (package.json, Gruntfile.js, karma-conf.js respectively) are in the current project.
This also means that the php code that I have written this week just might be the best tested php I have ever written.
Dash Cheatsheet for PhpUnit
I work with very many different kinds of programming languages, toolkits, libraries and frameworks - I cannot remember half of the apis I use - not even the ones I use the most. I use dash for finding what I need (it beats having to find the right website or even searching through google - oh, and it works when I’m offline as well).
In one of the latest updates to dash, they added the cheatsheet feature - and it is crazy easy to create your own cheatsheets. All you need is a simple ruby file, and the cheatset gem installed.
I copied all the assertion methods from the documentation from phpunit’s website, made sure each method were in a string, and stuffed them in an array.
Then I loop over them, rewrite them a bit for the name, and I end up with this: