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

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

本文介绍了phpunit中是否有一种方法可以断言数组中某个键的两个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

例如,我想检查a是1还是3.我认为使用它可以.

For example, I want to check if a was either 1 or 3. I thought using this would work.

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

推荐答案

如果您要断言$array["a"](我要检查a ...")包含1或3,则可以使用:

If you want to assert that $array["a"] ("I want to check if a...") contains 1 or 3, then this will work:

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

这篇关于phpunit中是否有一种方法可以断言数组中某个键的两个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 11:13