1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Card; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use App\Card\Deck; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test cases for class Deck. |
10
|
|
|
*/ |
11
|
|
|
class DeckTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Test creating a new deck. |
15
|
|
|
*/ |
16
|
|
|
public function testCreateDeck(): void |
17
|
|
|
{ |
18
|
|
|
$deck = new Deck(); |
19
|
|
|
$this->assertCount(52, $deck->getCards()); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test that shuffling the deck changes the card order. |
24
|
|
|
*/ |
25
|
|
|
public function testShuffle(): void |
26
|
|
|
{ |
27
|
|
|
$deck1 = new Deck(); |
28
|
|
|
$deck1->shuffle(); |
29
|
|
|
|
30
|
|
|
$deck2 = new Deck(); |
31
|
|
|
$deck2->shuffle(); |
32
|
|
|
|
33
|
|
|
$this->assertNotEquals($deck1, $deck2); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Test drawing a single card reduces the deck size by one. |
38
|
|
|
*/ |
39
|
|
|
public function testDrawCard(): void |
40
|
|
|
{ |
41
|
|
|
$deck = new Deck(); |
42
|
|
|
$deck->drawCard(); |
43
|
|
|
|
44
|
|
|
$this->assertCount(51, $deck->getCards()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test drawing multiple cards reduces the deck size accordingly. |
49
|
|
|
*/ |
50
|
|
|
public function testDrawMoreCards(): void |
51
|
|
|
{ |
52
|
|
|
$deck = new Deck(); |
53
|
|
|
$deck->drawMoreCards(5); |
54
|
|
|
|
55
|
|
|
$this->assertCount(47, $deck->getCards()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Test drawing more cards than remaining returns an empty array. |
60
|
|
|
*/ |
61
|
|
|
public function testDrawMoreCardsNoCardsLeft(): void |
62
|
|
|
{ |
63
|
|
|
$deck = new Deck(); |
64
|
|
|
$deck->drawMoreCards(52); |
65
|
|
|
$drawMore = $deck->drawMoreCards(5); |
66
|
|
|
|
67
|
|
|
$this->assertCount(0, $drawMore); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Test drawing a card from an empty deck returns null. |
72
|
|
|
*/ |
73
|
|
|
public function testDrawCardIfEmpty(): void |
74
|
|
|
{ |
75
|
|
|
$deck = new Deck(); |
76
|
|
|
$deck->drawMoreCards(52); |
77
|
|
|
|
78
|
|
|
$this->assertNull($deck->drawCard()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Test remainingCards returns the correct count after drawing cards. |
83
|
|
|
*/ |
84
|
|
|
public function testRemainingCards(): void |
85
|
|
|
{ |
86
|
|
|
$deck = new Deck(); |
87
|
|
|
$deck->drawMoreCards(12); |
88
|
|
|
|
89
|
|
|
$this->assertEquals(40, $deck->remainingCards()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Test getCardsAsArray returns an array representation of all cards. |
94
|
|
|
*/ |
95
|
|
|
public function testGetCardsAsArray(): void |
96
|
|
|
{ |
97
|
|
|
$deck = new Deck(); |
98
|
|
|
$cards = $deck->getCardsAsArray(); |
99
|
|
|
|
100
|
|
|
$this->assertNotEmpty($cards); |
101
|
|
|
$this->assertCount(52, $cards); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|