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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.