我正在尝试测试我的InvalidArgumentException类,但是我遇到了以下问题:
Tests\BarTest::should_receive_parameter缺失第1个参数,在/mypath/foo/tests/BarTest.php的第10行调用了Itdc\Foo\Bar::__construct()函数,但未定义
这是我使用的测试(BarTest.php)文件:
<?php namespace Tests;
use Itdc\Foo\Bar;
class BarTest extends \PHPUnit_Framework_TestCase {
/** @test */
public function should_receive_parameter() {
$this->setExpectedException('Exception');
$id = new Bar;
}
}
这是Bar类:
<?php namespace Itdc\Foo;
class Bar {
public function __construct($a) {
// do something
}
}
我已经尝试将setExpectedException放在注释部分,也尝试使用InvalidArgumentException,但没有成功。
如果你有任何建议,我将不胜感激。
$this->expectException(\Exception::class); $this->expectExceptionCode('the_expected_code'); $this->expectExceptionMessage('Wrong exception');
参考链接:https://stackoverflow.com/questions/61296581/how-to-use-expectexception-in-phpunit - undefined