Completed
Push — pull-request/7609 ( 4ccf63...393b85 )
by Kamil
146:59 queued 125:08
created

PromotionApiTest::it_allows_to_delete_promotion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
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\Tests\Controller;
13
14
use Lakion\ApiTestCase\JsonApiTestCase;
15
use Sylius\Component\Promotion\Model\PromotionInterface;
16
use Symfony\Component\HttpFoundation\Response;
17
18
/**
19
 * @author Anna Walasek <[email protected]>
20
 */
21
final class PromotionApiTest 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
    /**
40
     * @test
41
     */
42
    public function it_does_not_allow_to_show_promotions_list_when_access_is_denied()
43
    {
44
        $this->loadFixturesFromFile('resources/promotions.yml');
45
46
        $this->client->request('GET', '/api/v1/promotions/');
47
48
        $response = $this->client->getResponse();
49
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function it_allows_indexing_promotions()
56
    {
57
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
58
        $this->loadFixturesFromFile('resources/promotions.yml');
59
60
        $this->client->request('GET', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
61
62
        $response = $this->client->getResponse();
63
        $this->assertResponse($response, 'promotion/index_response', Response::HTTP_OK);
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_allows_sorting_the_index_of_promotions_by_code()
70
    {
71
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
72
        $this->loadFixturesFromFile('resources/promotions.yml');
73
        $this->loadFixturesFromFile('resources/many_promotions.yml');
74
75
        $this->client->request('GET', '/api/v1/promotions/', ['sorting' => ['code' => 'asc']], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
76
77
        $response = $this->client->getResponse();
78
        $this->assertResponse($response, 'promotion/sorted_by_code_index_response');
79
    }
80
81
    /**
82
     * @test
83
     */
84
    public function it_allows_sorting_the_index_of_promotions_by_name()
85
    {
86
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
87
        $this->loadFixturesFromFile('resources/promotions.yml');
88
        $this->loadFixturesFromFile('resources/many_promotions.yml');
89
90
        $this->client->request('GET', '/api/v1/promotions/', ['sorting' => ['name' => 'desc']], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
91
92
        $response = $this->client->getResponse();
93
        $this->assertResponse($response, 'promotion/sorted_by_name_index_response');
94
    }
95
96
    /**
97
     * @test
98
     */
99
    public function it_allows_sorting_the_index_of_promotions_by_priority()
100
    {
101
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
102
        $this->loadFixturesFromFile('resources/promotions.yml');
103
        $this->loadFixturesFromFile('resources/many_promotions.yml');
104
105
        $this->client->request('GET', '/api/v1/promotions/', ['sorting' => ['priority' => 'asc']], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
106
107
        $response = $this->client->getResponse();
108
        $this->assertResponse($response, 'promotion/sorted_by_priority_index_response');
109
    }
110
111
    /**
112
     * @test
113
     */
114
    public function it_allows_to_get_promotions_list_filtered_by_name_and_code()
115
    {
116
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
117
        $this->loadFixturesFromFile('resources/promotions.yml');
118
        $this->loadFixturesFromFile('resources/many_promotions.yml');
119
120
        $this->client->request('GET', '/api/v1/promotions/', ['criteria' => ['search' => 'promo']], [], [
121
            'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
122
        ]);
123
124
        $response = $this->client->getResponse();
125
        $this->assertResponse($response, 'promotion/filtered_by_code_and_name_index_response', Response::HTTP_OK);
126
    }
127
128
    /**
129
     * @test
130
     */
131
    public function it_allows_to_get_list_of_coupon_based_promotions()
132
    {
133
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
134
        $this->loadFixturesFromFile('resources/promotions.yml');
135
        $this->loadFixturesFromFile('resources/many_promotions.yml');
136
137
        $this->client->request('GET', '/api/v1/promotions/', ['criteria' => ['couponBased' => 'true']], [], [
138
            'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
139
        ]);
140
141
        $response = $this->client->getResponse();
142
        $this->assertResponse($response, 'promotion/only_coupon_based_index_response', Response::HTTP_OK);
143
    }
144
145
    /**
146
     * @test
147
     */
148
    public function it_does_not_allow_to_show_promotion_when_it_does_not_exist()
149
    {
150
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
151
152
        $this->client->request('GET', '/api/v1/promotions/-1', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
153
154
        $response = $this->client->getResponse();
155
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
156
    }
157
158
    /**
159
     * @test
160
     */
161
    public function it_allows_showing_promotion()
162
    {
163
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
164
        $promotions = $this->loadFixturesFromFile('resources/promotions.yml');
165
        $promotion = $promotions['promotion2'];
166
167
        $this->client->request('GET', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
168
169
        $response = $this->client->getResponse();
170
        $this->assertResponse($response, 'promotion/show_response', Response::HTTP_OK);
171
    }
172
173
    /**
174
     * @test
175
     */
176
    public function it_does_not_allow_to_delete_promotion_if_it_does_not_exist()
177
    {
178
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
179
180
        $this->client->request('DELETE', '/api/v1/promotions/-1', [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
181
182
        $response = $this->client->getResponse();
183
184
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
185
    }
186
187
    /**
188
     * @test
189
     */
190
    public function it_allows_to_delete_promotion()
191
    {
192
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
193
        $promotions = $this->loadFixturesFromFile('resources/promotions.yml');
194
        $promotion = $promotions['promotion1'];
195
196
        $this->client->request('DELETE', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithContentType, []);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
Documentation introduced by
array() is of type array, but the function expects a string|null.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
197
198
        $response = $this->client->getResponse();
199
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
200
201
        $this->client->request('GET', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
202
203
        $response = $this->client->getResponse();
204
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
205
    }
206
207
    /**
208
     * @test
209
     */
210
    public function it_does_not_allow_to_create_promotion_without_required_fields()
211
    {
212
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
213
214
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, []);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
Documentation introduced by
array() is of type array, but the function expects a string|null.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
215
216
        $response = $this->client->getResponse();
217
        $this->assertResponse($response, 'promotion/create_validation_fail_response', Response::HTTP_BAD_REQUEST);
218
    }
219
220
    /**
221
     * @test
222
     */
223
    public function it_allows_to_create_promotion()
224
    {
225
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
226
227
        $data =
228
<<<EOT
229
        {
230
            "code": "christmas-promotion",
231
            "name": "Christmas Promotion"
232
        }
233
EOT;
234
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
235
236
        $response = $this->client->getResponse();
237
        $this->assertResponse($response, 'promotion/create_response', Response::HTTP_CREATED);
238
    }
239
240
    /**
241
     * @test
242
     */
243
    public function it_allows_to_create_promotion_with_channels()
244
    {
245
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
246
        $this->loadFixturesFromFile('resources/channels.yml');
247
248
        $data =
249
<<<EOT
250
        {
251
            "code": "christmas-promotion",
252
            "name": "Christmas Promotion",
253
            "channels": [
254
                "WEB",
255
                "MOB"
256
            ]
257
        }
258
EOT;
259
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
260
261
        $response = $this->client->getResponse();
262
        $this->assertResponse($response, 'promotion/create_response_with_channels', Response::HTTP_CREATED);
263
    }
264
265
    /**
266
     * @test
267
     */
268
    public function it_allows_to_create_promotion_with_time_of_duration()
269
    {
270
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
271
272
        $data =
273
<<<EOT
274
        {
275
            "code": "christmas-promotion",
276
            "name": "Christmas Promotion",
277
            "startsAt": {
278
                "date": "2017-12-05",
279
                "time": "11:00"
280
            },
281
            "endsAt": {
282
                "date": "2017-12-31",
283
                "time": "11:00"
284
            }
285
        }
286
EOT;
287
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
288
289
        $response = $this->client->getResponse();
290
        $this->assertResponse($response, 'promotion/create_response_with_time_of_duration', Response::HTTP_CREATED);
291
    }
292
293
    /**
294
     * @test
295
     */
296
    public function it_allows_to_create_promotion_with_rules()
297
    {
298
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
299
        $this->loadFixturesFromFile('resources/channels.yml');
300
301
        $data =
302
<<<EOT
303
        {
304
            "code": "christmas-promotion",
305
            "name": "Christmas Promotion",
306
            "rules": [
307
                {
308
                    "type": "nth_order",
309
                    "configuration": {
310
                        "nth": 3
311
                    }
312
                },
313
                {
314
                    "type": "item_total",
315
                    "configuration": {
316
                        "WEB": {
317
                            "amount": 12
318
                        },
319
                        "MOB": {
320
                            "amount": 15
321
                        }
322
                    }
323
                }
324
            ]
325
        }
326
EOT;
327
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
328
329
        $response = $this->client->getResponse();
330
        $this->assertResponse($response, 'promotion/create_response_with_rules', Response::HTTP_CREATED);
331
    }
332
333
    /**
334
     * @test
335
     */
336
    public function it_allows_to_create_promotion_with_actions()
337
    {
338
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
339
        $this->loadFixturesFromFile('resources/channels.yml');
340
        $this->loadFixturesFromFile('resources/products.yml');
341
        $this->loadFixturesFromFile('resources/product_taxons.yml');
342
343
        $data =
344
<<<EOT
345
        {
346
            "code": "christmas-promotion",
347
            "name": "Christmas Promotion",
348
            "actions": [
349
                {
350
                    "type": "unit_percentage_discount",
351
                    "configuration": {
352
                        "WEB": {
353
                            "percentage": 15,
354
                            "filters": {
355
                                "price_range_filter": {
356
                                    "min": 1,
357
                                    "max": 12000
358
                                },
359
                                "taxons_filter": {
360
                                    "taxons": [
361
                                        "mugs"
362
                                    ]
363
                                },
364
                                "products_filter": {
365
                                    "products": [
366
                                        "MUG_SW",
367
                                        "MUG_LOTR"
368
                                    ]
369
                                }
370
                            }
371
                        },
372
                        "MOB": {
373
                            "percentage": 20,
374
                            "filters": {
375
                                "products_filter": {
376
                                    "products": [
377
                                        "MUG_SW"
378
                                    ]
379
                                }
380
                            }
381
                        }
382
                    }
383
                },
384
                {
385
                    "type": "order_fixed_discount",
386
                    "configuration": {
387
                        "WEB": {
388
                            "amount": 12
389
                        },
390
                        "MOB": {
391
                            "amount": 15
392
                        }
393
                    }
394
                }
395
            ]
396
        }
397
EOT;
398
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
399
400
        $response = $this->client->getResponse();
401
        $this->assertResponse($response, 'promotion/create_response_with_actions', Response::HTTP_CREATED);
402
    }
403
404
405
    /**
406
     * @test
407
     */
408
    public function it_allows_to_create_coupon_based_promotion()
409
    {
410
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
411
412
        $data =
413
<<<EOT
414
        {
415
            "code": "christmas-promotion",
416
            "name": "Christmas Promotion",
417
            "couponBased": true
418
        }
419
EOT;
420
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
421
422
        $response = $this->client->getResponse();
423
        $this->assertResponse($response, 'promotion/create_coupon_based_response', Response::HTTP_CREATED);
424
    }
425
426
    /**
427
     * @test
428
     */
429
    public function it_allows_to_create_exclusive_promotion()
430
    {
431
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
432
433
        $data =
434
<<<EOT
435
        {
436
            "code": "christmas-promotion",
437
            "name": "Christmas Promotion",
438
            "exclusive": true,
439
            "priority": 0
440
        }
441
EOT;
442
        $this->client->request('POST', '/api/v1/promotions/', [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
443
444
        $response = $this->client->getResponse();
445
        $this->assertResponse($response, 'promotion/create_exclusive_response', Response::HTTP_CREATED);
446
    }
447
448
    /**
449
     * @test
450
     */
451
    public function it_allows_updating_promotion()
452
    {
453
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
454
        $promotions = $this->loadFixturesFromFile('resources/promotions.yml');
455
        $promotion = $promotions["promotion1"];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal promotion1 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
456
457
        $data =
458
<<<EOT
459
        {
460
            "name": "Monday promotion"
461
        }
462
EOT;
463
        $this->client->request('PUT', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
464
        $response = $this->client->getResponse();
465
466
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
467
468
        $this->client->request('GET', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
469
470
        $response = $this->client->getResponse();
471
        $this->assertResponse($response, 'promotion/show_response_after_update', Response::HTTP_OK);
472
    }
473
474
    /**
475
     * @test
476
     */
477
    public function it_allows_updating_partial_information_about_promotion()
478
    {
479
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
480
        $promotions = $this->loadFixturesFromFile('resources/promotions.yml');
481
        $promotion = $promotions["promotion1"];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal promotion1 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
482
483
        $data =
484
<<<EOT
485
        {
486
            "exclusive": true,
487
            "priority": 0
488
        }
489
EOT;
490
        $this->client->request('PATCH', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithContentType, $data);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
491
        $response = $this->client->getResponse();
492
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
493
494
        $this->client->request('GET', $this->getPromotionUrl($promotion), [], [], static::$authorizedHeaderWithAccept);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PromotionApiTest is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
495
496
        $response = $this->client->getResponse();
497
        $this->assertResponse($response, 'promotion/show_response_after_partial_update', Response::HTTP_OK);
498
    }
499
500
    /**
501
     * @param PromotionInterface $promotion
502
     *
503
     * @return string
504
     */
505
    private function getPromotionUrl(PromotionInterface $promotion)
506
    {
507
        return '/api/v1/promotions/' . $promotion->getCode();
508
    }
509
}
510