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
|
|
|
|