Test Failed
Push — master ( 85ca69...144c12 )
by Roman
15:41
created

MaskTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
c 1
b 0
f 0
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExtractQueryAndLimit() 0 6 1
A maskDataProvider() 0 8 1
A testShiftLeft() 0 13 1
A testThrowExceptionWhenMaskLimitIsShort() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Dictionary\Domain\Model;
6
7
use App\Dictionary\Domain\Exception\SearchMaskIsShortException;
8
use App\Dictionary\Domain\Model\Mask;
9
use Generator;
10
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * @coversDefaultClass \App\Dictionary\Domain\Model\Mask
14
 */
15
final class MaskTest extends TestCase
16
{
17
    /**
18
     * @covers ::shiftLeft
19
     */
20
    public function testShiftLeft(): void
21
    {
22
        $mask = new Mask('a.*{0,10}');
23
24
        $newMask = $mask->shiftLeft();
25
26
        self::assertInstanceOf(Mask::class, $newMask);
27
28
        self::assertSame($newMask->query(), 'a.*');
29
        self::assertSame($newMask->limit(), '{0,9}');
30
31
        self::assertSame($mask->query(), 'a.*');
32
        self::assertSame($mask->limit(), '{0,10}');
33
    }
34
35
    /**
36
     * @covers ::query
37
     * @covers ::limit
38
     */
39
    public function testThrowExceptionWhenMaskLimitIsShort(): void
40
    {
41
        $this->expectException(SearchMaskIsShortException::class);
42
43
        new Mask('a.*{3,5}');
44
    }
45
46
    /**
47
     * @covers ::query
48
     * @covers ::limit
49
     *
50
     * @dataProvider maskDataProvider
51
     */
52
    public function testExtractQueryAndLimit(string $template, string $query, string $limit): void
53
    {
54
        $mask = new Mask($template);
55
56
        self::assertSame($mask->query(), $query);
57
        self::assertSame($mask->limit(), $limit);
58
    }
59
60
    public function maskDataProvider(): Generator
61
    {
62
        yield 'all symbols' => ['.*', '.*', '{0,100}'];
63
        yield 'with first letter' => ['a.*', 'a.*', '{0,100}'];
64
        yield 'with random letter' => ['t.a.', 't.a.', '{0,100}'];
65
        yield 'all symbols with limit' => ['.*{0,10}', '.*', '{0,10}'];
66
        yield 'with first letter with limit' => ['a.*{4,5}', 'a.*', '{4,5}'];
67
        yield 'with random letter with limit' => ['t.a.{10,20}', 't.a.', '{10,20}'];
68
    }
69
}
70