Passed
Push — main ( b1744e...69bb1b )
by Alex
03:36
created

GameHasWonTest::testCheckPlayerWon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 3
dl 0
loc 19
rs 9.8666
c 1
b 0
f 0
1
<?php
2
3
namespace App\Game;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Test cases for GameManager getHasWon and updateHasWonStatus methods.
9
 */
10
class GameHasWonTest extends TestCase
11
{
12
    /**
13
     * Provide data sets to test who has won.
14
     * @return mixed[] As data set
15
     */
16
    // public static function pointsProvider(): array
17
    // {
18
    //     return [
19
    //         'Player over 21 — Banker wins'     => [22, 0, -1],
20
    //         'Player scores 21 — Player wins'   => [21, 0, 1],
21
    //         'Player over banker — Player wins' => [20, 18, 1],
22
    //         'Banker over 21 — Player wins'     => [15, 23, 1],
23
    //         'Banker over player — Banker wins' => [14, 17, -1],
24
    //         'Same score — Banker wins'         => [19, 19, -1],
25
    //         'Only player score — No winner'    => [16, 0, 0],
26
    //     ];
27
    // }
28
    /**
29
     * Test different cases of who has won.
30
     * @dataProvider pointsProvider
31
     * @param int $playerPoints
32
     * @param int $bankerPoints
33
     * @param int $expected
34
     */
35
    // public function testHasWon(int $playerPoints, int $bankerPoints, int $expected): void
36
    // {
37
    //     // Create and configure stubs
38
    //     $player = $this->createStub(ReceiverInterface::class);
39
    //     $player->method('getPoints')
40
    //         ->willReturn($playerPoints);
41
    //     $banker = $this->createStub(BankerInterface::class);
42
    //     $banker->method('getPoints')
43
    //         ->willReturn($bankerPoints);
44
45
    //     // Set up game manager
46
    //     $gameManager = new GameManager();
47
    //     $gameManager->setPlayer($player);
48
    //     $gameManager->setBanker($banker);
49
50
    //     // Act and assert
51
    //     $gameManager->updateHasWonStatus();
52
    //     $res = $gameManager->getHasWon();
53
    //     $this->assertSame($expected, $res);
54
    // }
55
56
57
    /**
58
     * Provide data sets to test who has won.
59
     * @return mixed[] As data set
60
     */
61
    public static function pointsProvider(): array
62
    {
63
        return [
64
            'Player over 21 — Banker wins'     => [22, 0, -1],
65
            'Player scores 21 — Player wins'   => [21, 0, 1],
66
        ];
67
    }
68
    /**
69
     * Test different cases of who has won.
70
     * @dataProvider pointsProvider
71
     * @param int $playerPoints
72
     * @param int $bankerPoints
73
     * @param int $expected
74
     */
75
    public function testCheckPlayerWon(int $playerPoints, int $bankerPoints, int $expected): void
76
    {
77
        // Create and configure stubs
78
        $player = $this->createStub(ReceiverInterface::class);
79
        $player->method('getPoints')
80
            ->willReturn($playerPoints);
81
        $banker = $this->createStub(BankerInterface::class);
82
        $banker->method('getPoints')
83
            ->willReturn($bankerPoints);
84
85
        // Set up game manager
86
        $gameManager = new GameManager();
87
        $gameManager->setPlayer($player);
88
        $gameManager->setBanker($banker);
89
90
        // Act and assert
91
        $gameManager->checkPlayerWon();
92
        $res = $gameManager->getHasWon();
93
        $this->assertSame($expected, $res);
94
    }
95
96
    /**
97
     * Provide data sets to test who has won.
98
     * @return mixed[] As data set
99
     */
100
    public static function anotherPointsProvider(): array
101
    {
102
        return [
103
            'Banker over 21 — Player wins'     => [19, 23, 1],
104
            'Player over banker — Player wins'   => [20, 19, 1],
105
            'Banker over player — Banker wins'   => [20, 21, -1],
106
            'Banker equal player — Banker wins'   => [20, 20, -1],
107
        ];
108
    }
109
    /**
110
     * Test different cases of who has won.
111
     * @dataProvider anotherPointsProvider
112
     * @param int $playerPoints
113
     * @param int $bankerPoints
114
     * @param int $expected
115
     */
116
    public function testCheckBankerWon(int $playerPoints, int $bankerPoints, int $expected): void
117
    {
118
        // Create and configure stubs
119
        $player = $this->createStub(ReceiverInterface::class);
120
        $player->method('getPoints')
121
            ->willReturn($playerPoints);
122
        $banker = $this->createStub(BankerInterface::class);
123
        $banker->method('getPoints')
124
            ->willReturn($bankerPoints);
125
126
        // Set up game manager
127
        $gameManager = new GameManager();
128
        $gameManager->setPlayer($player);
129
        $gameManager->setBanker($banker);
130
131
        // Act and assert
132
        $gameManager->checkBankerWon();
133
        $res = $gameManager->getHasWon();
134
        $this->assertSame($expected, $res);
135
    }
136
}
137