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