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

sde*_*ont 2 php phpunit unit-testing symfony

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

在我的情况下,客户端请求可以返回代码200OR 302,但assertEquals期望只有一种可能性。如果代码不是200AND ,有什么方法可以抛出异常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());        
}
Run Code Online (Sandbox Code Playgroud)

Med*_*Med 7

使用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));        
}
Run Code Online (Sandbox Code Playgroud)