Completed
Push — master ( 133b57...4c004c )
by Kamil
20:32
created

ProvinceApiTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetProvinceAccessDeniedResponse() 0 7 1
A testGetProvinceResponse() 0 10 1
A testDeleteProvinceResponse() 0 15 1
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);
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...
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);
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...
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);
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...
60
61
        $response = $this->client->getResponse();
62
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
63
    }
64
}
65