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

LibraryControllerJsonTest::testApiShowBookIsbn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9332
1
<?php
2
3
namespace App\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
/**
8
 * Class LibraryControllerJsonTest
9
 */
10
class LibraryControllerJsonTest extends WebTestCase
11
{
12
    /**
13
     * Test the /api/library/books.
14
     */
15
    public function testApiShowLibrary(): void
16
    {
17
        $client = static::createClient();
18
        $client->request('GET', '/api/library/books');
19
20
        $this->assertResponseIsSuccessful();
21
        $this->assertResponseFormatSame('json');
22
    }
23
24
    /**
25
     * Test the /api/library/book/{isbn} with a valid ISBN.
26
     */
27
    public function testApiShowBookIsbn(): void
28
    {
29
        $client = static::createClient();
30
31
        $isbn = '9780099448785';
32
        $client->request('GET', "/api/library/book/{$isbn}");
33
34
        $this->assertResponseIsSuccessful();
35
        $this->assertResponseFormatSame('json');
36
37
        $content = $client->getResponse()->getContent();
38
        $this->assertIsString($content, 'Response content is not a string.');
39
40
        $data = json_decode($content, true);
41
        $this->assertIsArray($data, 'Decoded JSON is not an array.');
42
43
        $this->assertEquals($isbn, $data['isbn'] ?? null);
44
    }
45
46
    /**
47
     * Test the /api/library/book/{isbn} with an invalid ISBN.
48
     */
49
    public function testApiShowBookIsbnInvalid(): void
50
    {
51
        $client = static::createClient();
52
53
        $isbn = '1111111-isbn';
54
        $client->request('GET', "/api/library/book/{$isbn}");
55
56
        $this->assertResponseStatusCodeSame(404);
57
    }
58
}