在phpunit中是否有一种方法可以为数组中的键断言两个值?

时间:2017-08-18 15:32:42

标签: php unit-testing phpunit

$array = [a => '1',
 b => '2']

例如,我想检查a是1还是3。我认为使用它会起作用。

$this->assertThat(
    $this->assertContains('1',$array),
    $this->logicalOr(
        $this->assertContains('3',$array)
));

1 个答案:

答案 0 :(得分:3)

如果你想断言$array["a"](“我想检查一个......”)是否包含1或3,那么这将有效:

$array = ["a" => "1", "b" => "2"];
$this->assertThat($array["a"],
    $this->logicalOr(
        $this->equalTo("1"),
        $this->equalTo("3")
));