|
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\Grid\Cell; |
|
8
|
|
|
use App\Crossword\Features\Constructor\Scanner\Grid\Coordinate; |
|
9
|
|
|
use App\Crossword\Features\Constructor\Scanner\Grid\Grid; |
|
10
|
|
|
use App\Crossword\Features\Constructor\Scanner\Grid\Line; |
|
11
|
|
|
use App\Crossword\Features\Constructor\Scanner\Grid\Row; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @coversDefaultClass \App\Crossword\Features\Constructor\Scanner\Grid\Grid |
|
16
|
|
|
*/ |
|
17
|
|
|
final class GridTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @covers ::isEmpty |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testGridIsEmpty(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$grid = new Grid(); |
|
25
|
|
|
|
|
26
|
|
|
self::assertTrue($grid->isEmpty()); |
|
27
|
|
|
|
|
28
|
|
|
$grid->fillLine(new Line(new Row(new Cell(new Coordinate(1, 2), 'a')))); |
|
29
|
|
|
|
|
30
|
|
|
self::assertFalse($grid->isEmpty()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @covers ::fillLine |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testFillLineANewCell(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$grid = new Grid(); |
|
39
|
|
|
|
|
40
|
|
|
$grid->fillLine(new Line(new Row(new Cell(new Coordinate(1, 2), 'a')))); |
|
41
|
|
|
|
|
42
|
|
|
self::assertArrayHasKey('1.2', $grid->getIterator()->getArrayCopy()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @covers ::shiftCell |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testShiftCellToExistCoordinate(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$row = new Row( |
|
51
|
|
|
new Cell(new Coordinate(1, 2), 't'), |
|
52
|
|
|
new Cell(new Coordinate(1, 3), 'e'), |
|
53
|
|
|
new Cell(new Coordinate(1, 4), 's'), |
|
54
|
|
|
new Cell(new Coordinate(1, 5), 't'), |
|
55
|
|
|
); |
|
56
|
|
|
$grid = new Grid(); |
|
57
|
|
|
$grid->fillLine(new Line($row)); |
|
58
|
|
|
|
|
59
|
|
|
$cell = $grid->shiftCell(new Coordinate(1, 4)); |
|
60
|
|
|
|
|
61
|
|
|
self::assertSame($cell->letter(), 's'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @covers ::shiftCell |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testShiftCellToNotExistCoordinate(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$row = new Row( |
|
70
|
|
|
new Cell(new Coordinate(1, 2), 't'), |
|
71
|
|
|
new Cell(new Coordinate(1, 3), 'e'), |
|
72
|
|
|
new Cell(new Coordinate(1, 4), 's'), |
|
73
|
|
|
new Cell(new Coordinate(1, 5), 't'), |
|
74
|
|
|
); |
|
75
|
|
|
$grid = new Grid(); |
|
76
|
|
|
$grid->fillLine(new Line($row)); |
|
77
|
|
|
|
|
78
|
|
|
$cell = $grid->shiftCell(new Coordinate(2, 4)); |
|
79
|
|
|
|
|
80
|
|
|
self::assertTrue($cell->isEmpty()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @covers ::shiftCell |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testShiftCellToNotInFrameCoordinate(): void |
|
87
|
|
|
{ |
|
88
|
|
|
$grid = new Grid(); |
|
89
|
|
|
$grid->fillLine(new Line(new Row(new Cell(new Coordinate(0, 0), 'a')))); |
|
90
|
|
|
|
|
91
|
|
|
$cell = $grid->shiftCell(new Coordinate(0, 0)); |
|
92
|
|
|
|
|
93
|
|
|
self::assertTrue($cell->isEmpty()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @covers ::fillBlackSquare |
|
98
|
|
|
* |
|
99
|
|
|
* @dataProvider blackSquareDataProvider |
|
100
|
|
|
*/ |
|
101
|
|
|
public function testFillBlackSquare(array $blackSquareCoordinates, Row $row): void |
|
102
|
|
|
{ |
|
103
|
|
|
$grid = new Grid(); |
|
104
|
|
|
$grid->fillLine(new Line($row)); |
|
105
|
|
|
|
|
106
|
|
|
$array = $grid->getIterator()->getArrayCopy(); |
|
107
|
|
|
foreach ($blackSquareCoordinates as $coordinate) { |
|
108
|
|
|
self::assertTrue($array[(string) $coordinate]->isBlack()); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function blackSquareDataProvider() |
|
113
|
|
|
{ |
|
114
|
|
|
yield 'Row by X axis' => [ |
|
115
|
|
|
[ |
|
116
|
|
|
new Coordinate(1, 1), |
|
117
|
|
|
new Coordinate(1, 6) |
|
118
|
|
|
], |
|
119
|
|
|
new Row( |
|
120
|
|
|
new Cell(new Coordinate(1, 2), 'm'), |
|
121
|
|
|
new Cell(new Coordinate(1, 3), 'a'), |
|
122
|
|
|
new Cell(new Coordinate(1, 4), 'm'), |
|
123
|
|
|
new Cell(new Coordinate(1, 5), 'a'), |
|
124
|
|
|
) |
|
125
|
|
|
]; |
|
126
|
|
|
|
|
127
|
|
|
yield 'Row by Y axis' => [ |
|
128
|
|
|
[ |
|
129
|
|
|
new Coordinate(1, 2), |
|
130
|
|
|
new Coordinate(6, 2) |
|
131
|
|
|
], |
|
132
|
|
|
new Row( |
|
133
|
|
|
new Cell(new Coordinate(2, 2), 'm'), |
|
134
|
|
|
new Cell(new Coordinate(3, 2), 'a'), |
|
135
|
|
|
new Cell(new Coordinate(4, 2), 'm'), |
|
136
|
|
|
new Cell(new Coordinate(5, 2), 'a'), |
|
137
|
|
|
) |
|
138
|
|
|
]; |
|
139
|
|
|
|
|
140
|
|
|
yield 'Row by Y axis with out the frame top' => [ |
|
141
|
|
|
[ |
|
142
|
|
|
new Coordinate(5, 2), |
|
143
|
|
|
], |
|
144
|
|
|
new Row( |
|
145
|
|
|
new Cell(new Coordinate(1, 2), 'm'), |
|
146
|
|
|
new Cell(new Coordinate(2, 2), 'a'), |
|
147
|
|
|
new Cell(new Coordinate(3, 2), 'm'), |
|
148
|
|
|
new Cell(new Coordinate(4, 2), 'a'), |
|
149
|
|
|
) |
|
150
|
|
|
]; |
|
151
|
|
|
|
|
152
|
|
|
yield 'Row by X axis with out the frame top' => [ |
|
153
|
|
|
[ |
|
154
|
|
|
new Coordinate(2, 5), |
|
155
|
|
|
], |
|
156
|
|
|
new Row( |
|
157
|
|
|
new Cell(new Coordinate(2, 1), 'm'), |
|
158
|
|
|
new Cell(new Coordinate(2, 2), 'a'), |
|
159
|
|
|
new Cell(new Coordinate(2, 3), 'm'), |
|
160
|
|
|
new Cell(new Coordinate(2, 4), 'a'), |
|
161
|
|
|
) |
|
162
|
|
|
]; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths