Passed
Push — master ( f4eeb8...0d22ee )
by Sergei
11:47 queued 01:39
created

IsOneOfAssert::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\TestUtility;
6
7
use PHPUnit\Framework\Constraint\Constraint;
8
use Yiisoft\VarDumper\VarDumper;
9
10
use function array_map;
11
use function implode;
12
use function in_array;
13
14
/**
15
 * IsOneOfAssert asserts that the value is one of the expected values.
16
 */
17
final class IsOneOfAssert extends Constraint
18
{
19
    private array $allowedValues;
20
21 8
    public function __construct(array $allowedValues)
22
    {
23 8
        $this->allowedValues = $allowedValues;
24
    }
25
26
    /**
27
     * Returns a string representation of the object.
28
     *
29
     * @return string
30
     */
31
    public function toString(): string
32
    {
33
        $allowedValues = array_map(static function ($value) {
34
            return VarDumper::create($value)->asString();
35
        }, $this->allowedValues);
36
37
        $expectedAsString = implode(', ', $allowedValues);
38
39
        return "is one of $expectedAsString";
40
    }
41
42 8
    protected function matches($other): bool
43
    {
44 8
        return in_array($other, $this->allowedValues, false);
45
    }
46
}
47