|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SergeyNezbritskiy\NovaPoshta\Tests\Integration\Models\InternetDocument; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use SergeyNezbritskiy\NovaPoshta\Models\InternetDocument; |
|
9
|
|
|
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException; |
|
10
|
|
|
use SergeyNezbritskiy\NovaPoshta\Tests\AssertEntityByPropertiesTrait; |
|
11
|
|
|
use SergeyNezbritskiy\NovaPoshta\Tests\ConstantsInterface; |
|
12
|
|
|
use SergeyNezbritskiy\NovaPoshta\Tests\UsesConnectionTrait; |
|
13
|
|
|
|
|
14
|
|
|
class CrudTest extends TestCase implements ConstantsInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use AssertEntityByPropertiesTrait; |
|
17
|
|
|
use UsesConnectionTrait; |
|
18
|
|
|
|
|
19
|
|
|
private InternetDocument $model; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
date_default_timezone_set('Europe/Kyiv'); |
|
24
|
|
|
$connection = $this->getConnection(); |
|
25
|
|
|
$this->model = new InternetDocument($connection); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @throws NovaPoshtaApiException |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testCrudDocument(): void |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
// $counterpartyModel = new \SergeyNezbritskiy\NovaPoshta\Models\Counterparty($this->getConnection()); |
|
35
|
|
|
// $addressModel = new \SergeyNezbritskiy\NovaPoshta\Models\Address($this->getConnection()); |
|
36
|
|
|
|
|
37
|
|
|
// $recipient = $counterpartyModel->savePrivatePerson([ |
|
38
|
|
|
// 'FirstName' => 'Петро', |
|
39
|
|
|
// 'MiddleName' => 'Григорович', |
|
40
|
|
|
// 'LastName' => 'Порошенко', |
|
41
|
|
|
// 'Phone' => 380501112233, |
|
42
|
|
|
// 'Email' => '[email protected]', |
|
43
|
|
|
// 'CounterpartyProperty' => Counterparty::COUNTERPARTY_PROPERTY_RECIPIENT, |
|
44
|
|
|
// ]); // 4d21c8c7-b88e-11ed-a60f-48df37b921db |
|
45
|
|
|
$recipientRef = '4d21c8c7-b88e-11ed-a60f-48df37b921db'; |
|
46
|
|
|
|
|
47
|
|
|
// $address = $addressModel->save($recipientRef, [ |
|
48
|
|
|
// 'StreetRef' => self::KHRESHCHATYK_STREET_REF, |
|
49
|
|
|
// 'BuildingNumber' => '20', |
|
50
|
|
|
// 'Flat' => '12', |
|
51
|
|
|
// ]); |
|
52
|
|
|
$addressRef = 'cecaac32-25bb-11ee-a60f-48df37b921db'; |
|
53
|
|
|
|
|
54
|
|
|
// $contactPersons = $counterpartyModel->getCounterpartyContactPersons(self::COUNTERPARTY_REF); |
|
55
|
|
|
$senderContactRef = '4d06cbac-b88e-11ed-a60f-48df37b921db'; |
|
56
|
|
|
|
|
57
|
|
|
// $contactPersons = $counterpartyModel->getCounterpartyContactPersons($recipientRef); |
|
58
|
|
|
$recipientContactRef = '45b55250-25bb-11ee-a60f-48df37b921db'; |
|
59
|
|
|
|
|
60
|
|
|
//create document |
|
61
|
|
|
$params = [ |
|
62
|
|
|
'Sender' => self::COUNTERPARTY_REF, |
|
63
|
|
|
'CitySender' => self::CITY_REF_KHARKIV, |
|
64
|
|
|
'SenderAddress' => self::ADDRESS_REF_KHARKIV, |
|
65
|
|
|
'ContactSender' => $senderContactRef, |
|
66
|
|
|
'SendersPhone' => 380505511696, |
|
67
|
|
|
|
|
68
|
|
|
'Recipient' => $recipientRef, |
|
69
|
|
|
'CityRecipient' => self::CITY_REF_KYIV, |
|
70
|
|
|
'RecipientAddress' => $addressRef, |
|
71
|
|
|
'ContactRecipient' => $recipientContactRef, |
|
72
|
|
|
'RecipientsPhone' => 380505511696, |
|
73
|
|
|
|
|
74
|
|
|
'DateTime' => date('d.m.Y'), |
|
75
|
|
|
'CargoType' => InternetDocument::CARGO_TYPE_CARGO, |
|
76
|
|
|
'Weight' => '0.5', |
|
77
|
|
|
'SeatsAmount' => '1', |
|
78
|
|
|
'ServiceType' => 'DoorsDoors', |
|
79
|
|
|
'PayerType' => 'Recipient', |
|
80
|
|
|
'PaymentMethod' => 'Cash', |
|
81
|
|
|
'Description' => 'TEST, DO NOT PROCEED WITH THIS' |
|
82
|
|
|
]; |
|
83
|
|
|
|
|
84
|
|
|
$actualResult = $this->model->save($params); |
|
85
|
|
|
$this->assertNotEmpty($actualResult['Ref']); |
|
86
|
|
|
sleep(15); |
|
87
|
|
|
|
|
88
|
|
|
//delete document |
|
89
|
|
|
$this->model->delete($actualResult['Ref']); |
|
90
|
|
|
|
|
91
|
|
|
$documents = $this->model->getDocumentList([ |
|
92
|
|
|
'DateTimeFrom' => date('d.m.Y', strtotime('-2 days')), |
|
93
|
|
|
'DateTimeTo' => date('d.m.Y', strtotime('+2 days')), |
|
94
|
|
|
'GetFullList' => 1, |
|
95
|
|
|
'DateTime' => date('d.m.Y'), |
|
96
|
|
|
], 1); |
|
97
|
|
|
foreach ($documents as $document) { |
|
98
|
|
|
if ($document['Ref'] === $actualResult['Ref']) { |
|
99
|
|
|
$this->fail('Failed to delete document.'); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|