/** * ########## The method name is important! ########## * * A method indicates a single unit test. The method name *must* begin with * the "test". PHPUnit will ignore any method that does not begin * with test. */ public function testEvenCalculation() { // call a method on the object we are testing $util = new NumberUtil(); $isEven = $util->IsEven(2); // within our test, we must make at least one "assertion" // PHPUnit compares the expected value with an actual value. // This is how you tell PHPUnit whether or not the code behaved // as expected. // use a method from TestCase to check (assert) that the value is true $this->assertTrue($isEven); // there are tons of assertion methods, many things can be // tested more than one way, for example: $this->assertEquals(true, $isEven); // all assert methods have an optional parameter for a helpful message // that is printed if a test fails. This is a good place for info // that may not be obvious by looking at the code $this->assertTrue($isEven, 'Assert that isEven is true'); }
public function testMod() { $util = new NumberUtil(); $this->assertTrue($util->IsEven(2), 'Test that 2 is even'); $this->assertFalse($util->IsEven(3), 'Test that 3 is not even'); }