Phpunit phpspec-在使用过程中使用thows,但如果不使用?

Phpunit phpspec-在使用过程中使用thows,但如果不使用?,phpunit,phpspec,Phpunit,Phpspec,在phpspec中,我可以测试如下内容: function it_must_be_constructed_with_my_variable() { $this->shouldThrow(new \Exception('bla'))->during('__construct', array('variable' => 'value')); } 但是,如果我想确保在没有向函数传递某些内容时引发异常,该怎么办 例如,我想说,如果传递的数组不等于某个值,将引发异常。我相信您可

在phpspec中,我可以测试如下内容:

function it_must_be_constructed_with_my_variable()
{
    $this->shouldThrow(new \Exception('bla'))->during('__construct', array('variable' => 'value'));
}
但是,如果我想确保在没有向函数传递某些内容时引发异常,该怎么办


例如,我想说,如果传递的数组不等于某个值,将引发异常。

我相信您可以简单地执行以下操作:

function it_should_throw_exception_if_constructed_with_wrong_variable()
{
    $myWrongVariable = array('something' => 'wrong');
    $this->shouldThrow(new \Exception('bla'))->during('__construct', array($myWrongVariable));
}

如果我没弄错的话,您希望测试当用户传递一个实现不知道或无法处理的数组时,是否会抛出Exception


然后您可以举个例子,将“错误”数组作为参数传递

构造函数是规范测试的有效目标吗?但尽管如此,您的问题还是可以重新表述:如果参数未通过,如何测试是否发生了某些事情?我的第一个猜测是要么传递一个空参数数组,要么完全忽略它。