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

MatchRegularExpressionTest::testValidate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
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\MatchRegularExpression;
7
8
/**
9
 * @group validators
10
 */
11
class MatchRegularExpressionTest extends TestCase
12
{
13
    public function testValidate(): void
14
    {
15
        $rule = new MatchRegularExpression('/^[a-zA-Z0-9](\.)?([^\/]*)$/m');
16
        $this->assertTrue($rule->validate('b.4')->isValid());
17
        $this->assertFalse($rule->validate('b./')->isValid());
18
        $this->assertFalse($rule->validate(['a', 'b'])->isValid());
19
20
        $rule = (new MatchRegularExpression('/^[a-zA-Z0-9](\.)?([^\/]*)$/m'))->not();
21
        $this->assertFalse($rule->validate('b.4')->isValid());
22
        $this->assertTrue($rule->validate('b./')->isValid());
23
        $this->assertFalse($rule->validate(['a', 'b'])->isValid());
24
    }
25
}
26