mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-01 03:26:36 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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);
 | |
|     }
 | |
| }
 | 
