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

DeckOfCardsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateObject() 0 7 1
A testDeckManipulation() 0 10 1
A testDrawCard() 0 25 2
1
<?php
2
3
namespace App\Tests\Cards;
4
5
use PHPUnit\Framework\TestCase;
6
use App\Cards\CardGraphic;
7
use App\Cards\DeckOfCards;
8
9
/**
10
 * Test cases for class DeckOfCards.
11
 */
12
class DeckOfCardsTest 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
        $deck = new DeckOfCards();
25
        $this->assertInstanceOf(DeckOfCards::class, $deck);
26
27
        $res = $deck->getString();
28
        $this->assertNotEmpty($res);
29
    }
30
31
    /**
32
     * testDeckManipulation
33
     *
34
     * Test the various ways to manipulate the deck
35
     *
36
     * @return void
37
     */
38
    public function testDeckManipulation(): void
39
    {
40
        $deck = new DeckOfCards();
41
        $shuffledDeck = new DeckOfCards();
42
43
        $shuffledDeck->shuffleDeck();
44
        $this->assertNotEquals($deck->getString(), $shuffledDeck->getString());
45
46
        $shuffledDeck->resetDeck();
47
        $this->assertEquals($deck->getString(), $shuffledDeck->getString());
48
    }
49
50
    /**
51
     * testDrawCard
52
     *
53
     * Test the draw card function and then the reshuffle function
54
     *
55
     * @return void
56
     */
57
    public function testDrawCard(): void
58
    {
59
        $deck = new DeckOfCards();
60
61
        $cardCount = $deck->cardCount();
62
        $this->assertEquals(52, $cardCount);
63
64
        $card = $deck->drawCard();
65
        $this->assertEquals('🂱', $card->getString());
66
        $cardCount = $deck->cardCount();
67
        $this->assertEquals(51, $cardCount);
68
69
        for ($i = 0; $i < $cardCount; $i++) {
70
            $deck->drawCard();
71
        }
72
73
        $card = $deck->drawCard();
74
        $this->assertEquals(CardGraphic::BLANK_CARD, $card->getString());
75
76
        $deck->reshuffleDeck();
77
        $cardCount = $deck->cardCount();
78
        $this->assertEquals(52, $cardCount);
79
80
        $deckReference = new DeckOfCards();
81
        $this->assertNotEquals($deckReference->getString(), $deck->getString());
82
    }
83
}
84