forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsOneOfAssert.php
51 lines (44 loc) · 1.13 KB
/
IsOneOfAssert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yiiunit;
use yii\helpers\VarDumper;
/**
* IsOneOfAssert asserts that the value is one of the expected values.
*/
class IsOneOfAssert extends \PHPUnit\Framework\Constraint\Constraint
{
private $allowedValues;
/**
* IsOneOfAssert constructor.
* @param array $allowedValues
*/
public function __construct(array $allowedValues)
{
parent::__construct();
$this->allowedValues = $allowedValues;
}
/**
* Returns a string representation of the object.
*
* @return string
*/
public function toString()
{
$allowedValues = array_map(function ($value) {
return VarDumper::dumpAsString($value);
}, $this->allowedValues);
$expectedAsString = implode(', ', $allowedValues);
return "is one of $expectedAsString";
}
/**
* {@inheritdoc}
*/
protected function matches($other)
{
return in_array($other, $this->allowedValues, false);
}
}