public
anonymous / gist:6426826
Created

Sample PHPUnit test for TDD, PHPUnit doubts

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.