Prev | Current Page 118 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

wordcount.php
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once "PHPUnit/Framework/TestSuite.php";
require_once "class.testwordcount.php";
$suite = new PHPUnit_Framework_TestSuite();
$suite->addTestSuite("TestWordCount");
PHPUnit_TextUI_TestRunner::run($suite);
?>
Now if you run the code in testsuite.wordcount.php you will get the
following output:
PHPUnit 3.0.5 by Sebastian Bergmann.
Time: 00:00
OK (1 test)
That means our test has passed and our word-counter function works perfectly,
however, we will write some more test cases for that function.
Chapter 5
[ 115 ]
Let us add this new test case in our class.testwordcount.php:
public function testCountWordsWithSpaces()
{
$wc= new WordCount();
$testSentence = "my name is Anonymous ";
$wordCount = $Wc->countWords($testSentence);
$this->assertEquals(4,$wordCount);
}
Now if we run our test suite we will get the following result:
PHPUnit 3.0.5 by Sebastian Bergmann.
.F
Time: 00:00
There was 1 failure:
1) testCountWordsWithSpaces(TestWordCount)
Failed asserting that is equal to .
C:\OOP with PHP5\Codes\ch5\UnitTest\FirstTest.php:34
C:\OOP with PHP5\Codes\ch5\UnitTest\FirstTest.


Pages:
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130