Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I assert two possible values for a key in an array using Phpunit? [duplicate]

Tags:

php

phpunit

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

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)
));
like image 328
iii Avatar asked Jun 29 '26 09:06

iii


1 Answers

Pass your assertions as arguments into logicalOr

$this->assertThat($array, $this->logicalOr(
    $this->assertContains('3',$array),
    $this->assertContains('1',$array)
));
like image 189
FuzzyTree Avatar answered Jun 30 '26 23:06

FuzzyTree



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!