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

ApiControllerTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
    public function setUp(): void
13
    {
14
        parent::setUp();
15
        \DB::beginTransaction();
16
        UserNotFoundCache::add('ThisIsAnInvalidAccountName');
17
    }
18
19
    public function tearDown(): void
20
    {
21
        \DB::rollBack();
22
        parent::tearDown();
23
    }
24
25
    /**
26
     * @test
27
     */
28
    public function shouldReturnSteveAvatar(): void
29
    {
30
        $this->get('/avatar/ThisIsAnInvalidAccountName');
31
        $actualImage = $this->response->getContent();
32
        $expectedImage = \file_get_contents(base_path('tests/images/steve_avatar.png'));
33
        $this->assertEquals($expectedImage, $actualImage);
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function shouldReturnUserAvatarWithSize(): void
40
    {
41
        $this->get('/avatar/200/_Cyb3r');
42
        $this->assertResponseOk();
43
        $this->assertEquals(
44
            'image/png',
45
            $this->response->headers->get('Content-Type')
46
        );
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function shouldReturnSteveSkin(): void
53
    {
54
        $this->get('/skin/ThisIsAnInvalidAccountName');
55
        $actualImage = $this->response->getContent();
56
        $expectedImage = \file_get_contents(base_path('tests/images/steve_skin.png'));
57
        $this->assertEquals($expectedImage, $actualImage);
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function shouldReturnSteveSkinBack(): void
64
    {
65
        $this->get('/skin-back/ThisIsAnInvalidAccountName');
66
        $actualImage = $this->response->getContent();
67
        $expectedImage = \file_get_contents(base_path('tests/images/steve_skin_back.png'));
68
        $this->assertEquals($expectedImage, $actualImage);
69
    }
70
71
    /**
72
     * @test
73
     */
74
    public function shouldReturnSteveHead(): void
75
    {
76
        $this->get('/head/ThisIsAnInvalidAccountName');
77
        $this->assertResponseOk();
78
        $this->assertEquals(
79
            'image/png',
80
            $this->response->headers->get('Content-Type')
81
        );
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function shouldDownloadSteveTexture(): void
88
    {
89
        $this->get('/download/00000000000000000000000000000000');
90
        $actualImage = $this->response->getContent();
91
        $expectedImage = \file_get_contents(base_path('tests/images/steve_raw.png'));
92
93
        $this->assertEquals($expectedImage, $actualImage);
94
    }
95
96
    /**
97
     * @test
98
     */
99
    public function shouldGenerateIsometricAvatar(): void
100
    {
101
        $this->get('/head/d59dcabb30424b978f7201d1a076637f');
102
        $this->assertResponseOk();
103
        $this->assertEquals(
104
            'image/png',
105
            $this->response->headers->get('Content-Type')
106
        );
107
    }
108
109
    /**
110
     * @test
111
     */
112
    public function shouldGenerateAvatarUsingDifferentUuidFormat(): void
113
    {
114
        $this->get('/avatar/d59dcabb-3042-4b97-8f72-01d1a076637f');
115
        $this->assertResponseOk();
116
        $this->assertEquals(
117
            'image/png',
118
            $this->response->headers->get('Content-Type')
119
        );
120
    }
121
122
    /**
123
     * @test
124
     */
125
    public function shouldFailUpdatingUnExistingUser(): void
126
    {
127
        $this->get('/update/d59dcabb30424b978f7201ffffffffff');
128
129
        $expectedStatusCode = 404;
130
        $expectedContentType = 'application/json';
131
        $this->assertEquals($expectedContentType, $this->response->headers->get('Content-Type'));
132
        $this->assertEquals($expectedStatusCode, $this->response->getStatusCode());
133
    }
134
}
135