|
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 Jeroen Thora <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class ProvinceApiTest extends JsonApiTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private static $authorizedHeaderWithContentType = [ |
|
26
|
|
|
'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ', |
|
27
|
|
|
'CONTENT_TYPE' => 'application/json', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public function testGetProvinceAccessDeniedResponse() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->client->request('GET', '/api/countries/1/provinces/1'); |
|
33
|
|
|
|
|
34
|
|
|
$response = $this->client->getResponse(); |
|
35
|
|
|
$this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetProvinceResponse() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
|
41
|
|
|
$countryData = $this->loadFixturesFromFile('resources/countries.yml'); |
|
42
|
|
|
|
|
43
|
|
|
$this->client->request('GET', '/api/countries/'.$countryData['country_BE']->getId().'/provinces/'.$countryData['province_BE_limburg']->getId(), [], [], static::$authorizedHeaderWithContentType); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$response = $this->client->getResponse(); |
|
46
|
|
|
$this->assertResponse($response, 'province/show_response', Response::HTTP_OK); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testDeleteProvinceResponse() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->loadFixturesFromFile('authentication/api_administrator.yml'); |
|
52
|
|
|
$countryData = $this->loadFixturesFromFile('resources/countries.yml'); |
|
53
|
|
|
|
|
54
|
|
|
$this->client->request('DELETE', '/api/countries/'.$countryData['country_BE']->getId().'/provinces/'.$countryData['province_BE_limburg']->getId(), [], [], static::$authorizedHeaderWithContentType); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$response = $this->client->getResponse(); |
|
57
|
|
|
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT); |
|
58
|
|
|
|
|
59
|
|
|
$this->client->request('GET', '/api/countries/'.$countryData['country_BE']->getId().'/provinces/'.$countryData['province_BE_limburg']->getId(), [], [], static::$authorizedHeaderWithContentType); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$response = $this->client->getResponse(); |
|
62
|
|
|
$this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Let’s assume you have a class which uses late-static binding:
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:In the case above, it makes sense to update
SomeClassto useselfinstead: