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

LocaleApiTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testLocaleAccessDeniedResponse() 0 7 1
A testGetLocalesListResponse() 0 12 1
A testGetLocaleResponse() 0 10 1
A testCreateLocaleValidationFailResponse() 0 9 1
A testCreateLocaleResponse() 0 17 1
A testGetLocaleAccessDeniedResponse() 0 7 1
A testGetLocaleWhichDoesNotExistResponse() 0 9 1
A testDeleteLocaleWhichDoesNotExistResponse() 0 9 1
A testDeleteLocaleResponse() 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 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);
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...
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);
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...
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
        }
90
EOT;
91
92
        $this->client->request('POST', '/api/locales/', [], [], 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...
93
94
        $response = $this->client->getResponse();
95
96
        $this->assertResponse($response, 'locale/create_response', Response::HTTP_CREATED);
97
    }
98
99
    public function testGetLocaleAccessDeniedResponse()
100
    {
101
        $this->client->request('GET', '/api/locales/1');
102
103
        $response = $this->client->getResponse();
104
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
105
    }
106
107
    public function testGetLocaleWhichDoesNotExistResponse()
108
    {
109
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
110
111
        $this->client->request('GET', '/api/locales/-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...
112
113
        $response = $this->client->getResponse();
114
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
115
    }
116
    
117
    public function testDeleteLocaleWhichDoesNotExistResponse()
118
    {
119
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
120
121
        $this->client->request('DELETE', '/api/locales/-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...
122
123
        $response = $this->client->getResponse();
124
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
125
    }
126
127
    public function testDeleteLocaleResponse()
128
    {
129
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
130
        $locales = $this->loadFixturesFromFile('resources/locales.yml');
131
132
        $this->client->request('DELETE', '/api/locales/'.$locales['locale_en']->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...
133
134
        $response = $this->client->getResponse();
135
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
136
137
        $this->client->request('GET', '/api/locales/'.$locales['locale_en']->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...
138
139
        $response = $this->client->getResponse();
140
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
141
    }
142
}
143