Passed
Pull Request — master (#416)
by Sergei
04:39 queued 01:56
created

UrlTest::testGetValidSchemes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Rule;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\Rule\Url;
9
use Yiisoft\Validator\Rule\UrlHandler;
10
use Yiisoft\Validator\Tests\Rule\Base\DifferentRuleInHandlerTestTrait;
11
use Yiisoft\Validator\Tests\Rule\Base\SkipOnErrorTestTrait;
12
use Yiisoft\Validator\Tests\Rule\Base\WhenTestTrait;
13
14
final class UrlTest extends TestCase
15
{
16
    use DifferentRuleInHandlerTestTrait;
17
    use SkipOnErrorTestTrait;
18
    use WhenTestTrait;
19
20
    public function testDefaultValues(): void
21
    {
22
        $rule = new Url();
23
24
        $this->assertSame('url', $rule->getName());
25
        $this->assertSame(['http', 'https'], $rule->getValidSchemes());
26
    }
27
28
    public function testGetValidSchemes(): void
29
    {
30
        $rule = new Url(validSchemes: ['http', 'https', 'ftp', 'ftps']);
31
        $this->assertSame(['http', 'https', 'ftp', 'ftps'], $rule->getValidSchemes());
32
    }
33
34
    public function testSkipOnError(): void
35
    {
36
        $this->testSkipOnErrorInternal(new Url(), new Url(skipOnError: true));
37
    }
38
39
    public function testWhen(): void
40
    {
41
        $when = static fn (mixed $value): bool => $value !== null;
42
        $this->testWhenInternal(new Url(), new Url(when: $when));
43
    }
44
45
    protected function getDifferentRuleInHandlerItems(): array
46
    {
47
        return [Url::class, UrlHandler::class];
48
    }
49
}
50