简体   繁体   中英

Symfony2 : PHPUnit How to use 'OR' condition in an assertion?

Using Symfony2 with PHPUnit, how can I use a OR condition in an assertion?

In my case a client request can return codes 200 OR 302 , but the assertEquals expect only one possibility. Is there any way to throw an exception is the code is not 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());        
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM