💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# @expectedExceptionCode 将 `@expectedExceptionCode` 标注与 `@expectedException` 联合使用,可以对抛出异常的代码作出断言,这样可以缩小具体异常的范围。 ~~~ class MyTest extends PHPUnit_Framework_TestCase { /** * @expectedException MyException * @expectedExceptionCode 20 */ public function testExceptionHasErrorcode20() { throw new MyException('Some Message', 20); } } ~~~ 为了方便测试并减少冗余,可以用"`@expectedExceptionCode ClassName::CONST`"这样的语法将指定类常量作为 `@expectedExceptionCode` ~~~ class MyTest extends PHPUnit_Framework_TestCase { /** * @expectedException MyException * @expectedExceptionCode MyClass::ERRORCODE */ public function testExceptionHasErrorcode20() { throw new MyException('Some Message', 20); } } class MyClass { const ERRORCODE = 20; } ~~~