I want to test that my function refuses all non-positive integers. It throws an InvalidArgumentException. I wrote a test like this:
/**
* @test
* @expectedException InvalidArgumentException
*/
public function testXThrowsException()
{
$this->parser->x(1.5);
$this->parser->x('2');
$this->parser->x(1000E-1);
$this->parser->x(+100);
}
My test always passes because the first one throws an exception. The others don't get tested properly. I can add $this->parser->x(1);
to my code and it would still pass.
What should I do to assert that all these function calls raise the InvalidArgumentException?