Writing and running unit tests
Unit testing is generally used to test the relatively standalone components of an application, such as API wrappers of different services or classes by implementing your own custom logic.
In this recipe, we will review the structure of a unit test, the most useful methods of PHPUnit, and a way to run a test from the yiic console.
As an example, we will follow the TDD approach to create a class that will generate an HTML markup from a limited amount of BBCode tags. For simplicity, we will support only [b], [i], and [url].
Getting ready
Make sure that you have a ready-to-use application and testing tools as described in the Setting up the testing environment recipe in this chapter.
How to do it...
First, let's define the syntax and some use cases:
In
Out
[b]test[/b]
<strong>test</strong>
[i]test[/i]
<em>test</em>
[url]http://yiiframework.com/[/url]
<a href="http://yiiframework.com/"> http://yiiframework.com/</a>...