Completed
Push — symfony3-wololo-packages ( fecf70...6bf04d )
by Kamil
28:46 queued 11:35
created

CurrencyApiTest::testFullUpdateCurrencyResponse()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
rs 8.9713
cc 1
eloc 13
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 Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @author Axel Vankrunkelsven <[email protected]>
19
 */
20
class CurrencyApiTest extends JsonApiTestCase
21
{
22
    /**
23
     * @var array
24
     */
25
    private static $authorizedHeader = [
26
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
27
    ];
28
29
    /**
30
     * @var array
31
     */
32
    private static $authorizedHeaderWithContentType = [
33
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
34
        'CONTENT_TYPE' => 'application/json',
35
    ];
36
37
    /**
38
     * @var array
39
     */
40
    private static $authorizedHeaderWithAccept = [
41
        'HTTP_Authorization' => 'Bearer SampleTokenNjZkNjY2MDEwMTAzMDkxMGE0OTlhYzU3NzYyMTE0ZGQ3ODcyMDAwM2EwMDZjNDI5NDlhMDdlMQ',
42
        'ACCEPT' => 'application/json',
43
    ];
44
45
    public function testCreateCurrencyAccessDeniedResponse()
46
    {
47
        $this->client->request('POST', '/api/currencies/');
48
49
        $response = $this->client->getResponse();
50
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
51
    }
52
53
    public function testCreateCurrencyValidationFailResponse()
54
    {
55
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
56
57
        $this->client->request('POST', '/api/currencies/', [], [], 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...
58
59
        $response = $this->client->getResponse();
60
        $this->assertResponse($response, 'currency/create_validation_fail_response', Response::HTTP_BAD_REQUEST);
61
    }
62
63
    public function testCreateCurrencyResponse()
64
    {
65
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
66
67
        $data =
68
<<<EOT
69
        {
70
            "code": "USD"
71
        }
72
EOT;
73
74
        $this->client->request('POST', '/api/currencies/', [], [], 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...
75
76
        $response = $this->client->getResponse();
77
78
        $this->assertResponse($response, 'currency/create_response', Response::HTTP_CREATED);
79
    }
80
81
    public function testGetCurrenciesListAccessDeniedResponse()
82
    {
83
        $this->client->request('GET', '/api/currencies/');
84
85
        $response = $this->client->getResponse();
86
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
87
    }
88
89
    public function testGetCurrenciesListResponse()
90
    {
91
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
92
        $this->loadFixturesFromFile('resources/currencies.yml');
93
94
        $this->client->request('GET', '/api/currencies/', [], [], static::$authorizedHeader);
0 ignored issues
show
Bug introduced by
Since $authorizedHeader is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $authorizedHeader 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...
95
96
        $response = $this->client->getResponse();
97
        $this->assertResponse($response, 'currency/index_response', Response::HTTP_OK);
98
    }
99
100
    public function testGetCurrencyAccessDeniedResponse()
101
    {
102
        $this->client->request('GET', '/api/currencies/1');
103
104
        $response = $this->client->getResponse();
105
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
106
    }
107
108
    public function testGetCurrencyWhichDoesNotExistResponse()
109
    {
110
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
111
112
        $this->client->request('GET', '/api/currencies/-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...
113
114
        $response = $this->client->getResponse();
115
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
116
    }
117
118
    public function testGetCurrencyResponse()
119
    {
120
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
121
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
122
123
        $this->client->request('GET', '/api/currencies/'.$currencies['currency_1']->getCode(), [], [], 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...
124
125
        $response = $this->client->getResponse();
126
        $this->assertResponse($response, 'currency/show_response', Response::HTTP_OK);
127
    }
128
129
    public function testDeleteCurrencyWhichDoesNotExistResponse()
130
    {
131
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
132
133
        $this->client->request('DELETE', '/api/currencies/-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...
134
135
        $response = $this->client->getResponse();
136
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
137
    }
138
139
    public function testDeleteCurrencyResponse()
140
    {
141
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
142
        $currencies = $this->loadFixturesFromFile('resources/currencies.yml');
143
144
        $this->client->request('DELETE', '/api/currencies/'.$currencies['currency_1']->getCode(), [], [], 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...
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...
145
146
        $response = $this->client->getResponse();
147
        $this->assertResponseCode($response, Response::HTTP_NO_CONTENT);
148
149
        $this->client->request('GET', '/api/currencies/'.$currencies['currency_1']->getCode(), [], [], 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...
150
151
        $response = $this->client->getResponse();
152
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
153
    }
154
}
155