LuckyControllerJsonTest::testJsonLuckyNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.8666
1
<?php
2
3
namespace App\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
/**
8
 * Class LuckyControllerJsonTest
9
 */
10
class LuckyControllerJsonTest extends WebTestCase
11
{
12
    /**
13
     * Test the /api/lucky/number route.
14
     *
15
     * @return void
16
     */
17
    public function testJsonLuckyNumber(): void
18
    {
19
        $client = static::createClient();
20
        $client->request('GET', '/api/lucky/number');
21
22
        $this->assertResponseIsSuccessful();
23
        $this->assertResponseFormatSame('json');
24
25
        $content = $client->getResponse()->getContent();
26
        $this->assertIsString($content, 'Response content is not a string.');
27
28
        $data = json_decode($content, true);
29
        $this->assertIsArray($data, 'Decoded JSON is not an array.');
30
31
        $this->assertArrayHasKey('lucky-number', $data);
32
        $this->assertArrayHasKey('lucky-message', $data);
33
        $this->assertIsInt($data['lucky-number']);
34
        $this->assertSame('Hi there!', $data['lucky-message']);
35
    }
36
}
37