I have a PHPUnit test that loops through an array of invalid values, and asserts that each one is correctly rejected by the function.
For instance, validateInput
should return true only if the input is a string, else return false.
public function testValidateInput()
{
$obj = new MyClass();
$data = [
null,
42,
21.21,
-24,
-12.12,
false,
array('key' => 'value'),
(object) 'value'
];
foreach ($data as $item){
$this->assertSame(false, $obj->validateInput($item));
}
}
When the test fails an assertion, I only get the line number - which is the same for all the values because it's in a loop.
1) MyClassTest::testValidateInput Failed asserting that true is identical to false. /home/jeff/MyClass/tests/MyClassTest.php:24
How can I determine which value failed the assertion?