PHPUnit 中的单元测试 - 处理多个条件

Mar*_*ker 4 php phpunit unit-testing logical-operators

我想使用 PHPUnit 编写一个测试,其中包括检查以确保值是 astring NULL

AFAIK,我可以像这样编写这样的测试:

if (is_string($value) || is_null($value)) { 
    $result = TRUE; 
} else { 
    $result = FALSE; 
} 

$this->assertTrue($result);
Run Code Online (Sandbox Code Playgroud)

但是,我看到 PHPUnit 有一个logicalOr()方法,我不知道是否应该使用它来进行更“本机”的测试?如果我应该使用它,我不知道该怎么做......

Att*_*lop 5

使用 phpunit v5.5 它(也)以这种方式工作:

if (is_string($value) || is_null($value)) { 
    $result = TRUE; 
} else { 
    $result = FALSE; 
} 

$this->assertThat($value, $this->logicalOr(
    $this->isType('string'),
    $this->isNull()
));
Run Code Online (Sandbox Code Playgroud)