BlackJackControllerTest::testBlackJackReset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
7
use Symfony\Component\Routing\RouterInterface;
8
9
class BlackJackControllerTest extends WebTestCase
10
{
11
    /**
12
     * testGameStart
13
     *
14
     * Test game_start route
15
     *
16
     * @return void
17
     */
18
    public function testGameStart(): void
19
    {
20
        // Create a client to browse the application
21
        $client = static::createClient();
22
23
        // Retrieve router service
24
        /** @var RouterInterface $router */
25
        $router = static::getContainer()->get('router');
26
27
        // Generate URL from route name
28
        $url = $router->generate('game_start');
29
30
        // Send a GET request to the route
31
        $crawler = $client->request('GET', $url);
32
33
        // Assert the response status code
34
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
35
36
        // Assert that certain content exists in the response
37
        $this->assertStringContainsString('Black Jack:', $crawler->filter('title')->text());
38
    }
39
40
    /**
41
     * testBlackJackDoc
42
     *
43
     * Test game_doc route
44
     *
45
     * @return void
46
     */
47
    public function testBlackJackDoc(): void
48
    {
49
        // Create a client to browse the application
50
        $client = static::createClient();
51
52
        // Retrieve router service
53
        /** @var RouterInterface $router */
54
        $router = static::getContainer()->get('router');
55
56
        // Generate URL from route name
57
        $url = $router->generate('game_doc');
58
59
        // Send a GET request to the route
60
        $crawler = $client->request('GET', $url);
61
62
        // Assert the response status code
63
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
64
65
        // Assert that certain content exists in the response
66
        $this->assertStringContainsString('Black Jack: Doc', $crawler->filter('title')->text());
67
    }
68
69
    /**
70
     * testBlackJackStart
71
     *
72
     * Test game_black_jack route
73
     *
74
     * @return void
75
     */
76
    public function testBlackJackStart(): void
77
    {
78
        // Create a client to browse the application
79
        $client = static::createClient();
80
81
        // Retrieve router service
82
        /** @var RouterInterface $router */
83
        $router = static::getContainer()->get('router');
84
85
        // Generate URL from route name
86
        $url = $router->generate('game_black_jack');
87
88
        // Send a GET request to the route
89
        $crawler = $client->request('GET', $url);
90
91
        // Assert the response status code
92
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
93
94
        // Assert that certain content exists in the response
95
        $this->assertStringContainsString('Black Jack: Game', $crawler->filter('title')->text());
96
    }
97
98
    /**
99
     * testBlackJackHit
100
     *
101
     * Test black_jack_hit route
102
     *
103
     * @return void
104
     */
105
    public function testBlackJackHit(): void
106
    {
107
        // Create a client to browse the application
108
        $client = static::createClient();
109
110
        // Retrieve router service
111
        /** @var RouterInterface $router */
112
        $router = static::getContainer()->get('router');
113
114
        // Generate URL from route name
115
        $url = $router->generate('black_jack_hit');
116
117
        // Send POST request to the route
118
        $client->request('POST', $url);
119
120
        // Assert that response is a redirect (302 status)
121
        $response = $client->getResponse();
122
        $this->assertTrue($response->isRedirect());
123
124
        for ($i = 0; $i < 5; $i++) {
125
            // Send POST request to the route
126
            $client->request('POST', $url);
127
128
            // Assert that response is a redirect (302 status)
129
            $response = $client->getResponse();
130
            $this->assertTrue($response->isRedirect());
131
        }
132
    }
133
134
    /**
135
     * testBlackJackStay
136
     *
137
     * Test black_jack_stay route
138
     *
139
     * @return void
140
     */
141
    public function testBlackJackStay(): void
142
    {
143
        // Create a client to browse the application
144
        $client = static::createClient();
145
146
        // Retrieve router service
147
        /** @var RouterInterface $router */
148
        $router = static::getContainer()->get('router');
149
150
        // Generate URL from route name
151
        $url = $router->generate('black_jack_stay');
152
153
        // Send POST request to the route
154
        $client->request('POST', $url);
155
156
        // Assert that response is a redirect (302 status)
157
        $response = $client->getResponse();
158
        $this->assertTrue($response->isRedirect());
159
    }
160
161
    /**
162
     * testBlackJackReset
163
     *
164
     * Test black_jack_reset route
165
     *
166
     * @return void
167
     */
168
    public function testBlackJackReset(): void
169
    {
170
        // Create a client to browse the application
171
        $client = static::createClient();
172
173
        // Retrieve router service
174
        /** @var RouterInterface $router */
175
        $router = static::getContainer()->get('router');
176
177
        // Generate URL from route name
178
        $url = $router->generate('black_jack_reset');
179
180
        // Send POST request to the route
181
        $client->request('POST', $url);
182
183
        // Assert that response is a redirect (302 status)
184
        $response = $client->getResponse();
185
        $this->assertTrue($response->isRedirect());
186
    }
187
}
188