Created
September 3, 2013 17:21
-
-
Save anonymous/6426826 to your computer and use it in GitHub Desktop.
Sample PHPUnit test for TDD, PHPUnit doubts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function testMyObject() | |
{ | |
$TestObject = new OBJECT(); | |
$this->assertInstanceOf('OBJECT', $TestObject, 'Test the Object Created is the right class'); | |
$this->assertInstanceOf('PARENT_OBJECT', $TestObject, 'Test the Object Created is extended from the parent right class'); | |
$this->assertTrue(method_exists($TestObject, "ParentMethod"), "The parent method is expected and must exist."); | |
} | |
protected static function InvalidArguementsData() | |
{ | |
return array( | |
array('ABC', 'Text String is Invalid'), | |
array('1', 'Number passed as string is Invalid'), | |
array(NULL, 'NULL is Invalid'), | |
); | |
} | |
/** | |
* @dataProvider InvalidArguementsData | |
* @expectedException InvalidArgumentException | |
*/ | |
public function testInvalidArguements($Parameter, $Description) | |
{ | |
$TestObject = new OBJECT($Parameter); | |
} | |
protected static function ValidArguementsData() | |
{ | |
return array( | |
array(0, 0, 'Zero should return 0'), | |
array(1, 10, 'One should return 10'), | |
array('-1', 20, 'Negative Number returns 20'), | |
); | |
} | |
/** | |
* @dataProvider ValidArguementsData | |
*/ | |
public function testValidArgument($Parameter, $ReturnValue, $Description) | |
{ | |
$TestObject = new OBJECT(Parameter); | |
$this->assertEquals($ReturnValue, $TestObject->GetResult, $Description); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment