In today’s tutorial, we will focus on testing your code using SimpleTest. Before we start, let me explain how this tutorial ‘works’. I will explain the functions / methods etc. of SimpleTest by testing a sample class, which will be developed throughout the tutorial. Every time the class is updated, there will be a link to a text file containing the current version of the class. Let’s start!
The Requirements for the class
In the list below, I will tell you what the class will be doing. I will write a test, which obviously will fail since there is no code within the tested class method. Then we’ll write code until the test completes successfully. This type of coding is commonly referred to as TDD: “Test Driven Development”. For more on TDD, please see this link.
- The class will be used to handle a sale in a shop (where all products costs the same).
- The code should allow the use of a getter and setter for the items.
- In-case a method called ‘addItem‘ is used, it should add an item, instead of set the array to a new value (like setItems does)
- When using count($order_object), the code should return the price for this order.