将Symfony2与PHPUnit一起使用,如何在断言中使用OR条件?
在我的情况下,客户端请求可以返回代码200
或302
,但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());
}
答案 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));
}