A simple visual API testing protocol

Introduction

This script has no goal to replace PEAR::PHPUnit or any existing PEAR unit test process. Main goal is to help developers to test their api (all or partial list) in a very simple way (visual), and in very quick steps.

Why this script, when PEAR::PHPUnit exists ? Creates a full unit tests is long and difficult for most of the developers, and you've to know PHPUnit package. Here with my script, you don't need to know any other package, just your own is enough. Time to write test protocol can be count in minutes rather than hours. Of course it does not replace a full PHPUnit regression tests series.

Have a look on two examples below, to see how easy it is to implement, and found some errors.

Example 1 : PEAR::Auth_PrefManager2

In date of this article (2004-12-08), the PEAR::Auth_PrefManager2 package is still in alpha stage (version 2.0.1dev1).

When i've choosen to have a look on it, to see if it could help me in my new projects, i've discovered quickly a bug with the Array Container (bug#2885).
Easy to find, but it could be avoid by package-leader (no offense, it's not the purpose of this article). Let's have a look to see how we can test this package API. For the demonstration, i've only coded the factory method (see Source Code [3]).

First you've to change the main file (see Source Code [1]):

  1. Identify the class name of your package at line 24
  2. Depending of your class copy location, fixes line 26
  3. If you want to see only methods tested, un-comment line 34
  4. Tests to do are defined in a getTestCase() method into file declared at line 28

Second you've to adds your test cases in a file such as Source Code [2]:

The factory method is defined at line 20, and will be static call (default is not static), line 21. The first parameter of factory method is defined on line 22, (used the Array Container).

That's all to do; easy isn't it ? Now, have a look on browser output when you'll run the simple_api_tests.php (see source Code [1]) and tell me what is the error in this package. If you don't have the solution : read details on bug#2885.

Example 2 : PEAR::Net_UserAgent_Detect

In date of this article (2004-12-08), the PEAR::Net_UserAgent_Detect package is in stable stage (version 2.0.1).

This second example is very similar to previous (see Source Code [4]) for api implementation. I let you discover the notice error in getQuirk() method, and my solution to fix it: bug#2919.

Test Render

If you want to see all API (tested or not), let the line 34 of source code [1] inactive, otherwise if you want only the API declared into the getTestCase() function, un-comment the line 34.

That conclude this brief presentation, of a simple script (not a package proposal) that may help many of us to find all basic errors in quick steps.
Hope it could help you !!!

Source Codes

  1. Visual API Test (main file)
  2. Common basic API template file
  3. PEAR::Auth_PrefManager2 2.0.0dev1 tests protocol
  4. PEAR::Net_UserAgent_Detect 2.0.1 tests protocol
  5. Download all sources: simple_visual_api_tests-0.1.0.tgz