Php 如何扩展ArgumentCountError?

Php 如何扩展ArgumentCountError?,php,exception,codeception,Php,Exception,Codeception,我尝试在值对象中使用我的异常 我的测试: public function testCreateCompanyWithoutAddress() { $this->expectException(CompanyWithoutAddressException::class); CreateCompanyBuilder::instance()->withAddress(new Address())->build(); } My公司无地址异常类别: class Comp

我尝试在值对象中使用我的异常

我的测试:

public function testCreateCompanyWithoutAddress() {
    $this->expectException(CompanyWithoutAddressException::class);
    CreateCompanyBuilder::instance()->withAddress(new Address())->build();
}
My
公司无地址异常
类别:

class CompanyWithoutAddressException extends ArgumentCountError {

    public function __construct()
    {
        parent::__construct('Company must have an address');
    }
}
但当我运行测试时,我得到:

断言类型为“ArgumentCountError”的异常匹配失败 预期的异常。。。至少有4个“在……而不是 公司必须有地址

当我调用地址构造函数时,如何使用我的异常类

public function __construct(string $country, string $city, string $street, string $house, string $building = '0') {
    if (!$country && !$city && !$street && !$house && !$building) {
        throw new CompanyWithoutAddressException();
    }
}

好的,您的扩展异常类型将不会神奇地被抛出,而不是默认类型。如果您想使用它,您必须自己抛出异常。对不起,我在问题中添加了一个代码,在调用构造函数之前将抛出
ArgumentCountError
,因为它是为任何没有正确amo的函数内置的unt参数。我想你可以给
$country
$city
和其他参数一个默认的空值,但不确定你为什么要这么做。你能详细说明一下测试的目标吗?