Skip to content

Instantly share code, notes, and snippets.

Created September 3, 2013 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6426826 to your computer and use it in GitHub Desktop.
Save anonymous/6426826 to your computer and use it in GitHub Desktop.
Sample PHPUnit test for TDD, PHPUnit doubts
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