Completed
Push — master ( b70f30...259e2d )
by Kamil
32:06
created

testFullUpdateCurrencyValidationFailResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Tests\Controller;
13
14
use Lakion\ApiTestCase\JsonApiTestCase;
15
use Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @author Axel Vankrunkelsven <[email protected]>
19
 */
20
class CurrencyApiTest extends JsonApiTestCase
21
{
22
    /**
23
     * @var array
24
     */
25
    private static $authorizedHeader = [
26
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
27
    ];
28
29
    /**
30
     * @var array
31
     */
32
    private static $authorizedHeaderWithContentType = [
33
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
34
        'CONTENT_TYPE' => 'application/json',
35
    ];
36
37
    /**
38
     * @var array
39
     */
40
    private static $authorizedHeaderWithAccept = [
41
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
42
        'ACCEPT' => 'application/json',
43
    ];
44
45
    public function testCreateCurrencyAccessDeniedResponse()
46
    {
47
        $this->client->request('POST', '/api/currencies/');
48
49
        $response = $this->client->getResponse();
50
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
51
    }
52
53
    public function testCreateCurrencyValidationFailResponse()
54
    {
55
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
56
57
        $this->client->request('POST', '/api/currencies/', [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
58
59
        $response = $this->client->getResponse();
60
        $this->assertResponse($response, 'currency/create_validation_fail_response', Response::HTTP_BAD_REQUEST);
61
    }
62
63
    public function testCreateCurrencyResponse()
64
    {
65
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
66
67
        $data =
68
<<<EOT
69
        {
70
            "code": "USD",
71
            "exchangeRate": 1,
72
            "enabled": true
73
        }
74
EOT;
75
76
        $this->client->request('POST', '/api/currencies/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
77
78
        $response = $this->client->getResponse();
79
80
        $this->assertResponse($response, 'currency/create_response', Response::HTTP_CREATED);
81
    }
82
83
    public function testGetCurrenciesListAccessDeniedResponse()
84
    {
85
        $this->client->request('GET', '/api/currencies/');
86
87
        $response = $this->client->getResponse();
88
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
89
    }
90
91
    public function testGetCurrenciesListResponse()
92
    {
93
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
94
        $this->loadFixturesFromFile('resources/currencies.yml');
95
96
        $this->client->request('GET', '/api/currencies/', [], [], static::$authorizedHeader);
0 ignored issues
show
Bug introduced by
Since $authorizedHeader is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeader to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
97
98
        $response = $this->client->getResponse();
99
        $this->assertResponse($response, 'currency/index_response', Response::HTTP_OK);
100
    }
101
102
    public function testGetCurrencyAccessDeniedResponse()
103
    {
104
        $this->client->request('GET', '/api/currencies/1');
105
106
        $response = $this->client->getResponse();
107
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
108
    }
109
110
    public function testGetCurrencyWhichDoesNotExistResponse()
111
    {
112
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
113
114
        $this->client->request('GET', '/api/currencies/-1', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
115
116
        $response = $this->client->getResponse();
117
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
118
    }
119
120
    public function testGetCurrencyResponse()
121
    {
122
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
123
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
124
125
        $this->client->request('GET', '/api/currencies/'.$currencies['currency_1']->getId(), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
126
127
        $response = $this->client->getResponse();
128
        $this->assertResponse($response, 'currency/show_response', Response::HTTP_OK);
129
    }
130
131
    public function testFullUpdateCurrencyAccessDeniedResponse()
132
    {
133
        $this->client->request('PUT', '/api/currencies/1');
134
135
        $response = $this->client->getResponse();
136
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
137
    }
138
139
    public function testFullUpdateCurrencyWhichDoesNotExistResponse()
140
    {
141
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
142
143
        $this->client->request('PUT', '/api/currencies/-1', [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
144
145
        $response = $this->client->getResponse();
146
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
147
    }
148
149
    public function testFullUpdateCurrencyValidationFailResponse()
150
    {
151
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
152
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
153
154
        $this->client->request('PUT', '/api/currencies/'.$currencies['currency_2']->getId(), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
155
156
        $response = $this->client->getResponse();
157
158
        $this->assertResponse($response, 'currency/update_validation_fail_response', Response::HTTP_BAD_REQUEST);
159
    }
160
161
    public function testFullUpdateCurrencyResponse()
162
    {
163
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
164
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
165
166
        $data =
167
<<<EOT
168
        {
169
            "code": "EUR",
170
            "exchangeRate": 1.0000,
171
            "enabled": false
172
        }
173
EOT;
174
175
        $this->client->request('PUT', '/api/currencies/'.$currencies['currency_2']->getId(), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
176
177
        $response = $this->client->getResponse();
178
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
179
180
        $this->client->request('GET', '/api/currencies/'.$currencies['currency_2']->getId(), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
181
182
        $response = $this->client->getResponse();
183
        $this->assertResponse($response, 'currency/update_response', Response::HTTP_OK);
184
    }
185
186
    public function testPartialUpdateCurrencyWhichDoesNotExistResponse()
187
    {
188
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
189
190
        $this->client->request('PATCH', '/api/currencies/-1', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
191
192
        $response = $this->client->getResponse();
193
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
194
    }
195
196
    public function testPartialUpdateCurrencyResponse()
197
    {
198
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
199
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
200
201
        $data =
202
<<<EOT
203
        {
204
            "exchangeRate": 1,
205
            "enabled": false
206
        }
207
EOT;
208
209
        $this->client->request('PATCH', '/api/currencies/'.$currencies['currency_2']->getId(), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
210
211
        $response = $this->client->getResponse();
212
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
213
214
        $this->client->request('GET', '/api/currencies/'.$currencies['currency_2']->getId(), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
215
216
        $response = $this->client->getResponse();
217
        $this->assertResponse($response, 'currency/update_response', Response::HTTP_OK);
218
    }
219
220
    public function testDeleteCurrencyWhichDoesNotExistResponse()
221
    {
222
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
223
224
        $this->client->request('DELETE', '/api/currencies/-1', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
225
226
        $response = $this->client->getResponse();
227
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
228
    }
229
230
    public function testDeleteCurrencyResponse()
231
    {
232
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
233
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
234
235
        $this->client->request('DELETE', '/api/currencies/'.$currencies['currency_1']->getId(), [], [], static::$authorizedHeaderWithContentType, []);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithContentType is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithContentType to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
236
237
        $response = $this->client->getResponse();
238
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
239
240
        $this->client->request('GET', '/api/currencies/'.$currencies['currency_1']->getId(), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Bug introduced by
Since $authorizedHeaderWithAccept is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeaderWithAccept to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
241
242
        $response = $this->client->getResponse();
243
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
244
    }
245
}
246