Test Failed
Push — main ( 99efcd...df6632 )
by Alex
14:53
created

CardTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 56
rs 10
wmc 5
1
<?php
2
3
namespace App\Card;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Test cases for class Card and CardGraphic. Note that testing CardGraphic will cover parts of the base class too.
9
 * To avoid duplicate code, CardGraphic is therefore used instead of the base class in most test cases.
10
 */
11
class CardTest extends TestCase
12
{
13
    /**
14
     * Test create new Card object.
15
     */
16
    public function testCreateCard(): void
17
    {
18
        $card = new CardGraphic(1, 1);
19
        $this->assertInstanceOf('App\Card\Card', $card);
20
    }
21
22
    /**
23
     * Test get actual rank integer value.
24
     * Note that the actual rank of a card is different from the value passed to the constructor.
25
     * That initial value can be 0 (as in this case) and is used for indexing inside the class.
26
     * No real playing card has a rank of 0 though, so the getRank method increments it by one.
27
     */
28
    public function testGetRank(): void
29
    {
30
        $card = new CardGraphic(42, 0);
31
        $res = $card->getRank();
32
        $exp = 1;
33
        $this->assertSame($exp, $res);
34
    }
35
36
    /**
37
     * Test get suit integer value.
38
     */
39
    public function testGetSuit(): void
40
    {
41
        $card = new CardGraphic(1, 2);
42
        $res = $card->getSuit();
43
        $exp = 1;
44
        $this->assertSame($exp, $res);
45
    }
46
47
    /**
48
     * Test get Card string representation.
49
     */
50
    public function testCardToString(): void
51
    {
52
        $card = new Card(1, 2);
53
        $res = $card->__toString();
54
        $exp = '3 of Diamonds';
55
        $this->assertSame($exp, $res);
56
    }
57
58
    /**
59
     * Test get CardGraphic string representation.
60
     */
61
    public function testCardGraphicToString(): void
62
    {
63
        $card = new CardGraphic(1, 2);
64
        $res = $card->__toString();
65
        $exp = '3♦';
66
        $this->assertSame($exp, $res);
67
    }
68
}
69