1 | <?php |
||||
2 | |||||
3 | namespace App\Tests\Game; |
||||
4 | |||||
5 | use PHPUnit\Framework\TestCase; |
||||
6 | use App\Game\PokerSquareGame; |
||||
7 | use App\Card\Card; |
||||
8 | |||||
9 | class PokerSquareGameTest extends TestCase |
||||
10 | { |
||||
11 | public function testInitialState(): void |
||||
12 | { |
||||
13 | $game = new PokerSquareGame(); |
||||
14 | |||||
15 | $this->assertIsArray($game->getGrid()); |
||||
16 | $this->assertInstanceOf(Card::class, $game->getCurrentCard()); |
||||
17 | $this->assertFalse($game->isGameOver()); |
||||
18 | } |
||||
19 | |||||
20 | public function testPlaceCard(): void |
||||
21 | { |
||||
22 | $game = new PokerSquareGame(); |
||||
23 | $pos = '0-0'; |
||||
24 | $currentCard = $game->getCurrentCard(); |
||||
25 | |||||
26 | $game->placeCard($pos); |
||||
27 | $grid = $game->getGrid(); |
||||
28 | |||||
29 | $this->assertArrayHasKey($pos, $grid); |
||||
30 | $this->assertSame($currentCard, $grid[$pos]); |
||||
31 | } |
||||
32 | |||||
33 | public function testGetTotalScoreReturnsInt(): void |
||||
34 | { |
||||
35 | $game = new PokerSquareGame(); |
||||
36 | |||||
37 | for ($i = 0; $i < 5; $i++) { |
||||
38 | $game->placeCard("0-$i"); |
||||
39 | } |
||||
40 | |||||
41 | $totalScore = $game->getTotalScore(); |
||||
42 | |||||
43 | $this->assertIsInt($totalScore); |
||||
44 | $this->assertGreaterThanOrEqual(0, $totalScore); |
||||
45 | } |
||||
46 | |||||
47 | public function testGetSuggestedMoveReturnsValidPosition(): void |
||||
48 | { |
||||
49 | $game = new PokerSquareGame(); |
||||
50 | |||||
51 | $suggested = $game->getSuggestedMove(); |
||||
0 ignored issues
–
show
|
|||||
52 | |||||
53 | $this->assertNotNull($suggested); |
||||
54 | $this->assertMatchesRegularExpression('/^[0-4]-[0-4]$/', $suggested); |
||||
0 ignored issues
–
show
$suggested of type null is incompatible with the type string expected by parameter $string of PHPUnit\Framework\Assert...chesRegularExpression() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
55 | } |
||||
56 | |||||
57 | public function testPlaceCardDoesNotOverwrite(): void |
||||
58 | { |
||||
59 | $game = new PokerSquareGame(); |
||||
60 | $pos = '0-0'; |
||||
61 | $firstCard = $game->getCurrentCard(); |
||||
62 | |||||
63 | $game->placeCard($pos); |
||||
64 | $game->placeCard($pos); |
||||
65 | |||||
66 | $grid = $game->getGrid(); |
||||
67 | $this->assertSame($firstCard, $grid[$pos]); |
||||
68 | } |
||||
69 | |||||
70 | public function testGetGridScoresReturnsExpectedStructure(): void |
||||
71 | { |
||||
72 | $game = new PokerSquareGame(); |
||||
73 | |||||
74 | for ($i = 0; $i < 5; $i++) { |
||||
75 | $game->placeCard("0-$i"); |
||||
76 | } |
||||
77 | |||||
78 | $scores = $game->getGridScores(); |
||||
79 | |||||
80 | $this->assertArrayHasKey('rows', $scores); |
||||
81 | $this->assertArrayHasKey('cols', $scores); |
||||
82 | $this->assertCount(5, $scores['rows']); |
||||
83 | $this->assertCount(5, $scores['cols']); |
||||
84 | } |
||||
85 | |||||
86 | public function testIsGameOverWhenGridFull(): void |
||||
87 | { |
||||
88 | $game = new PokerSquareGame(); |
||||
89 | |||||
90 | for ($row = 0; $row < 5; $row++) { |
||||
91 | for ($col = 0; $col < 5; $col++) { |
||||
92 | $game->placeCard("$row-$col"); |
||||
93 | } |
||||
94 | } |
||||
95 | |||||
96 | $this->assertTrue($game->isGameOver()); |
||||
97 | } |
||||
98 | |||||
99 | public function testGameOverWhenGridFull(): void |
||||
100 | { |
||||
101 | $game = new PokerSquareGame(); |
||||
102 | for ($row = 0; $row < 5; $row++) { |
||||
103 | for ($col = 0; $col < 5; $col++) { |
||||
104 | $pos = "$row-$col"; |
||||
105 | $game->placeCard($pos); |
||||
106 | } |
||||
107 | } |
||||
108 | |||||
109 | $this->assertTrue($game->isGameOver()); |
||||
110 | } |
||||
111 | } |
||||
112 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.