jeudi 28 janvier 2016

PhpUnit throws catched exception

I have following php code which i want to test.

public function save(Object $test)
{
    try {
       $test->doSomething();
    } catch (\Exception $e) {
        error_log($e);
        return false;
    }
    return true;
}

The method doSomething() eventually throw an exception, thats why its surrounded with a try and catch.

public function testSaveOnError()
{
    $testObject= new Object();
    $mock
        ->expects($this->once())
        ->method('save')
        ->with($testObject)
        ->willThrowException(new \Exception());

    $returnData = $object->save($testObject);
    $this->assertFalse($returnData);
}

The test runs green but the catched exception is thrown and logged in the phpunit console. Is there a way to disable exception tracing in UnitTests or am i doing anything wrong?

Aucun commentaire:

Enregistrer un commentaire