I am writing a PHPUnit test suite and have run into a bit of a problem.
Here is the test:
public function testSomething(){
$stub = $this->getMockForAbstractClass('\core\classes\ImportedFile');
$stub->expects($this->exactly(4))
->method('thismethoddoesntexist');
$this->markTestIncomplete('not finished implementing');
}
For some reason this test is not failing. It should because the method does not exist and is therefore not called even once, let alone 4 times. It doesn't matter what I put in there, even if I put in a method name that does exist and say that I'm expecting it to run 100,000 times it still passes when this is obviously wrong.
I find this very strange since I have similar checks in previous tests which work properly.
Has anyone else experienced problems like this?
markTestIncomplete
is designed to prevent your test from failing. It isn't passing but your test suite will say that all the tests passed. phpunit.de/manual/current/en/…$this->assertTrue(false)
and then a call tomarkTestIncomplete
, PHPUnit rightly fails the test. So why doesn't it do that in my example above?markTestIncomplete
from ever being called. In your case, the checks for mocks happen after the test has been completed. SomarkTestIncomplete
is called and the test is marked as Incomplete.