Testing With Traits
April 5th, 2018
Traits are an easy way to share code between classes, but how do you test them? I used to test the trait in isolation and not test the traits functionality while testing the classes that used the trait. This lead to passing tests and bugs. I tried copy and pasting code between tests, but this always seemed like a bad solution. Lately, I've been using traits to test traits and have been happy with the results so far.
Ramsey UUID and Unit Tests
March 22nd, 2018
Generating Uuids with Ramsey Uuid is damn easy, \Ramsey\Uuid\Uuid::uuid1(). Generating predictable Uuids for testing while not obvious, is not difficult either. In a few simple steps you can replace the default Uuid Factory with a mock factory that will return your specified Uuids .
You're Writing Your Tests Wrong
March 31st, 2017
While preparing for a talk, I realized that I'd been writing unit tests wrong for the last 3 years. I'd always approached test writing iteratively rather than from the outside in. With this one change, I was able to write cleaner more maintainable tests.
PHPUnit Quick Tip - Type Hint Your Mocks
February 6th, 2017
Type hinting your properties, specifically your mock objects, in your tests can go a long way to create a more seamless and developer friendly test suite. For a long time, I suffered through static code analysis errors where I was supplying mocks to my concrete objects. But with these short steps, I solved those problems.
Data Provider Quick Tips
January 11th, 2017
Data providers are a powerful tool that allows the developer to reuse the same test with different input variables. Here are some easy tips that will take your dataProvider to the next level
Missing Your PHPStorm Autocompletion PHPUnit
August 12th, 2016
Are your phpunit autocompletions no longer showing up in PHPStorm? Here's the reason why and the solution.