如何在PHPUNIT 6.4中声明堆栈中的先前异常?

时间:2017-12-13 12:18:08

标签: phpunit

是否有一种简单的方法可以预期在抛出的异常堆栈中更深层次的异常?

//
//Code:
//
try {
    throw Unauthorized();
} catch(Unauthorized $e) {
    // here I put source exception and wrap it with another one
    throw CommandFailed("message",0,$e);     
}

//
// Test
//

$this->assertException(Unauthorized::class); // this won't work

// the only way I can think of. It works but kind of too wordy.
try { 
    //...code...
} catch(CommandFailed $e) {
    $this->assertEquals(Unauthorized::class, get_class($e->getPrevious()));
}

0 个答案:

没有答案