I have about 500 unit tests, which in total have about 2000 assertions. I also have a test for a method, where there is an exception handling, which influences the return value.
I am creating the mock in the following way:
$mockedClass = $this
->getMockBuilder('\My\Class\To\Mock')
->disableOriginalConstructor()
->setMethods(['ThisMethodThrows'])
->getMock();
$mockedClass
->expects($this->any())
->method('ThisMethodThrows')
->will($this->throwException(new \Exception));
And that works. I pass this $mockedClass
to the object whose behaviour I am testing, and inside this method I have logging that logs which method failed and also what the parameters were (using print_r($parameter, true)
).
When I run this test alone, it works, but if I run the whole bundle of (500) tests, when I get to this test, the print_r
fails, because it is no longer able to print the content of the $mockedClass
, because the stacktrace, for some reason, is really long, and if I print_r
the mocked object into console, the list basically goes forever.
Is this a default PHPUnit behaviour? If not, is there a problem with how I defined the mock which is supposed to throw an exception? If the code for mocking the class is correct, can I somehow shorten the output when the exception is thrown?
Aucun commentaire:
Enregistrer un commentaire