I would like to test, if my application logs the Fatal error
PHP Fatal error: Allowed memory size exhausted
to my monolog handler file. I would like to write an integration test for that. The problem is that when I trigger an error, PHPUnit will stop.
/**
* @return void
*/
public function testMemoryLimitExhaustedLogToMonolog(): void
{
// set memory limit 100mb
ini_set('memory_limit', '100M');
while(true) {
$memoryExhaustingArray[] = 1;
}
$this->assertThatMyLogFileHasCatchedTheOutOfMemoryException();
}
Is there a way to test a fatal out of memory error in PHP7?
I think, there is no way of testing this fatal error, because PHPUnit crashes when it is out of memory. This error triggers script termination and can not be caught: