Let's see the following example to understand how unit testing before real code
actually fits in project development.
PHPUnit provides you a lot of useful API for test-first programming such as
markTestSkipped() and markTestIncomplete(). We will use these two methods to
mark some of our tests, which are not implemented. Let us design a small feedback
manager which can accept user's feedback and mail them to you. So what could be
the useful features of a feedback manager? I would suggest the following:
It can render a feedback form.
It will handle user's input and properly filter it.
It will have a spam prevention functionality.
It will prevent any automated feedback submitted by bots or spammers.
It will render a confirmation after submission of feedback, mailing it
to owner.
Let's create some blank unit tests for this. Here comes our test case, before we have
the real code:
class FeedbackTester extends PHPUnit_Framework_TestCase
{
public function testUsersEmail()
{
$this->markTestIncomplete();
}
public function testInvalidDomain()
{
$this->markTestIncomplete();
}
??? ??? ??? ??? ???
Chapter 5
[ 125 ]
public function testCaptchaGenerator()
{
$this->markTestIncomplete();
}
public function testCaptchaChecker()
{
$this->markTestIncomplete();
}
public function testFormRenderer()
{
$this->markTestIncomplete();
}
public function testFormHandler()
{
$this->markTestIncomplete();
}
public function testValidUserName()
{
$this->markTestIncomplete();
}
public function testValidSubject()
{
$this->markTestIncomplete();
}
public function testValidContent()
{
$this->markTestIncomplete();
}
public function testFeedbackSender()
{
$this->markTestIncomplete();
}
public function testConfirmer()
{
$this->markTestIncomplete();
}
}
?>
This is good; we have now created 11 blank tests.
Pages:
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140