Туча доработок
- класс `PayingAgent`, покрытый тестами - новые константы для тегов ФФД 1.05 `Ffd105Tags` - `Entity::jsonSerialize()` object -> array (again) - `TooManyException::$max` int -> float - тесты по psr-4, потому что почему бы и нет - некоторые провайдеры вынесены в `BasicTestCase` - улучшен тест покупателя
This commit is contained in:
254
tests/AtolOnline/Tests/Entities/ClientTest.php
Normal file
254
tests/AtolOnline/Tests/Entities/ClientTest.php
Normal file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace AtolOnline\Tests\Entities;
|
||||
|
||||
use AtolOnline\{
|
||||
Entities\Client,
|
||||
Exceptions\InvalidEmailException,
|
||||
Exceptions\InvalidInnLengthException,
|
||||
Exceptions\TooLongClientContactException,
|
||||
Exceptions\TooLongClientNameException,
|
||||
Exceptions\TooLongEmailException,
|
||||
Helpers,
|
||||
Tests\BasicTestCase
|
||||
};
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класса покупателя
|
||||
*/
|
||||
class ClientTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует конструктор без передачи значений и приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::jsonSerialize
|
||||
*/
|
||||
public function testConstructorWithoutArgs(): void
|
||||
{
|
||||
$this->assertEquals('[]', (string)(new Client()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует конструктор с передачей значений и приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\Client::setName
|
||||
* @covers \AtolOnline\Entities\Client::setPhone
|
||||
* @covers \AtolOnline\Entities\Client::setEmail
|
||||
* @covers \AtolOnline\Entities\Client::setInn
|
||||
* @covers \AtolOnline\Entities\Client::getName
|
||||
* @covers \AtolOnline\Entities\Client::getPhone
|
||||
* @covers \AtolOnline\Entities\Client::getEmail
|
||||
* @covers \AtolOnline\Entities\Client::getInn
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$this->assertAtolable(new Client('John Doe'), ['name' => 'John Doe']);
|
||||
$this->assertAtolable(new Client(email: 'john@example.com'), ['email' => 'john@example.com']);
|
||||
$this->assertAtolable(new Client(phone: '+1/22/99*73s dsdas654 5s6'), ['phone' => '+122997365456']);
|
||||
$this->assertAtolable(new Client(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
|
||||
$this->assertAtolable(new Client(
|
||||
'John Doe',
|
||||
'john@example.com',
|
||||
'+1/22/99*73s dsdas654 5s6', // +122997365456
|
||||
'+fasd3\qe3fs_=nac99013928czc' // 3399013928
|
||||
), [
|
||||
'name' => 'John Doe',
|
||||
'email' => 'john@example.com',
|
||||
'phone' => '+122997365456',
|
||||
'inn' => '3399013928',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку имён, которые приводятся к null
|
||||
*
|
||||
* @param mixed $name
|
||||
* @dataProvider providerNullableStrings
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setName
|
||||
* @covers \AtolOnline\Entities\Client::getName
|
||||
* @throws TooLongClientNameException
|
||||
*/
|
||||
public function testNullableNames(mixed $name): void
|
||||
{
|
||||
$this->assertNull((new Client())->setName($name)->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку валидного имени
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setName
|
||||
* @covers \AtolOnline\Entities\Client::getName
|
||||
* @throws TooLongClientNameException
|
||||
*/
|
||||
public function testValidName(): void
|
||||
{
|
||||
$name = Helpers::randomStr();
|
||||
$this->assertEquals($name, (new Client())->setName($name)->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку невалидного имени
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setName
|
||||
* @covers \AtolOnline\Exceptions\TooLongClientNameException
|
||||
*/
|
||||
public function testInvalidName(): void
|
||||
{
|
||||
$this->expectException(TooLongClientNameException::class);
|
||||
(new Client())->setName(Helpers::randomStr(400));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Тестирует установку телефонов, которые приводятся к null
|
||||
*
|
||||
* @param mixed $phone
|
||||
* @dataProvider providerNullablePhones
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setPhone
|
||||
* @covers \AtolOnline\Entities\Client::getPhone
|
||||
* @throws TooLongClientContactException
|
||||
*/
|
||||
public function testNullablePhones(mixed $phone): void
|
||||
{
|
||||
$this->assertNull((new Client())->setPhone($phone)->getPhone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку валидного телефона
|
||||
*
|
||||
* @todo актуализировать при доработатанной валидации
|
||||
* @dataProvider providerValidPhones
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setPhone
|
||||
* @covers \AtolOnline\Entities\Client::getPhone
|
||||
* @throws TooLongClientContactException
|
||||
*/
|
||||
public function testValidPhone(string $input, string $output): void
|
||||
{
|
||||
$this->assertEquals($output, (new Client())->setPhone($input)->getPhone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку невалидного телефона
|
||||
*
|
||||
* @todo актуализировать при доработатанной валидации
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setPhone
|
||||
* @covers \AtolOnline\Exceptions\TooLongClientContactException
|
||||
* @throws TooLongClientContactException
|
||||
*/
|
||||
public function testTooLongClientPhone(): void
|
||||
{
|
||||
$this->expectException(TooLongClientContactException::class);
|
||||
(new Client())->setPhone('99999999999999999999999999999999999999999999999999999999999999999999999999');
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Тестирует установку валидных email-ов
|
||||
*
|
||||
* @param mixed $email
|
||||
* @dataProvider providerValidEmails
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setEmail
|
||||
* @covers \AtolOnline\Entities\Client::getEmail
|
||||
* @throws TooLongEmailException
|
||||
* @throws InvalidEmailException
|
||||
*/
|
||||
public function testValidEmails(mixed $email): void
|
||||
{
|
||||
$this->assertEquals($email, (new Client())->setEmail($email)->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку слишком длинного email
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setEmail
|
||||
* @covers \AtolOnline\Exceptions\TooLongEmailException
|
||||
* @throws TooLongEmailException
|
||||
* @throws InvalidEmailException
|
||||
*/
|
||||
public function testTooLongEmail(): void
|
||||
{
|
||||
$this->expectException(TooLongEmailException::class);
|
||||
(new Client())->setEmail(Helpers::randomStr(65));
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку невалидного email
|
||||
*
|
||||
* @param mixed $email
|
||||
* @dataProvider providerInvalidEmails
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setEmail
|
||||
* @covers \AtolOnline\Exceptions\InvalidEmailException
|
||||
* @throws TooLongEmailException
|
||||
* @throws InvalidEmailException
|
||||
*/
|
||||
public function testInvalidEmail(mixed $email): void
|
||||
{
|
||||
$this->expectException(InvalidEmailException::class);
|
||||
(new Client())->setEmail($email);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Тестирует исключение о корректной длине ИНН
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setInn
|
||||
* @covers \AtolOnline\Entities\Client::getInn
|
||||
* @throws InvalidInnLengthException
|
||||
*/
|
||||
public function testValidInn(): void
|
||||
{
|
||||
$this->assertEquals('1234567890', (new Client())->setInn('1234567890')->getInn());
|
||||
$this->assertEquals('123456789012', (new Client())->setInn('123456789012')->getInn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о некорректной длине ИНН (10 цифр)
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setInn
|
||||
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
|
||||
* @throws InvalidInnLengthException
|
||||
*/
|
||||
public function testInvalidInn10(): void
|
||||
{
|
||||
$this->expectException(InvalidInnLengthException::class);
|
||||
(new Client())->setInn('12345678901');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о некорректной длине ИНН (12 цифр)
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Client
|
||||
* @covers \AtolOnline\Entities\Client::setInn
|
||||
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
|
||||
* @throws InvalidInnLengthException
|
||||
*/
|
||||
public function testInvalidInn12(): void
|
||||
{
|
||||
$this->expectException(InvalidInnLengthException::class);
|
||||
(new Client())->setInn('1234567890123');
|
||||
}
|
||||
}
|
||||
136
tests/AtolOnline/Tests/Entities/CompanyTest.php
Normal file
136
tests/AtolOnline/Tests/Entities/CompanyTest.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace AtolOnline\Tests\Entities;
|
||||
|
||||
use AtolOnline\{
|
||||
Entities\Company,
|
||||
Enums\SnoTypes,
|
||||
Exceptions\InvalidEmailException,
|
||||
Exceptions\InvalidEnumValueException,
|
||||
Exceptions\InvalidInnLengthException,
|
||||
Exceptions\InvalidPaymentAddressException,
|
||||
Exceptions\TooLongEmailException,
|
||||
Exceptions\TooLongPaymentAddressException,
|
||||
Helpers,
|
||||
Tests\BasicTestCase
|
||||
};
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класс продавца
|
||||
*/
|
||||
class CompanyTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует конструктор с сеттерами и приведение к json с геттерами
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\Company::setEmail
|
||||
* @covers \AtolOnline\Entities\Company::setSno
|
||||
* @covers \AtolOnline\Entities\Company::setInn
|
||||
* @covers \AtolOnline\Entities\Company::setPaymentAddress
|
||||
* @covers \AtolOnline\Entities\Company::getEmail
|
||||
* @covers \AtolOnline\Entities\Company::getSno
|
||||
* @covers \AtolOnline\Entities\Company::getInn
|
||||
* @covers \AtolOnline\Entities\Company::getPaymentAddress
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->assertAtolable(new Company(
|
||||
$email = 'company@example.com',
|
||||
$sno = SnoTypes::OSN,
|
||||
$inn = '1234567890',
|
||||
$payment_address = 'https://example.com',
|
||||
), [
|
||||
'email' => $email,
|
||||
'sno' => $sno,
|
||||
'inn' => $inn,
|
||||
'payment_address' => $payment_address,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном email
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::setEmail
|
||||
* @covers \AtolOnline\Exceptions\TooLongEmailException
|
||||
*/
|
||||
public function testEmailTooLongException()
|
||||
{
|
||||
$this->expectException(TooLongEmailException::class);
|
||||
new Company(Helpers::randomStr(65), SnoTypes::OSN, '1234567890', 'https://example.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о невалидном email
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::setEmail
|
||||
* @covers \AtolOnline\Exceptions\InvalidEmailException
|
||||
*/
|
||||
public function testInvalidEmailException()
|
||||
{
|
||||
$this->expectException(InvalidEmailException::class);
|
||||
new Company('company@examas%^*.com', SnoTypes::OSN, '1234567890', 'https://example.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном платёжном адресе
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::setSno
|
||||
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
|
||||
*/
|
||||
public function testInvalidSnoException()
|
||||
{
|
||||
$this->expectException(InvalidEnumValueException::class);
|
||||
new Company('company@example.com', 'test', '1234567890', 'https://example.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном платёжном адресе
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::setInn
|
||||
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
|
||||
*/
|
||||
public function testInvalidInnLengthException()
|
||||
{
|
||||
$this->expectException(InvalidInnLengthException::class);
|
||||
new Company('company@example.com', SnoTypes::OSN, Helpers::randomStr(13), 'https://example.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном платёжном адресе
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::setPaymentAddress
|
||||
* @covers \AtolOnline\Exceptions\TooLongPaymentAddressException
|
||||
*/
|
||||
public function testTooLongPaymentAddressException()
|
||||
{
|
||||
$this->expectException(TooLongPaymentAddressException::class);
|
||||
new Company('company@example.com', SnoTypes::OSN, '1234567890', Helpers::randomStr(257));
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о невалидном платёжном адресе
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Company
|
||||
* @covers \AtolOnline\Entities\Company::setPaymentAddress
|
||||
* @covers \AtolOnline\Exceptions\InvalidPaymentAddressException
|
||||
*/
|
||||
public function testInvalidPaymentAddressException()
|
||||
{
|
||||
$this->expectException(InvalidPaymentAddressException::class);
|
||||
new Company('company@example.com', SnoTypes::OSN, '1234567890', '');
|
||||
}
|
||||
}
|
||||
137
tests/AtolOnline/Tests/Entities/KktEntityTest.php
Normal file
137
tests/AtolOnline/Tests/Entities/KktEntityTest.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace AtolOnline\Tests\Entities;
|
||||
|
||||
use AtolOnline\Entities\Kkt;
|
||||
use AtolOnline\Exceptions\EmptyMonitorDataException;
|
||||
use AtolOnline\Exceptions\NotEnoughMonitorDataException;
|
||||
use AtolOnline\Tests\BasicTestCase;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
|
||||
class KktEntityTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* @var array Данные для создания объекта ККТ
|
||||
*/
|
||||
private array $sample_data = [
|
||||
'serialNumber' => '00107703864827',
|
||||
'registrationNumber' => '0000000003027865',
|
||||
'deviceNumber' => 'KKT024219',
|
||||
'fiscalizationDate' => '2019-07-22T14:03:00+00:00',
|
||||
'fiscalStorageExpiration' => '2020-11-02T21:00:00+00:00',
|
||||
'signedDocuments' => 213350,
|
||||
'fiscalStoragePercentageUse' => 85.34,
|
||||
'fiscalStorageINN' => '3026455760',
|
||||
'fiscalStorageSerialNumber' => '9999078902004339',
|
||||
'fiscalStoragePaymentAddress' => 'test.qa.ru',
|
||||
'groupCode' => 'test-qa-ru_14605',
|
||||
'timestamp' => '2019-12-05T10:45:30+00:00',
|
||||
'isShiftOpened' => true,
|
||||
'shiftNumber' => 126,
|
||||
'shiftReceipt' => 2278,
|
||||
//'unsentDocs' => 123,
|
||||
'firstUnsetDocTimestamp' => 'there must be timestamp, but we want to get exception here to get string',
|
||||
'networkErrorCode' => 2,
|
||||
];
|
||||
|
||||
/**
|
||||
* Тестирует создание объекта ККТ с валидными данными
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Kkt::__construct
|
||||
* @covers \AtolOnline\Entities\Kkt::__get
|
||||
* @covers \AtolOnline\Entities\Kkt::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\Kkt::__toString
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testConstructor(): void
|
||||
{
|
||||
$kkt = new Kkt((object)$this->sample_data);
|
||||
$this->assertIsSameClass(Kkt::class, $kkt);
|
||||
$this->assertAtolable($kkt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение при попытке создать объект ККТ без данных от монитора
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Kkt::__construct
|
||||
* @covers \AtolOnline\Exceptions\EmptyMonitorDataException
|
||||
* @throws EmptyMonitorDataException
|
||||
* @throws NotEnoughMonitorDataException
|
||||
*/
|
||||
public function testEmptyMonitorDataException(): void
|
||||
{
|
||||
$this->expectException(EmptyMonitorDataException::class);
|
||||
new Kkt((object)[]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение при попытке создать объект ККТ без данных от монитора
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Kkt::__construct
|
||||
* @covers \AtolOnline\Exceptions\NotEnoughMonitorDataException
|
||||
* @throws EmptyMonitorDataException
|
||||
* @throws NotEnoughMonitorDataException
|
||||
*/
|
||||
public function testNotEnoughMonitorDataException(): void
|
||||
{
|
||||
$this->expectException(NotEnoughMonitorDataException::class);
|
||||
new Kkt((object)[
|
||||
'fiscalizationDate' => '2021-11-20T10:21:00+00:00',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует получение атрибутов через магический геттер
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Kkt::__get
|
||||
* @throws EmptyMonitorDataException
|
||||
* @throws NotEnoughMonitorDataException
|
||||
*/
|
||||
public function testMagicGetter(): void
|
||||
{
|
||||
$kkt = new Kkt((object)$this->sample_data);
|
||||
|
||||
// string
|
||||
$this->assertNotNull($kkt->serialNumber);
|
||||
$this->assertIsString($kkt->serialNumber);
|
||||
$this->assertEquals($this->sample_data['serialNumber'], $kkt->serialNumber);
|
||||
|
||||
// int
|
||||
$this->assertNotNull($kkt->signedDocuments);
|
||||
$this->assertIsInt($kkt->signedDocuments);
|
||||
|
||||
// float
|
||||
$this->assertNotNull($kkt->signedDocuments);
|
||||
$this->assertIsFloat($kkt->fiscalStoragePercentageUse);
|
||||
|
||||
// null
|
||||
$this->assertNull($kkt->unsentDocs);
|
||||
|
||||
// DateTime
|
||||
$this->assertNotNull($kkt->fiscalizationDate);
|
||||
$this->assertIsSameClass(DateTime::class, $kkt->fiscalizationDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение при попытке получить некорректный DateTime через магический геттер
|
||||
*
|
||||
* @covers \AtolOnline\Entities\Kkt::__get
|
||||
* @throws EmptyMonitorDataException
|
||||
* @throws NotEnoughMonitorDataException
|
||||
*/
|
||||
public function testDateTimeException(): void
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
(new Kkt((object)$this->sample_data))->firstUnsetDocTimestamp;
|
||||
}
|
||||
}
|
||||
145
tests/AtolOnline/Tests/Entities/PayingAgentTest.php
Normal file
145
tests/AtolOnline/Tests/Entities/PayingAgentTest.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace AtolOnline\Tests\Entities;
|
||||
|
||||
use AtolOnline\{
|
||||
Entities\PayingAgent,
|
||||
Exceptions\InvalidPhoneException,
|
||||
Exceptions\TooLongPayingAgentOperationException,
|
||||
Helpers,
|
||||
Tests\BasicTestCase
|
||||
};
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класса платёжного агента
|
||||
*/
|
||||
class PayingAgentTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует конструктор без передачи значений и корректное приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\PayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::jsonSerialize
|
||||
*/
|
||||
public function testConstructorWithoutArgs(): void
|
||||
{
|
||||
$this->assertEquals('[]', (string)(new PayingAgent()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует конструктор с передачей значений и корректное приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\PayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\PayingAgent::setOperation
|
||||
* @covers \AtolOnline\Entities\PayingAgent::setPhones
|
||||
* @covers \AtolOnline\Entities\PayingAgent::getOperation
|
||||
* @covers \AtolOnline\Entities\PayingAgent::getPhones
|
||||
* @throws InvalidPhoneException
|
||||
* @throws TooLongPayingAgentOperationException
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$operation = Helpers::randomStr();
|
||||
$this->assertAtolable(new PayingAgent(
|
||||
$operation,
|
||||
['+122997365456'],
|
||||
), [
|
||||
'operation' => $operation,
|
||||
'phones' => ['+122997365456'],
|
||||
]);
|
||||
$this->assertAtolable(
|
||||
new PayingAgent($operation),
|
||||
['operation' => $operation]
|
||||
);
|
||||
$this->assertAtolable(
|
||||
new PayingAgent(phones: ['+122997365456']),
|
||||
['phones' => ['+122997365456']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку операций, которые приводятся к null
|
||||
*
|
||||
* @param mixed $name
|
||||
* @dataProvider providerNullableStrings
|
||||
* @covers \AtolOnline\Entities\PayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::setOperation
|
||||
* @covers \AtolOnline\Entities\PayingAgent::getOperation
|
||||
* @throws TooLongPayingAgentOperationException
|
||||
*/
|
||||
public function testNullableOperations(mixed $name): void
|
||||
{
|
||||
$this->assertNull((new PayingAgent())->setOperation($name)->getOperation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку невалидного имени покупателя
|
||||
*
|
||||
* @covers \AtolOnline\Entities\PayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::setOperation
|
||||
* @covers \AtolOnline\Exceptions\TooLongPayingAgentOperationException
|
||||
*/
|
||||
public function testTooLongPayingAgentOperationException(): void
|
||||
{
|
||||
$this->expectException(TooLongPayingAgentOperationException::class);
|
||||
(new PayingAgent())->setOperation(Helpers::randomStr(25));
|
||||
}
|
||||
|
||||
/**
|
||||
* Провайдер массивов телефонов, которые приводятся к null
|
||||
*
|
||||
* @return array<array<mixed>>
|
||||
*/
|
||||
public function providerNullablePhonesArrays(): array
|
||||
{
|
||||
return [
|
||||
[[]],
|
||||
[null],
|
||||
[collect()],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку пустых телефонов
|
||||
*
|
||||
* @dataProvider providerNullablePhonesArrays
|
||||
* @covers \AtolOnline\Entities\PayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::setPhones
|
||||
* @covers \AtolOnline\Entities\PayingAgent::getPhones
|
||||
* @throws InvalidPhoneException
|
||||
* @throws TooLongPayingAgentOperationException
|
||||
*/
|
||||
public function testNullablePhones(mixed $phones): void
|
||||
{
|
||||
$agent = new PayingAgent(phones: $phones);
|
||||
$this->assertIsCollection($agent->getPhones());
|
||||
$this->assertTrue($agent->getPhones()->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует установку невалидных телефонов
|
||||
*
|
||||
* @covers \AtolOnline\Entities\PayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::setPhones
|
||||
* @covers \AtolOnline\Exceptions\InvalidPhoneException
|
||||
* @throws InvalidPhoneException
|
||||
*/
|
||||
public function testInvalidPhoneException(): void
|
||||
{
|
||||
$this->expectException(InvalidPhoneException::class);
|
||||
(new PayingAgent())->setPhones([
|
||||
'12345678901234567', // good
|
||||
'+123456789012345678', // good
|
||||
'12345678901234567890', // bad
|
||||
'+12345678901234567890', // bad
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user