Skip to content

Categories:

SimpleTest: Start testing your code

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.

First let’s write a test!

Continue reading…

Posted in General.

Tagged with , .


5 Tips for Documenting Your Code

Today I want to focus on documenting your code, why it is useful, and when it’s redundant. Last but not least, I’m going to give you 5 tips on how to improve your documenting skills.

Why You Should Document Your Code

You might think “Oh, well, I will remember why I did this, and what it does“. And you may be correct… until you don’t work on the project for a few weeks or months, and then start working on it again. If you haven’t documented your code, and haven’t paid attention to keeping it maintainable, you will probably spent a lot of time trying to find out what you did.

In addition to that, any co-workers, supervisors, or clients might want to know why you made some decisions in your code. Keeping your code documented makes it look more professional, thus more attractive to clients, in-case you are freelancing.

2 Ways To Document Your Code

There are a few ways to document your code. Continue reading…

Posted in Tips.

Tagged with , .