2021-11-24 09:54:04 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-24 09:54:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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\{
|
2021-11-24 10:45:01 +00:00
|
|
|
|
Entities\ReceivePaymentsOperator,
|
2021-11-24 09:54:04 +00:00
|
|
|
|
Exceptions\InvalidPhoneException,
|
|
|
|
|
Tests\BasicTestCase};
|
2021-12-06 08:14:19 +00:00
|
|
|
|
use Exception;
|
2021-11-24 09:54:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы класса оператора по приёму платежей
|
|
|
|
|
*/
|
2021-11-24 10:45:01 +00:00
|
|
|
|
class ReceivePaymentsOperatorTest extends BasicTestCase
|
2021-11-24 09:54:04 +00:00
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор без передачи значений и корректное приведение к json
|
|
|
|
|
*
|
2021-11-24 10:45:01 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::jsonSerialize
|
2021-11-24 09:54:04 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithoutArgs(): void
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame('[]', (string)(new ReceivePaymentsOperator()));
|
2021-11-24 09:54:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор с передачей значений и корректное приведение к json
|
|
|
|
|
*
|
2021-11-24 10:45:01 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::jsonSerialize
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::setPhones
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::getPhones
|
2021-11-24 09:54:04 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws Exception
|
2021-11-24 09:54:04 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithArgs(): void
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable(new ReceivePaymentsOperator(['+122997365456']), ['phones' => ['+122997365456']]);
|
2021-11-24 09:54:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Провайдер массивов телефонов, которые приводятся к null
|
|
|
|
|
*
|
|
|
|
|
* @return array<array>
|
|
|
|
|
*/
|
|
|
|
|
public function providerNullablePhonesArrays(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[[]],
|
|
|
|
|
[null],
|
|
|
|
|
[collect()],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку пустых телефонов
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider providerNullablePhonesArrays
|
2021-11-24 10:45:01 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::setPhones
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::getPhones
|
2021-11-24 09:54:04 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
|
|
|
|
*/
|
|
|
|
|
public function testNullablePhones(mixed $phones): void
|
|
|
|
|
{
|
2021-11-24 10:45:01 +00:00
|
|
|
|
$agent = new ReceivePaymentsOperator($phones);
|
2021-11-24 09:54:04 +00:00
|
|
|
|
$this->assertIsCollection($agent->getPhones());
|
|
|
|
|
$this->assertTrue($agent->getPhones()->isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку невалидных телефонов
|
|
|
|
|
*
|
2021-11-24 10:45:01 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator
|
|
|
|
|
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::setPhones
|
2021-11-24 09:54:04 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidPhoneException
|
|
|
|
|
* @throws InvalidPhoneException
|
|
|
|
|
*/
|
|
|
|
|
public function testInvalidPhoneException(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidPhoneException::class);
|
2021-11-24 10:45:01 +00:00
|
|
|
|
(new ReceivePaymentsOperator([
|
2021-11-24 09:54:04 +00:00
|
|
|
|
'12345678901234567', // good
|
|
|
|
|
'+123456789012345678', // good
|
|
|
|
|
'12345678901234567890', // bad
|
|
|
|
|
'+12345678901234567890', // bad
|
2021-11-24 10:45:01 +00:00
|
|
|
|
]));
|
2021-11-24 09:54:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|