From the course: Writing and Refactoring Testable PHP

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Write testable code

Write testable code

- [Lecturer] All code is testable. Some code is much harder to test than other code. If you think about writing your code in a way to make testing easier, you'll start to see some patterns emerge. I'm going to show some examples in this video from a project I recently shipped. Here are three examples of link arrays I had to work with. Structurally, they're simple, an ID and a URL, but quickly you see some problems. The first item has an ID and a full URL. The second has no ID and a relative path. Finally, the third looks like the first but has no ID. There are a million ways data can end up in this state and none of those actually matter. I'm going to pseudo code this thing right quick. So we'll accept the link array in this function and we'll say if link array ID is false, we can return link array URL. Otherwise, I will return get link ID, link array ID. Ignore that that's not a real function. In the project I was working…

Contents