Symfony2:PHPUnit如何使用' OR'断言中的条件?

时间:2015-06-05 09:58:38

标签: php unit-testing symfony phpunit

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

在我的情况下,客户端请求可以返回代码200302,但assertEquals只能提供一种可能性。有没有办法抛出异常,代码不是200 AND 302

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());        
}

1 个答案:

答案 0 :(得分:3)

使用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));        
}