Game21ControllerJsonTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGame21() 0 21 1
A testNoGameInSession() 0 15 1
1
<?php
2
3
namespace App\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
/**
8
 * @group controller
9
 */
10
class Game21ControllerJsonTest extends WebTestCase
11
{
12
    /**
13
     * Tests api/game when no Game21 is in the session.
14
     */
15
    public function testNoGameInSession(): void
16
    {
17
        $client = static::createClient();
18
        $client->request('GET', '/api/game');
19
20
        $this->assertResponseStatusCodeSame(404);
21
22
        $content = $client->getResponse()->getContent();
23
        $this->assertIsString($content);
24
25
        $data = json_decode($content, true);
26
        $this->assertIsArray($data);
27
28
        $this->assertArrayHasKey('error', $data);
29
        $this->assertEquals('No active game found in session.', $data['error']);
30
    }
31
32
    /*
33
     * Tests to init a new Game21 and return JSON data.
34
     */
35
    public function testGame21(): void
36
    {
37
        $client = static::createClient();
38
39
        // Trigger game init logic
40
        $client->request('GET', '/game/play');
41
42
        // Call the /api/game
43
        $client->request('GET', '/api/game');
44
45
        $this->assertResponseIsSuccessful();
46
        $content = $client->getResponse()->getContent();
47
        $this->assertIsString($content);
48
49
        $data = json_decode($content, true);
50
        $this->assertIsArray($data);
51
52
        $this->assertArrayHasKey('player', $data);
53
        $this->assertArrayHasKey('playerTotal', $data);
54
        $this->assertArrayHasKey('bank', $data);
55
        $this->assertArrayHasKey('bankTotal', $data);
56
    }
57
}
58