Passed
Push — master ( 9aa048...898b5e )
by Mattia
04:05
created

JsonControllerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 24
dl 0
loc 66
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldReturnMostWantedUser() 0 6 1
A setUp() 0 4 1
A shouldReturnUserDataUsingUsername() 0 6 1
A shouldReturnTypeaheadEntries() 0 4 1
A shouldNotReturnUserDataUsingInvalidUuid() 0 7 1
A tearDown() 0 4 1
A shouldReturnUserDataUsingUuid() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MinepicTests\Http\Controllers;
6
7
use MinepicTests\TestCase;
8
9
class JsonControllerTest extends TestCase
10
{
11
    public function setUp(): void
12
    {
13
        parent::setUp();
14
        \DB::beginTransaction();
15
    }
16
17
    public function tearDown(): void
18
    {
19
        \DB::rollBack();
20
        parent::tearDown();
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function shouldReturnTypeaheadEntries(): void
27
    {
28
        $this->get('/api/v1/typeahead/Cy');
29
        $this->assertJson($this->response->content());
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function shouldReturnUserDataUsingUuid(): void
36
    {
37
        $this->get('/api/v1/user/d59dcabb30424b978f7201d1a076637f');
38
        $responseContent = $this->response->content();
39
        $this->assertJson($responseContent);
40
        $this->seeJsonStructure(['ok', 'data'], $responseContent);
0 ignored issues
show
Bug introduced by
$responseContent of type string is incompatible with the type array|null expected by parameter $responseData of Laravel\Lumen\Testing\TestCase::seeJsonStructure(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $this->seeJsonStructure(['ok', 'data'], /** @scrutinizer ignore-type */ $responseContent);
Loading history...
41
    }
42
43
    /**
44
     * @test
45
     */
46
    public function shouldNotReturnUserDataUsingInvalidUuid(): void
47
    {
48
        $this->get('/api/v1/user/d59dcabb30424b978f7201ffffffffff');
49
        $responseContent = $this->response->content();
50
        $this->assertResponseStatus(404);
51
        $this->assertJson($responseContent);
52
        $this->seeJsonStructure(['ok', 'message'], $responseContent);
0 ignored issues
show
Bug introduced by
$responseContent of type string is incompatible with the type array|null expected by parameter $responseData of Laravel\Lumen\Testing\TestCase::seeJsonStructure(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        $this->seeJsonStructure(['ok', 'message'], /** @scrutinizer ignore-type */ $responseContent);
Loading history...
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function shouldReturnUserDataUsingUsername(): void
59
    {
60
        $this->get('/api/v1/user/_Cyb3r');
61
        $responseContent = $this->response->content();
62
        $this->assertJson($responseContent);
63
        $this->seeJsonStructure(['ok', 'data'], $responseContent);
0 ignored issues
show
Bug introduced by
$responseContent of type string is incompatible with the type array|null expected by parameter $responseData of Laravel\Lumen\Testing\TestCase::seeJsonStructure(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        $this->seeJsonStructure(['ok', 'data'], /** @scrutinizer ignore-type */ $responseContent);
Loading history...
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function shouldReturnMostWantedUser(): void
70
    {
71
        $this->get('/api/v1/stats/user/most-wanted');
72
        $responseContent = $this->response->content();
73
        $this->assertJson($responseContent);
74
        $this->seeJsonStructure(['ok', 'data'], $responseContent);
0 ignored issues
show
Bug introduced by
$responseContent of type string is incompatible with the type array|null expected by parameter $responseData of Laravel\Lumen\Testing\TestCase::seeJsonStructure(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        $this->seeJsonStructure(['ok', 'data'], /** @scrutinizer ignore-type */ $responseContent);
Loading history...
75
    }
76
}
77