I am writing a test phpunit for a class by venimus. Hope this can help someone.
class Validate_DateCompareTest extends PHPUnit_Framework_TestCase { public function dataForTest() { return array( array('2011-06-05', '2011-06-01', '2011-06-10', true), //between dates array('2011-06-10', '2011-06-01', '2011-06-10', true), //between dates array('2011-06-01', '2011-06-01', '2011-06-10', true), //between dates array('2011-06-15', '2011-06-01', '2011-06-10', false), //between dates array('2011-05-30', '2011-06-01', '2011-06-10', false), //between dates array('2011-06-01', '2011-06-01', null, true), //exact match array('2011-06-15', '2011-06-01', null, false), //exact match array('2011-05-30', '2011-06-01', null, false), //exact match array('2011-06-02', '2011-06-01', true, true), //not later array('2011-06-01', '2011-06-01', true, false), //not later array('2011-05-30', '2011-06-01', true, false), //not later array('2011-05-30', '2011-06-01', false, true), //not earlier array('2011-06-01', '2011-06-01', false, false), //not earlier array('2011-06-10', '2011-06-01', false, false), //not earlier ); } /** * @dataProvider dataForTest * @param $value * @param $token * @param $compare * @param $expected * @return void */ public function testDateCompare($value, $token, $compare, $expected) { /** @var $validate My_Validate_DateCompare */ $validate = new My_Validate_DateCompare($token, $compare); $this->assertEquals( $expected, $validate->isValid($value), "value: $value -- token: $token -- compare: $compare" ); }
}
this class was really useful for me, thanks again!