Completed
Push — checkout-optimisation ( 40d0de )
by Kamil
21:30
created

PaymentMethodApiTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 61
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_denies_getting_payment_method_for_non_authenticated_user() 0 7 1
A it_does_not_allow_to_show_payment_method_when_it_does_not_exist() 0 9 1
A it_allows_showing_payment_method() 0 13 1
A getPaymentMethodUrl() 0 4 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\Tests\Controller;
13
14
use Lakion\ApiTestCase\JsonApiTestCase;
15
use Sylius\Component\Payment\Model\PaymentMethodInterface;
16
use Symfony\Component\HttpFoundation\Response;
17
18
/**
19
 * @author Anna Walasek <[email protected]>
20
 */
21
final class PaymentMethodApiTest 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
     * @test
33
     */
34
    public function it_denies_getting_payment_method_for_non_authenticated_user()
35
    {
36
        $this->client->request('GET', '/api/v1/payment-methods/none');
37
38
        $response = $this->client->getResponse();
39
        $this->assertResponse($response, 'authentication/access_denied_response', Response::HTTP_UNAUTHORIZED);
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function it_does_not_allow_to_show_payment_method_when_it_does_not_exist()
46
    {
47
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
48
49
        $this->client->request('GET', '/api/v1/payment-methods/none', [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PaymentMethodApiTest 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...
50
51
        $response = $this->client->getResponse();
52
        $this->assertResponse($response, 'error/not_found_response', Response::HTTP_NOT_FOUND);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function it_allows_showing_payment_method()
59
    {
60
        $this->loadFixturesFromFile('authentication/api_administrator.yml');
61
        $this->loadFixturesFromFile('resources/channels.yml');
62
        $paymentMethods = $this->loadFixturesFromFile('resources/payment_methods.yml');
63
        /** @var PaymentMethodInterface $paymentMethod */
64
        $paymentMethod = $paymentMethods['cash_on_delivery'];
65
66
        $this->client->request('GET', $this->getPaymentMethodUrl($paymentMethod), [], [], static::$authorizedHeaderWithContentType);
0 ignored issues
show
Comprehensibility introduced by
Since Sylius\Tests\Controller\PaymentMethodApiTest 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...
67
68
        $response = $this->client->getResponse();
69
        $this->assertResponse($response, 'payment_method/show_response', Response::HTTP_OK);
70
    }
71
72
    /**
73
     * @param PaymentMethodInterface $paymentMethod
74
     *
75
     * @return string
76
     */
77
    private function getPaymentMethodUrl(PaymentMethodInterface $paymentMethod)
78
    {
79
        return '/api/v1/payment-methods/' . $paymentMethod->getCode();
80
    }
81
}
82