1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Tests\Card; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use App\Card\Card; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test cases for class Card. |
10
|
|
|
*/ |
11
|
|
|
class CardTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Test creating an instance of Card. |
15
|
|
|
*/ |
16
|
|
|
public function testCreateCard(): void |
17
|
|
|
{ |
18
|
|
|
$card = new Card('Hearts', 'Ace'); |
19
|
|
|
$this->assertInstanceOf(Card::class, $card); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test getting the suit of the card. |
24
|
|
|
*/ |
25
|
|
|
public function testGetSuire(): void |
26
|
|
|
{ |
27
|
|
|
$card = new Card('Clubs', 'Ace'); |
28
|
|
|
$this->assertEquals('Clubs', $card->getSuit()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Test getting the value of the card. |
33
|
|
|
*/ |
34
|
|
|
public function testGetValue(): void |
35
|
|
|
{ |
36
|
|
|
$card = new Card('Spades', 'Ace'); |
37
|
|
|
$this->assertEquals('Ace', $card->getValue()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Test getting the numeric value cards. |
42
|
|
|
*/ |
43
|
|
|
public function testNumericValue(): void |
44
|
|
|
{ |
45
|
|
|
$king = new Card('Diamond', 'King'); |
46
|
|
|
$queen = new Card('Hearts', 'Queen'); |
47
|
|
|
$jack = new Card('Spades', 'Jack'); |
48
|
|
|
$ace = new Card('Clubs', 'Ace'); |
49
|
|
|
|
50
|
|
|
$card = new Card('Hearts', '9'); |
51
|
|
|
|
52
|
|
|
$this->assertEquals(13, $king->getNumericValue()); |
53
|
|
|
$this->assertEquals(12, $queen->getNumericValue()); |
54
|
|
|
$this->assertEquals(11, $jack->getNumericValue()); |
55
|
|
|
$this->assertEquals(1, $ace->getNumericValue()); |
56
|
|
|
|
57
|
|
|
$this->assertEquals(9, $card->getNumericValue()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Test the string representation of the card. |
62
|
|
|
*/ |
63
|
|
|
public function testToString(): void |
64
|
|
|
{ |
65
|
|
|
$card = new Card('Spades', 'Jack'); |
66
|
|
|
|
67
|
|
|
$this->assertEquals('Jack of Spades', (string)$card); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Test converting the card to an array. |
72
|
|
|
*/ |
73
|
|
|
public function testToArray(): void |
74
|
|
|
{ |
75
|
|
|
$card = new Card('Hearts', '9'); |
76
|
|
|
$cardArray = ['value' => '9', 'suit' => 'Hearts']; |
77
|
|
|
|
78
|
|
|
$this->assertEquals($cardArray, $card->toArray()); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|