BlackjackGameTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 30
c 2
b 0
f 1
dl 0
loc 67
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetHandValue() 0 17 1
A testDealCards() 0 10 1
A testCreateBlackjackGame() 0 10 1
A testHit() 0 12 1
1
<?php
2
3
namespace App\Game;
4
5
use PHPUnit\Framework\TestCase;
6
use App\Card\Deck;
7
use App\Card\Card;
8
9
/**
10
 * Test cases for class BlackjackGame.
11
 */
12
class BlackjackGameTest extends TestCase
13
{
14
    /**
15
     * Construct object and verify that the object has the expected
16
     * properties, use no arguments.
17
     */
18
    public function testCreateBlackjackGame()
19
    {
20
        $game = new BlackjackGame();
21
        $this->assertInstanceOf("\App\Game\BlackjackGame", $game);
22
23
        $playerHand = $game->getPlayerHand();
24
        $this->assertEmpty($playerHand);
25
26
        $dealerHand = $game->getDealerHand();
27
        $this->assertEmpty($dealerHand);
28
    }
29
    /**
30
     * Test dealing cards.
31
     */
32
    public function testDealCards()
33
    {
34
        $game = new BlackjackGame();
35
        $game->dealCards();
36
37
        $playerHand = $game->getPlayerHand();
38
        $this->assertCount(2, $playerHand);
39
40
        $dealerHand = $game->getDealerHand();
41
        $this->assertCount(1, $dealerHand);
42
    }
43
    /**
44
     * Test hitting player and dealer.
45
     */
46
    public function testHit()
47
    {
48
        $game = new BlackjackGame();
49
        $game->dealCards();
50
51
        $game->hitPlayer();
52
        $playerHand = $game->getPlayerHand();
53
        $this->assertCount(3, $playerHand);
54
55
        $game->hitDealer();
56
        $dealerHand = $game->getDealerHand();
57
        $this->assertCount(2, $dealerHand);
58
    }
59
    /**
60
     * Test hand value, stub Card to assure the value can be asserted.
61
     */
62
    public function testGetHandValue()
63
    {
64
        $game = new BlackjackGame();
65
66
        // Create a stub for the Card class
67
        $stub = $this->createMock(Card::class);
68
69
        // Configure the stub
70
        $stub->method('getBlackjackValue')
71
             ->willReturn(7, 11);
72
        $stub->method('getValue')
73
             ->willReturn('7', 'Ace');
74
75
        $hand = [clone $stub, clone $stub];
76
77
        $value = $game->getHandValue($hand);
78
        $this->assertEquals(18, $value);
79
    }
80
}
81