1 | <?php |
||||||
2 | |||||||
3 | namespace App\Tests\Card; |
||||||
4 | |||||||
5 | use PHPUnit\Framework\TestCase; |
||||||
6 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
||||||
7 | use App\Card\Card; |
||||||
8 | use App\Card\Game; |
||||||
9 | use App\Card\DeckOfCards; |
||||||
10 | use App\Card\CardHand; |
||||||
11 | use App\Card\CardGraphic; |
||||||
12 | use App\Card\Turn; |
||||||
13 | |||||||
14 | /** |
||||||
15 | * Test cases for class Game. |
||||||
16 | */ |
||||||
17 | class GameTest extends TestCase |
||||||
18 | { |
||||||
19 | public function testPlayGame(): void |
||||||
20 | { |
||||||
21 | $session = $this->createMock(SessionInterface::class); |
||||||
22 | $turnSession = $this->createMock(Turn::class); |
||||||
23 | $deck = new DeckOfCards(); |
||||||
24 | $game = new Game(); |
||||||
0 ignored issues
–
show
|
|||||||
25 | $result = $game->playGame($deck, $session, $turnSession, false, false); |
||||||
26 | |||||||
27 | $this->assertTrue($result); |
||||||
28 | } |
||||||
29 | // public function testPlayGame(): void |
||||||
30 | // { |
||||||
31 | // $session = $this->createMock(SessionInterface::class); |
||||||
32 | // $turnSession = $this->createMock(Turn::class); |
||||||
33 | // $deck = new DeckOfCards(); |
||||||
34 | // $game = new Game(); |
||||||
35 | // $result = $game->playGame($deck, $session, $turnSession); |
||||||
36 | |||||||
37 | // $this->assertTrue($result); |
||||||
38 | // } |
||||||
39 | |||||||
40 | // public function testPlayGameWithDrawCard(): void |
||||||
41 | // { |
||||||
42 | // $_POST['drawCard'] = true; |
||||||
43 | // $mockSession = $this->createMock(SessionInterface::class); |
||||||
44 | // $turnSession = $this->createMock(Turn::class); |
||||||
45 | |||||||
46 | // $deck = new DeckOfCards(); |
||||||
47 | // $game = new Game(); |
||||||
48 | // $turnSession->expects($this->once())->method('playerTurn'); |
||||||
49 | |||||||
50 | // $game->playGame($deck, $mockSession, $turnSession); |
||||||
51 | // } |
||||||
52 | |||||||
53 | // public function testPlayGameWithStop(): void |
||||||
54 | // { |
||||||
55 | // $_POST['stop'] = true; |
||||||
56 | // $mockSession = $this->createMock(SessionInterface::class); |
||||||
57 | // $turnSession = $this->createMock(Turn::class); |
||||||
58 | |||||||
59 | // $deck = new DeckOfCards(); |
||||||
60 | // $game = new Game(); |
||||||
61 | // $turnSession->expects($this->once())->method('bankTurn'); |
||||||
62 | |||||||
63 | // $game->playGame($deck, $mockSession, $turnSession); |
||||||
64 | // } |
||||||
65 | |||||||
66 | public function testPlayGameWithDrawCard(): void |
||||||
67 | { |
||||||
68 | $mockSession = $this->createMock(SessionInterface::class); |
||||||
69 | $turnSession = $this->createMock(Turn::class); |
||||||
70 | |||||||
71 | $deck = new DeckOfCards(); |
||||||
72 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
73 | $turnSession->expects($this->once())->method('playerTurn'); |
||||||
74 | |||||||
75 | $game->playGame($deck, $mockSession, $turnSession, true, false); |
||||||
76 | } |
||||||
77 | |||||||
78 | public function testPlayGameWithStop(): void |
||||||
79 | { |
||||||
80 | $mockSession = $this->createMock(SessionInterface::class); |
||||||
81 | $turnSession = $this->createMock(Turn::class); |
||||||
82 | |||||||
83 | $deck = new DeckOfCards(); |
||||||
84 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
85 | $turnSession->expects($this->once())->method('bankTurn'); |
||||||
86 | |||||||
87 | $game->playGame($deck, $mockSession, $turnSession, false, true); |
||||||
88 | } |
||||||
89 | |||||||
90 | public function testWinner(): void |
||||||
91 | { |
||||||
92 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
93 | |||||||
94 | $this->assertEquals("Bank wins", $game->winner(23, 17)); |
||||||
95 | $this->assertEquals("Player wins", $game->winner(15, 25)); |
||||||
96 | $this->assertEquals("Bank wins", $game->winner(18, 18)); |
||||||
97 | $this->assertEquals("Player wins", $game->winner(20, 18)); |
||||||
98 | } |
||||||
99 | |||||||
100 | public function testSessionGame(): void |
||||||
101 | { |
||||||
102 | $sessionMock = $this->createMock(SessionInterface::class); |
||||||
103 | $sessionMock->method('get')->willReturnMap([ |
||||||
104 | ['bankHand', [], []], |
||||||
105 | ['playerHand', [], []], |
||||||
106 | ['playerScore', 0, 17], |
||||||
107 | ['bankScore', 0, 20] |
||||||
108 | ]); |
||||||
109 | |||||||
110 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
111 | $result = $game->sessionGame($sessionMock); |
||||||
0 ignored issues
–
show
The method
sessionGame() does not exist on App\Card\Game .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
112 | |||||||
113 | $this->assertEquals(17, $result['playerScore']); |
||||||
114 | $this->assertEquals(20, $result['bankScore']); |
||||||
115 | } |
||||||
116 | |||||||
117 | public function testReturnGame(): void |
||||||
118 | { |
||||||
119 | $sessionMock = $this->createMock(SessionInterface::class); |
||||||
120 | |||||||
121 | $sessionMock->method('get')->willReturnMap([ |
||||||
122 | ['bankHand', [], []], |
||||||
123 | ['playerHand', [], []], |
||||||
124 | ['playerScore', 0, 19], |
||||||
125 | ['bankScore', 0, 17] |
||||||
126 | ]); |
||||||
127 | |||||||
128 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
129 | $result = $game->returnGame($sessionMock); |
||||||
0 ignored issues
–
show
The method
returnGame() does not exist on App\Card\Game .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
130 | |||||||
131 | $this->assertEquals(19, $result['player']['score']); |
||||||
132 | } |
||||||
133 | |||||||
134 | public function testJsonGame(): void |
||||||
135 | { |
||||||
136 | $cardMock = $this->createMock(CardGraphic::class); |
||||||
137 | $cardMock->method('getValue')->willReturn(13); |
||||||
138 | $cardMock->method('getSuitAsWord')->willReturn('Spades'); |
||||||
139 | |||||||
140 | $sessionMock = $this->createMock(SessionInterface::class); |
||||||
141 | $sessionMock->method('get')->willReturnMap([ |
||||||
142 | ['playerHand', [], [$cardMock]], |
||||||
143 | ['bankHand', [], []], |
||||||
144 | ['playerScore', 0, 10], |
||||||
145 | ['bankScore', 0, 12], |
||||||
146 | ]); |
||||||
147 | |||||||
148 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
149 | $result = $game->jsonGame($sessionMock); |
||||||
0 ignored issues
–
show
The method
jsonGame() does not exist on App\Card\Game .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
150 | |||||||
151 | $expectedPlayerHand = [['value' => 'K', 'suit' => 'Spades']]; |
||||||
152 | $this->assertEquals($expectedPlayerHand, $result['player']['hand']); |
||||||
153 | } |
||||||
154 | |||||||
155 | public function testJsonBankHand(): void |
||||||
156 | { |
||||||
157 | $bankCard = $this->createMock(CardGraphic::class); |
||||||
158 | $bankCard->method('getValue')->willReturn(11); |
||||||
159 | $bankCard->method('getSuitAsWord')->willReturn('Diamonds'); |
||||||
160 | |||||||
161 | $sessionMock = $this->createMock(SessionInterface::class); |
||||||
162 | $sessionMock->method('get')->willReturnMap([ |
||||||
163 | ['playerHand', [], []], |
||||||
164 | ['bankHand', [], [$bankCard]], |
||||||
165 | ['playerScore', 0, 10], |
||||||
166 | ['bankScore', 0, 17], |
||||||
167 | ]); |
||||||
168 | |||||||
169 | $game = new Game(); |
||||||
0 ignored issues
–
show
The call to
App\Card\Game::__construct() has too few arguments starting with session .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
170 | $result = $game->jsonGame($sessionMock); |
||||||
171 | |||||||
172 | $expectedBankHand = [['value' => 'J', 'suit' => 'Diamonds']]; |
||||||
173 | $this->assertEquals($expectedBankHand, $result['bank']['hand']); |
||||||
174 | } |
||||||
175 | |||||||
176 | public function testGameData(): void |
||||||
177 | { |
||||||
178 | $sessionMock = $this->createMock(SessionInterface::class); |
||||||
179 | $gameMock = $this->getMockBuilder(Game::class) |
||||||
180 | ->onlyMethods(['sessionGame', 'winner']) |
||||||
181 | ->getMock(); |
||||||
182 | |||||||
183 | $gameMock->method('sessionGame')->willReturn([ |
||||||
184 | 'playerScore' => 21, |
||||||
185 | 'bankScore' => 8, |
||||||
186 | 'playerHand' => ['PlayerCard'], |
||||||
187 | 'bankHand' => ['BankCard'] |
||||||
188 | ]); |
||||||
189 | |||||||
190 | $gameMock->method('winner')->with(21, 8)->willReturn('Player wins'); |
||||||
191 | $result = $gameMock->gameData($sessionMock); |
||||||
192 | |||||||
193 | $this->assertEquals(21, $result['playerScore']); |
||||||
194 | $this->assertEquals(8, $result['bankScore']); |
||||||
195 | } |
||||||
196 | } |
||||||
197 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.