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

RequiredTest::testValidateWithDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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