Passed
Push — master ( e73618...52f31e )
by Alexander
17:03 queued 10:18
created

RequiredTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testValidateWithDefaults() 0 7 1
1
<?php
2
3
namespace Yiisoft\Validator\Tests\Rule;
4
5
use PHPUnit\Framework\TestCase;
6
use Yiisoft\Validator\Rule\Required;
7
8
/**
9
 * @group validators
10
 */
11
class RequiredTest extends TestCase
12
{
13
    public function testValidateWithDefaults()
14
    {
15
        $val = new Required();
16
        $this->assertFalse($val->validate(null)->isValid());
17
        $this->assertFalse($val->validate([])->isValid());
18
        $this->assertTrue($val->validate('not empty')->isValid());
19
        $this->assertTrue($val->validate(['with', 'elements'])->isValid());
20
    }
21
22
//    public function testValidateAttribute()
23
//    {
24
//        // empty req-value
25
//        $val = new Required();
26
//        $m = FakedValidationModel::createWithAttributes(['attr_val' => null]);
27
//        $val->validateAttribute($m, 'attr_val');
28
//        $this->assertTrue($m->hasErrors('attr_val'));
29
//        $this->assertNotFalse(stripos(current($m->getErrors('attr_val')), 'blank'));
30
//        $val = new Required(['requiredValue' => 55]);
31
//        $m = FakedValidationModel::createWithAttributes(['attr_val' => 56]);
32
//        $val->validateAttribute($m, 'attr_val');
33
//        $this->assertTrue($m->hasErrors('attr_val'));
34
//        $this->assertNotFalse(stripos(current($m->getErrors('attr_val')), 'must be'));
35
//        $val = new Required(['requiredValue' => 55]);
36
//        $m = FakedValidationModel::createWithAttributes(['attr_val' => 55]);
37
//        $val->validateAttribute($m, 'attr_val');
38
//        $this->assertFalse($m->hasErrors('attr_val'));
39
//    }
40
}
41