Test Failed
Push — main ( 49ffe2...63a966 )
by Vedrana
07:24 queued 02:15
created

CardGameControllerJsonTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testDrawCards() 0 7 1
A testShuffleDeck() 0 6 1
A testDrawCard() 0 7 1
A testGetDeck() 0 6 1
A testDrawCardWhenEmptyDeck() 0 17 2
1
<?php
2
3
namespace App\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
/**
8
 * Class CardGameControllerJsonTest
9
 */
10
class CardGameControllerJsonTest extends WebTestCase
11
{
12
    /**
13
     * Test the GET /api/deck to retrieve the current deck.
14
     *
15
     * @return void
16
     */
17
    public function testGetDeck(): void
18
    {
19
        $client = static::createClient();
20
        $client->request('GET', '/api/deck');
21
22
        $this->assertResponseIsSuccessful();
23
    }
24
25
    /**
26
     * Test the POST /api/deck/shuffle to shuffle the deck.
27
     *
28
     * @return void
29
     */
30
    public function testShuffleDeck(): void
31
    {
32
        $client = static::createClient();
33
        $client->request('POST', '/api/deck/shuffle');
34
35
        $this->assertResponseIsSuccessful();
36
    }
37
38
    /**
39
     * Test draw a single card from.
40
     *
41
     * @return void
42
     */
43
    public function testDrawCard(): void
44
    {
45
        $client = static::createClient();
46
        $client->request('POST', '/api/deck/shuffle');
47
        $client->request('POST', '/api/deck/draw');
48
49
        $this->assertResponseIsSuccessful();
50
    }
51
52
    /**
53
     * Test draw multiple cards.
54
     *
55
     * @return void
56
     */
57
    public function testDrawCards(): void
58
    {
59
        $client = static::createClient();
60
        $client->request('POST', '/api/deck/shuffle');
61
        $client->request('POST', '/api/deck/draw/5');
62
63
        $this->assertResponseIsSuccessful();
64
    }
65
66
    /**
67
     * Test that drawing a card when the deck is empty gives error response.
68
     * @return void
69
     */
70
    public function testDrawCardWhenEmptyDeck(): void
71
    {
72
        $client = static::createClient();
73
74
        $client->request('GET', '/api/deck');
75
76
        $client->request('POST', '/api/deck/draw/54');
77
78
        $client->request('POST', '/api/deck/draw');
79
80
        $this->assertResponseStatusCodeSame(400);
81
82
        $content = $client->getResponse()->getContent();
83
        $this->assertIsString($content);
84
        $data = json_decode($content ?: '', true);
85
        $this->assertIsArray($data);
86
        $this->assertEquals('The deck is empty.', $data['error'] ?? null);
87
    }
88
}