Chúng ta có thể đã ra lệnh cho các phiên bản theo cách chỉ là về bất kỳ, nhưng chúng tôi chọn theo thứ tự cao nhất cho nguy cơ thấp nhất, do đó buộc quá trình phát triển của chúng tôi để trực tiếp tấn công các vấn đề khó khăn đầu tiên. Phát triển các chức năng tối thiểu | Reflection and Unit Testing unset this- Ev public function testSimpleEmail result this- Ev- validateEmail hasin@ this- assertTrue result public function testEmailWithDotInName result this- Ev- validateEmail this- assertTrue result public function testEmailWithComma result this- Ev- validateEmail has in@ this- assertFalse result public function testEmailWithSpace result this- Ev- validateEmail has in@ this- assertTrue result public function testEmailLengthMoreThan64Char result this- Ev- validateEmail str_repeat h 67 . @ this- assertFalse result public function testEmailWithInValidCharacters result this- Ev- validateEmail has in@ this- assertFalse result public function testEmailWithNoDomain result this- Ev- validateEmail hasin@ this- assertFalse result public function testEmailWithInvalidDomain result this- Ev- validateEmail hasin@ this- assertFalse result 118 Chapter 5 When you run the test suite you will get the following result PHPUnit by Sebastian Bergmann. .. Time 00 00 There were 1 failures 1 testEmailWithDotInName TestEmailValidator Failed asserting that boolean false is identical to boolean true . C OOP with PHP5 Codes ch5 UnitTest 40 C OOP with PHP5 Codes ch5 UnitTest 83 C Program Files Zend bin php5 1 FAILURES Tests 8 Failures 1. So our email validator fails If you look at the result you will see that it fails with testEmailWithDotInName. Therefore we have to change the regular expression pattern we used and allow . in the name. Let s redesign the validator as show here class EmailValidator public function validateEmail email pattern A-z0-9 . 1 64 @ A-z0-9 . A-z0-9 2 3 preg_match pattern email matches return strlen matches 0 strlen email true false Now if you run your test suites again you will see the following output PHPUnit by Sebastian Bergmann. .