Completed
Push — master ( fc84c5...f8f0da )
by Razon
02:54
created

UrlValidatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 2
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidateValue() 0 11 2
A dataProviderUrl() 0 7 1
1
<?php
2
namespace App\Tests\Unit\Validator;
3
4
use App\Validator\UrlValidator;
5
use Codeception\Test\Unit;
6
7
class UrlValidatorTest extends Unit
8
{
9
    /**
10
     * @dataProvider dataProviderUrl
11
     */
12
    public function testValidateValue(string $url, bool $valid, array $config = []): void
13
    {
14
        $validator = new UrlValidator($config);
15
        $method = new \ReflectionMethod(UrlValidator::class, 'validateValue');
16
        $method->setAccessible(true);
17
        $result = $method->invoke($validator, $url);
18
        if ($valid) {
19
            $this->assertNull($result);
20
        } else {
21
            $this->assertTrue(is_array($result));
22
            $this->assertCount(2, $result);
23
        }
24
    }
25
26
    public function dataProviderUrl(): array
27
    {
28
        return [
29
            ['http://localhost', true],
30
            ['http://localhost:8080', true],
31
            ['localhost:8080', false],
32
            ['ftp://localhost:8080', false],
33
        ];
34
    }
35
}
36