From the course: PHP: Testing Legacy Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Refactor your tests

Refactor your tests

From the course: PHP: Testing Legacy Applications

Start my 1-month free trial

Refactor your tests

- [Narrator] Okay, so when I was writing the previous tests that used doubles, when I was looking at the code in the roster model, I discovered I was not writing a test for a specific condition. I want to show you that condition in the code. As you can see in lines 30 to 40, I added a conditional statement that basically says if I get no information from the database, I want to return an empty array, and then later on in the application, I handle what happens when we get that empty array. When you're writing tests, you need to look at every single conditional statement, and every loop, to make sure that you have coverage for all possible behaviors. So while you were busy soaking in all the information that I taught you before, I went and wrote a test to cover this, so let's take a quick look at it. So we're doing the same sort of things that we did for the previous test, where we're creating a bunch of doubles for our select object, our db object, our pdo statement, and then down…

Contents