-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindPointsTest.php
More file actions
198 lines (169 loc) · 8.95 KB
/
Copy pathFindPointsTest.php
File metadata and controls
198 lines (169 loc) · 8.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
declare(strict_types=1);
namespace Answear\InpostBundle\Tests\Integration\Command;
use Answear\InpostBundle\Client\Client;
use Answear\InpostBundle\Command\FindPoints;
use Answear\InpostBundle\ConfigProvider;
use Answear\InpostBundle\Enum\PointFunctionsType;
use Answear\InpostBundle\Enum\PointType;
use Answear\InpostBundle\Request\FindPointsRequest;
use Answear\InpostBundle\Response\Struct\Item;
use Answear\InpostBundle\Response\Struct\ItemAddress;
use Answear\InpostBundle\Response\Struct\ItemAddressDetails;
use Answear\InpostBundle\Response\Struct\ItemLocation;
use Answear\InpostBundle\Response\Struct\ItemOperatingHours;
use Answear\InpostBundle\Response\Struct\ItemOperatingHoursDay;
use Answear\InpostBundle\Tests\MockGuzzleTrait;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
class FindPointsTest extends TestCase
{
use MockGuzzleTrait;
private Client $client;
private const POLAND = 'Poland';
private const ITALY = 'Italy';
public function setUp(): void
{
parent::setUp();
$configProvider = new ConfigProvider();
$this->client = new Client($configProvider, $this->setupGuzzleClient());
}
/**
* @test
*/
public function successfulFindPointsPoland(): void
{
$this->mockGuzzleResponse(new Response(200, [], $this->getSuccessfulBody(self::POLAND)));
$response = $this->getCommand()->findPoints(new FindPointsRequest());
$this->assertCount(1, $response->getItems());
$this->assertSame(1, $response->getTotalItemsCount());
/** @var Item $point */
$point = $response->getItems()->get(0);
$this->assertNotNull($point);
$this->assertSame($point->id, 'ADA01M');
$this->assertSame($point->name, 'ADA01M');
$this->assertSame($point->type, [PointType::ParcelLocker]);
$this->assertSame($point->status, 'Operating');
$this->assertInstanceOf(ItemLocation::class, $point->location);
$this->assertSame($point->location->longitude, 22.264049625);
$this->assertSame($point->location->latitude, 51.73834066);
$this->assertSame($point->locationType, 'Outdoor');
$this->assertSame($point->locationDescription, 'Przy sklepie Lewiatan');
$this->assertNull($point->locationDescription1);
$this->assertNull($point->locationDescription2);
$this->assertNull($point->distance);
$this->assertSame($point->openingHours, '24/7');
$this->assertInstanceOf(ItemOperatingHours::class, $point->operatingHoursExtended);
$this->assertInstanceOf(ItemAddress::class, $point->address);
$this->assertSame($point->address->line1, 'Kościuszki 27');
$this->assertSame($point->address->line2, '21-412 Adamów');
$this->assertInstanceOf(ItemAddressDetails::class, $point->addressDetails);
$this->assertSame($point->addressDetails->city, 'Adamów');
$this->assertSame($point->addressDetails->province, 'lubelskie');
$this->assertSame($point->addressDetails->postCode, '21-412');
$this->assertSame($point->addressDetails->street, 'Kościuszki');
$this->assertSame($point->addressDetails->buildingNumber, '27');
$this->assertNull($point->addressDetails->flatNumber);
$this->assertNull($point->phoneNumber);
$this->assertSame($point->paymentPointDescr, 'Płatność internetowa PayByLink oraz Blik');
$this->assertSame($point->functions, [PointFunctionsType::ParcelCollect, PointFunctionsType::ParcelSend]);
$this->assertSame($point->partnerId, 0);
$this->assertFalse($point->isNext);
$this->assertTrue($point->paymentAvailable);
$this->assertSame($point->paymentType, ['0' => 'Payments are not supported']);
$this->assertSame($point->virtual, '0');
$this->assertNull($point->recommendedLowInterestBoxMachinesList);
$this->assertTrue($point->location247);
}
/**
* @test
*/
public function findPointsSendsGetRequestWithoutBody(): void
{
$this->mockGuzzleResponse(new Response(200, [], $this->getSuccessfulBody(self::POLAND)));
$this->getCommand()->findPoints(new FindPointsRequest());
$this->assertCount(1, $this->clientHistory);
$request = $this->clientHistory[0]['request'];
$this->assertSame('GET', $request->getMethod());
$this->assertSame('', (string) $request->getBody());
$this->assertSame(['application/json'], $request->getHeader('Content-Type'));
}
/**
* @test
*/
public function successfulFindPointsItaly(): void
{
$this->mockGuzzleResponse(new Response(200, [], $this->getSuccessfulBody(self::ITALY)));
$response = $this->getCommand()->findPoints(new FindPointsRequest());
$this->assertCount(1, $response->getItems());
$this->assertSame(1, $response->getTotalItemsCount());
/** @var Item $point */
$point = $response->getItems()->get(0);
$this->assertNotNull($point);
$this->assertSame($point->id, 'ITAAQ01570P');
$this->assertSame($point->name, 'ITAAQ01570P');
$this->assertSame($point->type, [PointType::Pok, PointType::Pop]);
$this->assertSame($point->status, 'Operating');
$this->assertInstanceOf(ItemLocation::class, $point->location);
$this->assertSame($point->location->longitude, 13.47289);
$this->assertSame($point->location->latitude, 42.35751);
$this->assertSame($point->locationType, 'Indoor');
$this->assertSame($point->locationDescription, 'presso Dottor Tech');
$this->assertNull($point->locationDescription1);
$this->assertNull($point->locationDescription2);
$this->assertNull($point->distance);
$this->assertSame($point->openingHours, 'Lun-Ven: 10:00 - 13:00 - 16:00 - 19:00 ');
$this->assertInstanceOf(ItemOperatingHours::class, $point->operatingHoursExtended);
$this->assertIsArray($point->operatingHoursExtended->sunday);
$this->assertIsArray($point->operatingHoursExtended->monday);
$this->assertContainsOnlyInstancesOf(ItemOperatingHoursDay::class, $point->operatingHoursExtended->sunday);
$this->assertContainsOnlyInstancesOf(ItemOperatingHoursDay::class, $point->operatingHoursExtended->monday);
$this->assertEmpty($point->operatingHoursExtended->sunday);
$this->assertSame($point->operatingHoursExtended->monday[0]->start, 600);
$this->assertSame($point->operatingHoursExtended->monday[0]->end, 780);
$this->assertSame($point->operatingHoursExtended->monday[1]->start, 960);
$this->assertSame($point->operatingHoursExtended->monday[1]->end, 1140);
$this->assertSame($point->operatingHoursExtended->monday[0]->startParsed, '10:00');
$this->assertSame($point->operatingHoursExtended->monday[0]->endParsed, '13:00');
$this->assertSame($point->operatingHoursExtended->monday[1]->startParsed, '16:00');
$this->assertSame($point->operatingHoursExtended->monday[1]->endParsed, '19:00');
$this->assertInstanceOf(ItemAddress::class, $point->address);
$this->assertSame($point->address->line1, 'Via Ten. Antonio Rossi Tascione in Str. Vicinale di Paganica 7');
$this->assertSame($point->address->line2, '67100 L\'Aquila');
$this->assertInstanceOf(ItemAddressDetails::class, $point->addressDetails);
$this->assertSame($point->addressDetails->city, 'L\'Aquila');
$this->assertSame($point->addressDetails->province, 'AQ');
$this->assertSame($point->addressDetails->postCode, '67100');
$this->assertSame($point->addressDetails->street, 'Via Ten. Antonio Rossi Tascione in Str. Vicinale di Paganica');
$this->assertSame($point->addressDetails->buildingNumber, '7');
$this->assertNull($point->addressDetails->flatNumber);
$this->assertNull($point->phoneNumber);
$this->assertSame($point->paymentPointDescr, '');
$this->assertSame($point->functions, [
PointFunctionsType::Parcel,
PointFunctionsType::ParcelCollect,
PointFunctionsType::ParcelReverseReturnSend,
PointFunctionsType::ParcelSend,
PointFunctionsType::StandardCourierSend,
]);
$this->assertSame($point->partnerId, 1);
$this->assertFalse($point->isNext);
$this->assertTrue($point->paymentAvailable);
$this->assertSame($point->paymentType, ['3' => 'Payment by cash and card']);
$this->assertSame($point->virtual, '3');
$this->assertNull($point->recommendedLowInterestBoxMachinesList);
$this->assertFalse($point->location247);
}
private function getCommand(): FindPoints
{
return new FindPoints($this->client);
}
private function getSuccessfulBody(string $country): string
{
$response = file_get_contents(__DIR__ . sprintf('/data/exampleResponse_%s.json', $country));
if (false === $response) {
throw new \RuntimeException('Cannot read example response file');
}
return $response;
}
}