|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SergeyNezbritskiy\Tests\Integration\Models\Counterparty; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use SergeyNezbritskiy\NovaPoshta\Models\Counterparty; |
|
10
|
|
|
use SergeyNezbritskiy\NovaPoshta\Tests\UsesConnectionTrait; |
|
11
|
|
|
|
|
12
|
|
|
class SavePrivatePersonTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
use UsesConnectionTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Kharkiv city ref |
|
18
|
|
|
*/ |
|
19
|
|
|
private const CITY_REF = 'db5c88e0-391c-11dd-90d9-001a92567626'; |
|
20
|
|
|
|
|
21
|
|
|
private Counterparty $model; |
|
22
|
|
|
|
|
23
|
|
|
protected function setUp(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$connection = $this->getConnection(); |
|
26
|
|
|
$this->model = new Counterparty($connection); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return void |
|
31
|
|
|
* @throws Exception |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testCounterpartyPrivatePersonCrud(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$sfx = $this->randomString(5); |
|
36
|
|
|
$counterparty = [ |
|
37
|
|
|
'FirstName' => 'Іван' . $sfx, |
|
38
|
|
|
'MiddleName' => 'Іванович' . $sfx, |
|
39
|
|
|
'LastName' => 'Іванов' . $sfx, |
|
40
|
|
|
'Phone' => rand(380000000000, 380000999999), |
|
41
|
|
|
'Email' => '[email protected]', |
|
42
|
|
|
'CounterpartyProperty' => 'Recipient', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
//create counterparty |
|
46
|
|
|
$actualResult = $this->model->savePrivatePerson($counterparty); |
|
47
|
|
|
$this->assertIsCounterparty($actualResult); |
|
48
|
|
|
|
|
49
|
|
|
//update counterparty |
|
50
|
|
|
$counterparty['Ref'] = $actualResult['Ref']; |
|
51
|
|
|
$counterparty['MiddleName'] = 'Петрович' . $sfx; |
|
52
|
|
|
$counterparty['CityRef'] = self::CITY_REF; |
|
53
|
|
|
|
|
54
|
|
|
$actualResult = $this->model->updatePrivatePerson($counterparty); |
|
55
|
|
|
$this->assertSame($counterparty['MiddleName'], $actualResult['MiddleName']); |
|
56
|
|
|
|
|
57
|
|
|
//get counterparty options |
|
58
|
|
|
$counterpartyOptions = $this->model->getCounterpartyOptions($counterparty['Ref']); |
|
59
|
|
|
$this->assertIsCounterpartyOptions($counterpartyOptions); |
|
60
|
|
|
|
|
61
|
|
|
//get counterparty contact persons |
|
62
|
|
|
$contactPersons = $this->model->getCounterpartyContactPersons($counterparty['Ref']); |
|
63
|
|
|
$this->assertIsContactPerson(array_shift($contactPersons)); |
|
64
|
|
|
|
|
65
|
|
|
//delete counterparty |
|
66
|
|
|
$this->expectExceptionMessage('Counterparty PrivatePerson can\'t be deleted'); |
|
67
|
|
|
$this->model->delete($counterparty['Ref']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param array $counterparty |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
private function assertIsCounterparty(array $counterparty): void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertArrayHasKey('Ref', $counterparty); |
|
77
|
|
|
$this->assertArrayHasKey('Description', $counterparty); |
|
78
|
|
|
$this->assertArrayHasKey('FirstName', $counterparty); |
|
79
|
|
|
$this->assertArrayHasKey('LastName', $counterparty); |
|
80
|
|
|
$this->assertArrayHasKey('Counterparty', $counterparty); |
|
81
|
|
|
$this->assertArrayHasKey('EDRPOU', $counterparty); |
|
82
|
|
|
$this->assertArrayHasKey('CounterpartyType', $counterparty); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param array $contactPerson |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
private function assertIsContactPerson(array $contactPerson): void |
|
90
|
|
|
{ |
|
91
|
|
|
$this->assertArrayHasKey('Ref', $contactPerson); |
|
92
|
|
|
$this->assertArrayHasKey('Description', $contactPerson); |
|
93
|
|
|
$this->assertArrayHasKey('Phones', $contactPerson); |
|
94
|
|
|
$this->assertArrayHasKey('FirstName', $contactPerson); |
|
95
|
|
|
$this->assertArrayHasKey('LastName', $contactPerson); |
|
96
|
|
|
$this->assertArrayHasKey('MiddleName', $contactPerson); |
|
97
|
|
|
$this->assertArrayHasKey('Email', $contactPerson); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param array $counterpartyOptions |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
private function assertIsCounterpartyOptions(array $counterpartyOptions): void |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertArrayHasKey('Debtor', $counterpartyOptions); |
|
107
|
|
|
$this->assertArrayHasKey('DebtorParams', $counterpartyOptions); |
|
108
|
|
|
$this->assertArrayHasKey('SecurePayment', $counterpartyOptions); |
|
109
|
|
|
$this->assertArrayHasKey('MainCounterparty', $counterpartyOptions); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @throws Exception |
|
114
|
|
|
*/ |
|
115
|
|
|
private function randomString($length = 10): string |
|
116
|
|
|
{ |
|
117
|
|
|
$characters = 'абвгґдеєжзиіїйклмнопрстуфхцчшщьюяАБВГҐДЕЄЖЗИІЇЙКЛМНОПРСТУФХЦЧШЩЬЮЯ'; |
|
118
|
|
|
$charactersLength = mb_strlen($characters); |
|
119
|
|
|
$randomString = ''; |
|
120
|
|
|
for ($i = 0; $i < $length; $i++) { |
|
121
|
|
|
$symbolPosition = random_int(0, $charactersLength - 1); |
|
122
|
|
|
$randomString .= mb_substr($characters, $symbolPosition, 1); |
|
123
|
|
|
} |
|
124
|
|
|
return $randomString; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|