1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Card; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use App\Card\DeckOfCards; |
7
|
|
|
use App\Card\CardGraphic; |
8
|
|
|
use App\Card\Card; |
9
|
|
|
use App\Card\CardFactory; |
10
|
|
|
use App\Game\Player; |
11
|
|
|
|
12
|
|
|
class DeckOfCardsTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testDeckCreation(): void |
15
|
|
|
{ |
16
|
|
|
$factory = new CardFactory(); |
17
|
|
|
$deck = new DeckOfCards($factory); |
18
|
|
|
$this->assertCount(52, $deck->getCards()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testDeckCreationWithGraphics(): void |
22
|
|
|
{ |
23
|
|
|
$factory = new CardFactory(); |
24
|
|
|
$deck = new DeckOfCards($factory, true); |
|
|
|
|
25
|
|
|
$this->assertCount(52, $deck->getCards()); |
26
|
|
|
$this->assertInstanceOf(CardGraphic::class, $deck->getCards()[0]); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testShuffle(): void |
30
|
|
|
{ |
31
|
|
|
$factory = new CardFactory(); |
32
|
|
|
$deck = new DeckOfCards($factory); |
33
|
|
|
$cardsBeforeShuffle = $deck->getCards(); |
34
|
|
|
$deck->shuffle(); |
35
|
|
|
$cardsAfterShuffle = $deck->getCards(); |
36
|
|
|
|
37
|
|
|
$this->assertNotEquals($cardsBeforeShuffle, $cardsAfterShuffle); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testDrawCardFromDeck(): void |
41
|
|
|
{ |
42
|
|
|
$player = new Player(); |
43
|
|
|
$factory = new CardFactory(); |
44
|
|
|
$deck = new DeckOfCards($factory); |
45
|
|
|
|
46
|
|
|
$initialCount = $deck->count(); |
47
|
|
|
$player->drawCard($deck); |
48
|
|
|
|
49
|
|
|
$this->assertEquals($initialCount - 1, $deck->count()); |
50
|
|
|
$this->assertGreaterThan(0, $player->getScore()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testDeckCount(): void |
54
|
|
|
{ |
55
|
|
|
$factory = new CardFactory(); |
56
|
|
|
$deck = new DeckOfCards($factory); |
57
|
|
|
$this->assertEquals(52, $deck->count()); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more 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.