【问题标题】:Is there a way in phpunit that I could possibly assert two values for a key in an array?phpunit 中有没有一种方法可以为数组中的键声明两个值?
【发布时间】:2017-08-18 15:32:42
【问题描述】:
$array = [a => '1',
 b => '2']

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

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

【问题讨论】:

    标签: php unit-testing phpunit


    【解决方案1】:

    如果你想断言$array["a"] ("I want to check if a...") 包含 1 或 3,那么这将起作用:

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

    【讨论】:

      猜你喜欢
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 2017-02-28
      • 2021-06-22
      • 2010-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多