These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Tests\Controller; |
||
13 | |||
14 | use Lakion\ApiTestCase\JsonApiTestCase; |
||
15 | use Symfony\Component\HttpFoundation\Response; |
||
16 | |||
17 | /** |
||
18 | * @author Joeri Timmermans <[email protected]> |
||
19 | * @group joeri |
||
20 | */ |
||
21 | class LocaleApiTest extends JsonApiTestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private static $authorizedHeaderWithContentType = [ |
||
27 | 'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
||
28 | 'CONTENT_TYPE' => 'application/json', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private static $authorizedHeaderWithAccept = [ |
||
35 | 'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
||
36 | 'ACCEPT' => 'application/json', |
||
37 | ]; |
||
38 | |||
39 | public function testLocaleAccessDeniedResponse() |
||
40 | { |
||
41 | $this->client->request('POST', '/api/locales/'); |
||
42 | |||
43 | $response = $this->client->getResponse(); |
||
44 | $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
||
45 | } |
||
46 | |||
47 | public function testGetLocalesListResponse() |
||
48 | { |
||
49 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
50 | $this->loadFixturesFromFile('resources/locales.yml'); |
||
51 | |||
52 | $this->client->request('GET', '/api/locales/', [], [], [ |
||
53 | 'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
||
54 | ]); |
||
55 | |||
56 | $response = $this->client->getResponse(); |
||
57 | $this->assertResponse($response, 'locale/index_response', Response::HTTP_OK); |
||
58 | } |
||
59 | |||
60 | public function testGetLocaleResponse() |
||
61 | { |
||
62 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
63 | $locales = $this->loadFixturesFromFile('resources/locales.yml'); |
||
64 | |||
65 | $this->client->request('GET', '/api/locales/'.$locales['locale_en']->getId(), [], [], static::$authorizedHeaderWithAccept); |
||
66 | |||
67 | $response = $this->client->getResponse(); |
||
68 | $this->assertResponse($response, 'locale/show_response', Response::HTTP_OK); |
||
69 | } |
||
70 | |||
71 | public function testCreateLocaleValidationFailResponse() |
||
72 | { |
||
73 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
74 | |||
75 | $this->client->request('POST', '/api/locales/', [], [], static::$authorizedHeaderWithContentType); |
||
76 | |||
77 | $response = $this->client->getResponse(); |
||
78 | $this->assertResponse($response, 'locale/create_validation_fail_response', Response::HTTP_BAD_REQUEST); |
||
79 | } |
||
80 | |||
81 | public function testCreateLocaleResponse() |
||
82 | { |
||
83 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
84 | |||
85 | $data = |
||
86 | <<<EOT |
||
87 | { |
||
88 | "code": "es", |
||
89 | "enabled": true |
||
90 | } |
||
91 | EOT; |
||
92 | |||
93 | $this->client->request('POST', '/api/locales/', [], [], static::$authorizedHeaderWithContentType, $data); |
||
94 | |||
95 | $response = $this->client->getResponse(); |
||
96 | |||
97 | $this->assertResponse($response, 'locale/create_response', Response::HTTP_CREATED); |
||
98 | } |
||
99 | |||
100 | public function testGetLocaleAccessDeniedResponse() |
||
101 | { |
||
102 | $this->client->request('GET', '/api/locales/1'); |
||
103 | |||
104 | $response = $this->client->getResponse(); |
||
105 | $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
||
106 | } |
||
107 | |||
108 | public function testGetLocaleWhichDoesNotExistResponse() |
||
109 | { |
||
110 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
111 | |||
112 | $this->client->request('GET', '/api/locales/-1', [], [], static::$authorizedHeaderWithAccept); |
||
113 | |||
114 | $response = $this->client->getResponse(); |
||
115 | $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
||
116 | } |
||
117 | |||
118 | public function testDeleteLocaleWhichDoesNotExistResponse() |
||
119 | { |
||
120 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
121 | |||
122 | $this->client->request('DELETE', '/api/locales/-1', [], [], static::$authorizedHeaderWithAccept); |
||
123 | |||
124 | $response = $this->client->getResponse(); |
||
125 | $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
||
126 | } |
||
127 | |||
128 | public function testDeleteLocaleResponse() |
||
129 | { |
||
130 | $this->loadFixturesFromFile('authentication/api_administrator.yml'); |
||
131 | $locales = $this->loadFixturesFromFile('resources/locales.yml'); |
||
132 | |||
133 | $this->client->request('DELETE', '/api/locales/'.$locales['locale_en']->getId(), [], [], static::$authorizedHeaderWithContentType, []); |
||
0 ignored issues
–
show
|
|||
134 | |||
135 | $response = $this->client->getResponse(); |
||
136 | $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); |
||
137 | |||
138 | $this->client->request('GET', '/api/locales/'.$locales['locale_en']->getId(), [], [], static::$authorizedHeaderWithAccept); |
||
139 | |||
140 | $response = $this->client->getResponse(); |
||
141 | $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
||
142 | } |
||
143 | } |
||
144 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: