Passed
Push — main ( f3cfb1...17781b )
by Emil
04:34
created

CardHandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFunctions() 0 21 1
A testAddCard() 0 9 1
A testCreateObject() 0 7 1
1
<?php
2
3
namespace App\Tests\Cards;
4
5
use PHPUnit\Framework\TestCase;
6
use App\Cards\CardGraphic;
7
use App\Cards\CardHand;
8
9
/**
10
 * Test cases for class CardHand.
11
 */
12
class CardHandTest extends TestCase
13
{
14
    /**
15
     * testCreateObject
16
     *
17
     * Construct object and verify that the object has the expected
18
     * properties, use no arguments.
19
     *
20
     * @return void
21
     */
22
    public function testCreateObject(): void
23
    {
24
        $cardHand = new CardHand();
25
        $this->assertInstanceOf(CardHand::class, $cardHand);
26
27
        $res = $cardHand->getString();
28
        $this->assertEmpty($res);
29
    }
30
31
    /**
32
     * testAddCard
33
     *
34
     * Test the add card function
35
     *
36
     * @return void
37
     */
38
    public function testAddCard(): void
39
    {
40
        $cardHand = new CardHand();
41
42
        $cardHand->addCard(new CardGraphic("a", "Heart"));
43
        $cardHand->addCard(new CardGraphic("king", "spade"));
44
45
        $res = $cardHand->getString();
46
        $this->assertEquals(['🂱', '🂮'], $res);
47
    }
48
49
    /**
50
     * testGetFunctions
51
     *
52
     * Test the get functions of the class
53
     *
54
     * @return void
55
     */
56
    public function testGetFunctions(): void
57
    {
58
        $cardHand = new CardHand();
59
60
        $cardHand->addCard(new CardGraphic("a", "Heart"));
61
        $cardHand->addCard(new CardGraphic("king", "spade"));
62
63
        $cardCount = $cardHand->cardCount();
64
        $this->assertEquals(2, $cardCount);
65
66
        $value = $cardHand->getValue();
67
        $this->assertEquals(14, $value);
68
69
        $value = $cardHand->getValueAceHigh();
70
        $this->assertEquals(27, $value);
71
72
        $value = $cardHand->getBlackJackValue();
73
        $this->assertEquals(11, $value);
74
75
        $value = $cardHand->getBlackJackValueAceHigh();
76
        $this->assertEquals(21, $value);
77
    }
78
}
79