I am just starting with PHPUnit and TDD.
In particular, I cannot answer this question: is this a good test? Am I really testing my code or something already tested (i.e. the Framework or PHP itself)?
A small example: this is a tag:
class DateMax extends Constraint { public $limit; private $invalidLimit = 'Option "limit" should be a valid date/time string.'; public function __construct($options = null) { parent::__construct($options); if(false === strtotime($this->limit)) { throw new InvalidOptionsException($this->invalidLimit, ['limit']); } } }
I want to check that an InvalidOptionsException is expected when invalid "limit" options are passed, otherwise $constraint->limit contains the correct value:
public function testInvalidLimits($testLimit) { new DateMax($testLimit); } public function testValidLimits($testLimit) { $constraint = new DateMax($testLimit); $this->assertEquals($testLimit, $constraint->limit); } public function getInvalidLimits() { return array(array('invalid specification'), array('tomorr')); } public function getValidLimits() { return array(array('now'), array('+1 day'),array('last Monday')); }
So the question is , does this make sense or am I testing the frame / PHP myself?
gremo source share