Реализован и покрыт тестами AgentInfo (переименован из Agent)
This commit is contained in:
@@ -67,16 +67,16 @@ class BasicTestCase extends TestCase
|
||||
* Тестирует является ли объект приводимым к json-строке согласно схеме АТОЛ Онлайн
|
||||
*
|
||||
* @param Entity $entity
|
||||
* @param array $json_structure
|
||||
* @param array|null $json_structure
|
||||
* @covers \AtolOnline\Entities\Entity::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\Entity::__toString
|
||||
*/
|
||||
public function assertAtolable(Entity $entity, array $json_structure = []): void
|
||||
public function assertAtolable(Entity $entity, ?array $json_structure = null): void
|
||||
{
|
||||
$this->assertIsArray($entity->jsonSerialize());
|
||||
$this->assertIsString((string)$entity);
|
||||
$this->assertJson((string)$entity);
|
||||
if ($json_structure) {
|
||||
if (!is_null($json_structure)) {
|
||||
$this->assertEquals(json_encode($json_structure), (string)$entity);
|
||||
}
|
||||
}
|
||||
|
||||
118
tests/AtolOnline/Tests/Entities/AgentInfoTest.php
Normal file
118
tests/AtolOnline/Tests/Entities/AgentInfoTest.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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\AgentInfo,
|
||||
Entities\MoneyTransferOperator,
|
||||
Entities\PayingAgent,
|
||||
Entities\ReceivePaymentsOperator,
|
||||
Enums\AgentTypes,
|
||||
Exceptions\InvalidEnumValueException,
|
||||
Exceptions\InvalidInnLengthException,
|
||||
Exceptions\InvalidPhoneException,
|
||||
Exceptions\TooLongPayingAgentOperationException,
|
||||
Tests\BasicTestCase
|
||||
};
|
||||
|
||||
/**
|
||||
* Набор тестов для проверки работы класса агента
|
||||
*/
|
||||
class AgentInfoTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует конструктор без передачи значений и корректное приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\AgentInfo
|
||||
* @covers \AtolOnline\Entities\AgentInfo::jsonSerialize
|
||||
*/
|
||||
public function testConstructorWithoutArgs(): void
|
||||
{
|
||||
$this->assertAtolable(new AgentInfo(), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует конструктор с передачей значений и корректное приведение к json
|
||||
*
|
||||
* @covers \AtolOnline\Entities\AgentInfo
|
||||
* @covers \AtolOnline\Entities\AgentInfo::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\AgentInfo::setType
|
||||
* @covers \AtolOnline\Entities\AgentInfo::getType
|
||||
* @covers \AtolOnline\Entities\AgentInfo::setPayingAgent
|
||||
* @covers \AtolOnline\Entities\AgentInfo::getPayingAgent
|
||||
* @covers \AtolOnline\Entities\PayingAgent::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\AgentInfo::setMoneyTransferOperator
|
||||
* @covers \AtolOnline\Entities\AgentInfo::getMoneyTransferOperator
|
||||
* @covers \AtolOnline\Entities\MoneyTransferOperator::jsonSerialize
|
||||
* @covers \AtolOnline\Entities\AgentInfo::setReceivePaymentsOperator
|
||||
* @covers \AtolOnline\Entities\AgentInfo::getReceivePaymentsOperator
|
||||
* @covers \AtolOnline\Entities\ReceivePaymentsOperator::jsonSerialize
|
||||
* @throws InvalidPhoneException
|
||||
* @throws TooLongPayingAgentOperationException
|
||||
* @throws InvalidInnLengthException
|
||||
* @throws InvalidEnumValueException
|
||||
*/
|
||||
public function testConstructorWithArgs(): void
|
||||
{
|
||||
$this->assertAtolable(new AgentInfo(null), []);
|
||||
$this->assertAtolable(new AgentInfo(AgentTypes::ANOTHER), ['type' => AgentTypes::ANOTHER]);
|
||||
$this->assertAtolable(new AgentInfo(paying_agent: new PayingAgent()), []);
|
||||
$this->assertAtolable(new AgentInfo(money_transfer_operator: new MoneyTransferOperator()), []);
|
||||
$this->assertAtolable(new AgentInfo(receive_payments_operator: new ReceivePaymentsOperator()), []);
|
||||
|
||||
$this->assertAtolable(new AgentInfo(
|
||||
AgentTypes::ANOTHER,
|
||||
new PayingAgent(),
|
||||
new ReceivePaymentsOperator(),
|
||||
new MoneyTransferOperator(),
|
||||
), ['type' => AgentTypes::ANOTHER]);
|
||||
|
||||
$this->assertAtolable(new AgentInfo(
|
||||
AgentTypes::ANOTHER,
|
||||
new PayingAgent('test', ['+79518888888']),
|
||||
new ReceivePaymentsOperator(['+79519999999']),
|
||||
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
|
||||
), [
|
||||
'type' => AgentTypes::ANOTHER,
|
||||
'paying_agent' => [
|
||||
'operation' => 'test',
|
||||
'phones' => [
|
||||
'+79518888888',
|
||||
],
|
||||
],
|
||||
'receive_payments_operator' => [
|
||||
'phones' => [
|
||||
'+79519999999',
|
||||
],
|
||||
],
|
||||
'money_transfer_operator' => [
|
||||
'name' => 'MTO Name',
|
||||
'inn' => '9876543210',
|
||||
'address' => 'London',
|
||||
'phones' => [
|
||||
"+79517777777",
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение при некорректном типе
|
||||
*
|
||||
* @covers \AtolOnline\Entities\AgentInfo
|
||||
* @covers \AtolOnline\Enums\AgentTypes::isValid
|
||||
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
|
||||
*/
|
||||
public function testInvalidEnumValueException(): void
|
||||
{
|
||||
$this->expectException(InvalidEnumValueException::class);
|
||||
new AgentInfo('qwerty');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user