Symfony2 : PHPUnit 如何在断言中使用"OR"条件?



使用Symfony2与PHPUnit,我如何在断言中使用OR条件?

在我的情况下,客户端请求可以返回代码200302,但assertEquals期望只有一种可能性。是否有任何方法抛出异常是代码不是200302 ?

private function check($method, $url, $code)
{
    echo "Expected code [".$code."] => URL ".$url."n";
    $this->client->request($method, $url);
    $this->assertEquals($code, $this->client->getResponse()->getStatusCode());        
}

使用assertContains https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertContains

private function check($method, $url, $code)
{
    echo "Expected code [".$code."] => URL ".$url."n";
    $this->client->request($method, $url);
    $this->assertContains($this->client->getResponse()->getStatusCode(), array(200,302));        
}

最新更新