jeudi 14 avril 2016

Testing PHP parse errors with phpunit

I need to test how our error logger works in various scenarios. One such scenario are parse errors. Here's an example:

public function testParseErrorLogsAnError()
{
    $this->assertCount(0, $this->log_handler->getRecords());

    try {
        eval('<?php not good');
        $this->fail('Code above should throw a parse error');
    } catch (\Exception $e) {
        $this->assertInstanceOf(\ParseError::class, $e);
    }

    $this->assertCount(1, $this->log_handler->getRecords());
}

Problem is that phpunit always exists with an exception, and never enters catch block. How to disable or orverride phpunit's exception handler, so we can test our own?

Aucun commentaire:

Enregistrer un commentaire