| Total Complexity | 6 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 17 | class PHPUnit extends \Codeception\Test\Unit |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * 断言 True |
||
| 21 | * |
||
| 22 | * @param yii\base\Model $model 模型对象 |
||
| 23 | * @param mixed $attributes |
||
| 24 | * |
||
| 25 | * @return void |
||
| 26 | */ |
||
| 27 | public static function true($model, $attributes = null) |
||
| 28 | { |
||
| 29 | parent::assertTrue($model->validate($attributes), implode($model->getFirstErrors())); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * 断言 False |
||
| 34 | * |
||
| 35 | * @param yii\base\Model $model 模型对象 |
||
| 36 | * @param mixed $attributes |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public static function false($model, $attributes = null) |
||
| 41 | { |
||
| 42 | parent::assertFalse($model->validate($attributes), implode($model->getFirstErrors())); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * 断言属性 |
||
| 47 | * |
||
| 48 | * @param yii\base\Model $model 模型对象 |
||
| 49 | * @param [type] $attribute 属性 |
||
| 50 | * @param [type] $array 格式:[错误的属性值,正确的属性值],正确的属性可以不要 |
||
| 51 | * |
||
| 52 | * @return void |
||
| 53 | */ |
||
| 54 | public static function checkAttribute($model, $attribute, $array) |
||
| 55 | { |
||
| 56 | if (2 >= count($array) && isset($array[0])) { |
||
| 57 | $model->$attribute = $array[0]; |
||
| 58 | static::false($model, $attribute); |
||
| 59 | if (isset($array[1])) { |
||
| 60 | $model->$attribute = $array[1]; |
||
| 61 | } |
||
| 62 | } else { |
||
| 63 | throw new \Exception('数组 0 位元素表示错误的属性值,1 位元素表示正确的属性值'); |
||
| 64 | } |
||
| 67 |