Completed
Pull Request — master (#285)
by
unknown
02:58
created

LoggedInCustomerDetailsActionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 85.71 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 60
loc 70
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A it_shows_currently_logged_in_customer_details() 30 30 1
A it_shows_currently_logged_in_customer_addresses() 30 30 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Sylius\ShopApiPlugin\Controller\Customer;
6
7
use Sylius\Component\Channel\Context\ChannelContextInterface;
8
use Tests\Sylius\ShopApiPlugin\Controller\TestCase\JsonApiTestCase;
9
use Symfony\Component\HttpFoundation\Response;
10
11
final class LoggedInCustomerDetailsActionTest extends JsonApiTestCase
12
{
13
    /**
14
     * @test
15
     */
16 View Code Duplication
    public function it_shows_currently_logged_in_customer_details()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
17
    {
18
        $this->loadFixturesFromFile('customer.yml');
19
        $this->loadFixturesFromFile('channel.yml');
20
21
        $fakeChannelContext = $this->createMock(ChannelContextInterface::class);
22
        $fakeChannelContext->method('getChannel')->willReturn($this->get('sylius.repository.channel')->findOneByCode('WEB_GB'));
23
        $this->client->getContainer()->set('sylius.context.channel', $fakeChannelContext);
24
25
        $data =
26
<<<EOT
27
        {
28
            "_username": "[email protected]",
29
            "_password": "123pa\$\$word"
30
        }
31
EOT;
32
33
        $this->client->request('POST', '/shop-api/login_check', [], [], ['CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json'], $data);
34
35
        $response = json_decode($this->client->getResponse()->getContent(), true);
36
        $this->client->setServerParameter('HTTP_Authorization', sprintf('Bearer %s', $response['token']));
37
38
        $this->client->request('GET', '/shop-api/me', [], [], [
39
            'CONTENT_TYPE' => 'application/json',
40
            'ACCEPT' => 'application/json',
41
        ]);
42
43
        $response = $this->client->getResponse();
44
        $this->assertResponse($response, 'customer/logged_in_customer_details_response', Response::HTTP_OK);
45
    }
46
47
    /**
48
     * @test
49
     */
50 View Code Duplication
    public function it_shows_currently_logged_in_customer_addresses()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
51
    {
52
        $this->loadFixturesFromFile('customer.yml');
53
        $this->loadFixturesFromFile('channel.yml');
54
55
        $fakeChannelContext = $this->createMock(ChannelContextInterface::class);
56
        $fakeChannelContext->method('getChannel')->willReturn($this->get('sylius.repository.channel')->findOneByCode('WEB_GB'));
57
        $this->client->getContainer()->set('sylius.context.channel', $fakeChannelContext);
58
59
        $data =
60
            <<<EOT
61
        {
62
            "_username": "[email protected]",
63
            "_password": "123pa\$\$word"
64
        }
65
EOT;
66
67
        $this->client->request('POST', '/shop-api/login_check', [], [], ['CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json'], $data);
68
69
        $response = json_decode($this->client->getResponse()->getContent(), true);
70
        $this->client->setServerParameter('HTTP_Authorization', sprintf('Bearer %s', $response['token']));
71
72
        $this->client->request('GET', '/shop-api/me/address', [], [], [
73
            'CONTENT_TYPE' => 'application/json',
74
            'ACCEPT' => 'application/json',
75
        ]);
76
77
        $response = $this->client->getResponse();
78
        $this->assertResponse($response, 'customer/logged_in_customer_addresses', Response::HTTP_OK);
79
    }
80
}
81