Passed
Pull Request — master (#7)
by Mattia
08:27 queued 03:30
created

testShouldGenerateAvatarUsingDifferentUuidFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MinepicTests\Http\Controllers;
6
7
use Minepic\Cache\UserNotFoundCache;
8
use MinepicTests\TestCase;
9
10
class ApiControllerTest extends TestCase
11
{
12
    protected function setUp(): void
13
    {
14
        parent::setUp();
15
        \DB::beginTransaction();
16
        UserNotFoundCache::add('ThisIsAnInvalidAccountName');
17
    }
18
19
    protected function tearDown(): void
20
    {
21
        \DB::rollBack();
22
        parent::tearDown();
23
    }
24
25
    public function testShouldReturnSteveAvatar(): void
26
    {
27
        $this->get('/avatar/ThisIsAnInvalidAccountName');
28
        $actualImage = $this->response->getContent();
29
        $expectedImage = \file_get_contents(base_path('tests/images/steve_avatar.png'));
30
        $this->assertEquals($expectedImage, $actualImage);
31
    }
32
33
    public function testShouldReturnUserAvatarWithSize(): void
34
    {
35
        $this->get('/avatar/200/_Cyb3r');
36
        $this->assertResponseOk();
37
        $this->assertEquals(
38
            'image/png',
39
            $this->response->headers->get('Content-Type')
40
        );
41
    }
42
43
    public function testShouldReturnUserSkinWithoutSize(): void
44
    {
45
        $this->get('/skin/_Cyb3r');
46
        $this->assertResponseOk();
47
        $this->assertEquals(
48
            'image/png',
49
            $this->response->headers->get('Content-Type')
50
        );
51
    }
52
53
    public function testShouldReturnUserSkinBackWithoutSize(): void
54
    {
55
        $this->get('/skin-back/_Cyb3r');
56
        $this->assertResponseOk();
57
        $this->assertEquals(
58
            'image/png',
59
            $this->response->headers->get('Content-Type')
60
        );
61
    }
62
63
    public function testShouldReturnUserSkinWithSize(): void
64
    {
65
        $this->get('/skin/200/_Cyb3r');
66
        $this->assertResponseOk();
67
        $this->assertEquals(
68
            'image/png',
69
            $this->response->headers->get('Content-Type')
70
        );
71
    }
72
73
    public function testShouldReturnUserSkinBackWithSize(): void
74
    {
75
        $this->get('/skin-back/200/_Cyb3r');
76
        $this->assertResponseOk();
77
        $this->assertEquals(
78
            'image/png',
79
            $this->response->headers->get('Content-Type')
80
        );
81
    }
82
83
    public function testShouldReturnSteveSkin(): void
84
    {
85
        $this->get('/skin/ThisIsAnInvalidAccountName');
86
        $actualImage = $this->response->getContent();
87
        $expectedImage = \file_get_contents(base_path('tests/images/steve_skin.png'));
88
        $this->assertEquals($expectedImage, $actualImage);
89
    }
90
91
    public function testShouldReturnSteveSkinBack(): void
92
    {
93
        $this->get('/skin-back/ThisIsAnInvalidAccountName');
94
        $actualImage = $this->response->getContent();
95
        $expectedImage = \file_get_contents(base_path('tests/images/steve_skin_back.png'));
96
        $this->assertEquals($expectedImage, $actualImage);
97
    }
98
99
    public function testShouldReturnSteveHead(): void
100
    {
101
        $this->get('/head/ThisIsAnInvalidAccountName');
102
        $this->assertResponseOk();
103
        $this->assertEquals(
104
            'image/png',
105
            $this->response->headers->get('Content-Type')
106
        );
107
    }
108
109
    /**
110
     * @group pippo
111
     */
112
    public function testShouldDownloadSteveTexture(): void
113
    {
114
        $this->get('/download/00000000000000000000000000000000');
115
        $actualImage = $this->response->getContent();
116
        $expectedImage = \file_get_contents(base_path('tests/images/steve_raw.png'));
117
118
        $this->assertEquals($expectedImage, $actualImage);
119
    }
120
121
    public function testShouldGenerateIsometricAvatar(): void
122
    {
123
        $this->get('/head/d59dcabb30424b978f7201d1a076637f');
124
        $this->assertResponseOk();
125
        $this->assertEquals(
126
            'image/png',
127
            $this->response->headers->get('Content-Type')
128
        );
129
    }
130
131
    public function testShouldGenerateAvatarUsingDifferentUuidFormat(): void
132
    {
133
        $this->get('/avatar/d59dcabb-3042-4b97-8f72-01d1a076637f');
134
        $this->assertResponseOk();
135
        $this->assertEquals(
136
            'image/png',
137
            $this->response->headers->get('Content-Type')
138
        );
139
    }
140
141
    public function testShouldFailUpdatingUnExistingUser(): void
142
    {
143
        $this->get('/update/d59dcabb30424b978f7201ffffffffff');
144
145
        $expectedStatusCode = 404;
146
        $expectedContentType = 'application/json';
147
        $this->assertEquals($expectedContentType, $this->response->headers->get('Content-Type'));
148
        $this->assertEquals($expectedStatusCode, $this->response->getStatusCode());
149
    }
150
}
151