in@somewherein.net");
$this->assertTrue($result);
}
}
Now you have to write the test suit and run:
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTestSuite("TestEmailValidator");
PHPUnit_TextUI_TestRunner::run($suite);
You will get the following output when you run this test suite:
PHPUnit 3.0.5 by Sebastian Bergmann.
...
Time: 00:00
OK (1 test)
Now try harder; try to break your code. Try all the possible cases that may occur in
an email and try as many as you can. We are going to add more test cases:
class TestEmailValidator extends PHPUnit_Framework_TestCase
{
private $Ev;
protected function setUp()
{
$this->Ev = new EmailValidator();
}
protected function tearDown()
{
Reflection and Unit Testing
[ 118 ]
unset($this->Ev);
}
public function testSimpleEmail()
{
$result = $this->Ev->validateEmail("hasin@somewherein.net");
$this->assertTrue($result);
}
public function testEmailWithDotInName()
{
$result = $this->Ev->validateEmail("has.in@somewherein.net");
$this->assertTrue($result);
}
public function testEmailWithComma()
{
$result = $this->Ev->validateEmail("has,in@somewherein.net");
$this->assertFalse($result);
}
public function testEmailWithSpace()
{
$result = $this->Ev->validateEmail("has in@somewherein.
Pages:
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133