Passed
Push — master ( 1fb483...35eebd )
by Roman
04:31
created

LineTest::rowDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 0
dl 0
loc 29
ccs 0
cts 19
cp 0
crap 2
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Tests\Crossword\Features\Constructor\Scaner\Grid;
6
7
use App\Crossword\Features\Constructor\Scanner\Exception\WordNotFitException;
8
use App\Crossword\Features\Constructor\Scanner\Grid\Cell;
9
use App\Crossword\Features\Constructor\Scanner\Grid\Coordinate;
10
use App\Crossword\Features\Constructor\Scanner\Grid\Line;
11
use App\Crossword\Features\Constructor\Scanner\Grid\Row;
12
use Generator;
13
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...
14
15
/**
16
 * @coversDefaultClass \App\Crossword\Features\Constructor\Scanner\Grid\Line
17
 */
18
final class LineTest extends TestCase
19
{
20
    /**
21
     * @covers ::withLetter
22
     */
23
    public function testFillLetter(): void
24
    {
25
        $row = new Row(new Cell(new Coordinate(1, 1), null));
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\C...canner\Grid\null|string expected by parameter $letter of App\Crossword\Features\C...rid\Cell::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $row = new Row(new Cell(new Coordinate(1, 1), /** @scrutinizer ignore-type */ null));
Loading history...
26
        $line = Line::withLetter($row, 'q');
27
        $cells = $line->jsonSerialize();
28
29
        self::assertSame($cells[0]['letter'], 'q');
30
    }
31
32
    /**
33
     * @covers ::withWord
34
     */
35
    public function testThrowException(): void
36
    {
37
        $this->expectException(WordNotFitException::class);
38
39
        $row = new Row(
40
            new Cell(new Coordinate(1, 1), null),
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\C...canner\Grid\null|string expected by parameter $letter of App\Crossword\Features\C...rid\Cell::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
            new Cell(new Coordinate(1, 1), /** @scrutinizer ignore-type */ null),
Loading history...
41
            new Cell(new Coordinate(1, 2), null),
42
            new Cell(new Coordinate(1, 3), null),
43
            new Cell(new Coordinate(1, 4), 'r'),
44
            new Cell(new Coordinate(1, 5), null),
45
            new Cell(new Coordinate(1, 6), null),
46
            new Cell(new Coordinate(1, 7), null),
47
        );
48
49
        Line::withWord($row, 'rest');
50
    }
51
52
    /**
53
     * @covers ::withWord
54
     *
55
     * @dataProvider rowDataProvider
56
     */
57
    public function testFillWord(Row $row): void
58
    {
59
        $line = Line::withWord($row, 'rest');
60
        $cells = $line->jsonSerialize();
61
62
        self::assertSame($cells[0]['letter'], 'r');
63
        self::assertSame($cells[1]['letter'], 'e');
64
        self::assertSame($cells[2]['letter'], 's');
65
        self::assertSame($cells[3]['letter'], 't');
66
    }
67
68
    public function rowDataProvider(): Generator
69
    {
70
        yield '..r.' => [
71
            new Row(
72
                new Cell(new Coordinate(1, 1), null),
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type App\Crossword\Features\C...canner\Grid\null|string expected by parameter $letter of App\Crossword\Features\C...rid\Cell::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
                new Cell(new Coordinate(1, 1), /** @scrutinizer ignore-type */ null),
Loading history...
73
                new Cell(new Coordinate(1, 2), null),
74
                new Cell(new Coordinate(1, 3), 'r'),
75
                new Cell(new Coordinate(1, 4), null),
76
                new Cell(new Coordinate(1, 5), null),
77
                new Cell(new Coordinate(1, 6), null),
78
            )
79
        ];
80
81
        yield '.r..' => [
82
            new Row(
83
                new Cell(new Coordinate(1, 1), null),
84
                new Cell(new Coordinate(1, 2), 'r'),
85
                new Cell(new Coordinate(1, 3), null),
86
                new Cell(new Coordinate(1, 4), null),
87
                new Cell(new Coordinate(1, 5), null),
88
            )
89
        ];
90
91
        yield 'r...' => [
92
            new Row(
93
                new Cell(new Coordinate(1, 1), 'r'),
94
                new Cell(new Coordinate(1, 2), null),
95
                new Cell(new Coordinate(1, 3), null),
96
                new Cell(new Coordinate(1, 4), null),
97
            )
98
        ];
99
    }
100
}
101