|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Card; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Test cases for class DeckOfCards. |
|
9
|
|
|
*/ |
|
10
|
|
|
class DeckOfCardsTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Construct object without input arguments and verify that the object has the expected |
|
14
|
|
|
* properties. |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testCreateDeckOfCards(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$deck = new DeckOfCards(); |
|
19
|
|
|
$this->assertInstanceOf("\App\Card\DeckOfCards", $deck); |
|
20
|
|
|
|
|
21
|
|
|
$res = $deck->getValues(); |
|
22
|
|
|
$exp = [ |
|
23
|
|
|
['C', 'A'], ['C', '2'], ['C', '3'], ['C', '4'], ['C', '5'], ['C', '6'], ['C', '7'], ['C', '8'], ['C', '9'], ['C', '10'], ['C', 'J'], ['C', 'Q'], ['C', 'K'], |
|
24
|
|
|
['S', 'A'], ['S', '2'], ['S', '3'], ['S', '4'], ['S', '5'], ['S', '6'], ['S', '7'], ['S', '8'], ['S', '9'], ['S', '10'], ['S', 'J'], ['S', 'Q'], ['S', 'K'], |
|
25
|
|
|
['H', 'A'], ['H', '2'], ['H', '3'], ['H', '4'], ['H', '5'], ['H', '6'], ['H', '7'], ['H', '8'], ['H', '9'], ['H', '10'], ['H', 'J'], ['H', 'Q'], ['H', 'K'], |
|
26
|
|
|
['D', 'A'], ['D', '2'], ['D', '3'], ['D', '4'], ['D', '5'], ['D', '6'], ['D', '7'], ['D', '8'], ['D', '9'], ['D', '10'], ['D', 'J'], ['D', 'Q'], ['D', 'K'], |
|
27
|
|
|
]; |
|
28
|
|
|
$this->assertEquals($exp, $res); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Test Deck-object against correct order, after: |
|
33
|
|
|
* 1. Deck has been shuffled |
|
34
|
|
|
* 2. Deck has been sorted |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testShuffleAndSortCards(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$deck = new DeckOfCards(); |
|
39
|
|
|
$exp = [ |
|
40
|
|
|
['C', 'A'], ['C', '2'], ['C', '3'], ['C', '4'], ['C', '5'], ['C', '6'], ['C', '7'], ['C', '8'], ['C', '9'], ['C', '10'], ['C', 'J'], ['C', 'Q'], ['C', 'K'], |
|
41
|
|
|
['S', 'A'], ['S', '2'], ['S', '3'], ['S', '4'], ['S', '5'], ['S', '6'], ['S', '7'], ['S', '8'], ['S', '9'], ['S', '10'], ['S', 'J'], ['S', 'Q'], ['S', 'K'], |
|
42
|
|
|
['H', 'A'], ['H', '2'], ['H', '3'], ['H', '4'], ['H', '5'], ['H', '6'], ['H', '7'], ['H', '8'], ['H', '9'], ['H', '10'], ['H', 'J'], ['H', 'Q'], ['H', 'K'], |
|
43
|
|
|
['D', 'A'], ['D', '2'], ['D', '3'], ['D', '4'], ['D', '5'], ['D', '6'], ['D', '7'], ['D', '8'], ['D', '9'], ['D', '10'], ['D', 'J'], ['D', 'Q'], ['D', 'K'], |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
// 1. Test shuffle |
|
47
|
|
|
$deck->shuffleCards(); |
|
48
|
|
|
$res = $deck->getValues(); |
|
49
|
|
|
$this->assertNotEquals($exp, $res); |
|
50
|
|
|
|
|
51
|
|
|
// 2. Test sorted |
|
52
|
|
|
$deck->sortCards(); |
|
53
|
|
|
$res = $deck->getValues(); |
|
54
|
|
|
$this->assertEquals($exp, $res); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Test that the object contains the correct number of cards: |
|
59
|
|
|
* 1. After deck has been created |
|
60
|
|
|
* 2. After a card has been drawn from the deck |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testGetNoOfCards(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$deck = new DeckOfCards(); |
|
65
|
|
|
|
|
66
|
|
|
// 1. Initial amount of cards in deck |
|
67
|
|
|
$exp = 52; |
|
68
|
|
|
$res = $deck->getNumberCards(); |
|
69
|
|
|
$this->assertEquals($exp, $res); |
|
70
|
|
|
|
|
71
|
|
|
// 2. After card has been drawn |
|
72
|
|
|
$deck->drawCard(); |
|
73
|
|
|
$exp = 51; |
|
74
|
|
|
$res = $deck->getNumberCards(); |
|
75
|
|
|
$this->assertEquals($exp, $res); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Test draw card method against mocked object. |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testDrawStubbedCard(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$stub = $this->createMock(DeckOfCards::class); |
|
84
|
|
|
$stub->method('drawCard') |
|
85
|
|
|
->willReturn(["H", "10"]); |
|
86
|
|
|
|
|
87
|
|
|
$res = $stub->drawCard(); |
|
88
|
|
|
$exp = ["H", "10"]; |
|
89
|
|
|
$this->assertEquals($exp, $res); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|