2021-11-24 09:57:24 +00:00
|
|
|
|
<?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\Supplier,
|
2021-11-24 10:54:48 +00:00
|
|
|
|
Exceptions\InvalidInnLengthException,
|
2021-11-24 09:57:24 +00:00
|
|
|
|
Exceptions\InvalidPhoneException,
|
|
|
|
|
Tests\BasicTestCase};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Набор тестов для проверки работы класса поставщика
|
|
|
|
|
*/
|
|
|
|
|
class SupplierTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор без передачи значений и корректное приведение к json
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::jsonSerialize
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithoutArgs(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertEquals('[]', (string)(new Supplier()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует конструктор с передачей значений и корректное приведение к json
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::jsonSerialize
|
2021-11-24 10:54:48 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setName
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::getName
|
2021-11-24 09:57:24 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setPhones
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::getPhones
|
2021-11-24 10:54:48 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setInn
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::getInn
|
2021-11-24 09:57:24 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-24 10:54:48 +00:00
|
|
|
|
* @throws InvalidInnLengthException
|
2021-11-24 09:57:24 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithArgs(): void
|
|
|
|
|
{
|
2021-11-24 10:54:48 +00:00
|
|
|
|
$this->assertAtolable(new Supplier('some name'), ['name' => 'some name']);
|
|
|
|
|
$this->assertAtolable(new Supplier(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
|
|
|
|
|
$this->assertAtolable(new Supplier(phones: ['+122997365456']), ['phones' => ['+122997365456']]);
|
|
|
|
|
$this->assertAtolable(new Supplier(
|
|
|
|
|
'some name',
|
|
|
|
|
'+fasd3\qe3fs_=nac99013928czc',
|
|
|
|
|
['+122997365456'],
|
|
|
|
|
), [
|
|
|
|
|
'name' => 'some name',
|
|
|
|
|
'inn' => '3399013928',
|
|
|
|
|
'phones' => ['+122997365456'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку имён, которые приводятся к null
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $name
|
|
|
|
|
* @dataProvider providerNullableStrings
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setName
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::getName
|
|
|
|
|
* @throws InvalidPhoneException
|
|
|
|
|
* @throws InvalidInnLengthException
|
|
|
|
|
*/
|
|
|
|
|
public function testNullableOperations(mixed $name): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertNull((new Supplier($name))->getName());
|
2021-11-24 09:57:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Провайдер массивов телефонов, которые приводятся к null
|
|
|
|
|
*
|
|
|
|
|
* @return array<array>
|
|
|
|
|
*/
|
|
|
|
|
public function providerNullablePhonesArrays(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[[]],
|
|
|
|
|
[null],
|
|
|
|
|
[collect()],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку пустых телефонов
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider providerNullablePhonesArrays
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setPhones
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::getPhones
|
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-24 10:54:48 +00:00
|
|
|
|
* @throws InvalidInnLengthException
|
2021-11-24 09:57:24 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testNullablePhones(mixed $phones): void
|
|
|
|
|
{
|
2021-11-24 10:54:48 +00:00
|
|
|
|
$agent = new Supplier(phones: $phones);
|
2021-11-24 09:57:24 +00:00
|
|
|
|
$this->assertIsCollection($agent->getPhones());
|
|
|
|
|
$this->assertTrue($agent->getPhones()->isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует установку невалидных телефонов
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setPhones
|
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidPhoneException
|
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-24 10:54:48 +00:00
|
|
|
|
* @throws InvalidInnLengthException
|
2021-11-24 09:57:24 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testInvalidPhoneException(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidPhoneException::class);
|
2021-11-24 10:54:48 +00:00
|
|
|
|
(new Supplier(phones: [
|
2021-11-24 09:57:24 +00:00
|
|
|
|
'12345678901234567', // good
|
|
|
|
|
'+123456789012345678', // good
|
|
|
|
|
'12345678901234567890', // bad
|
|
|
|
|
'+12345678901234567890', // bad
|
2021-11-24 10:54:48 +00:00
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о корректной длине ИНН
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setInn
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::getInn
|
|
|
|
|
* @throws InvalidInnLengthException
|
|
|
|
|
*/
|
|
|
|
|
public function testValidInn(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertEquals('1234567890', (new Supplier())->setInn('1234567890')->getInn());
|
|
|
|
|
$this->assertEquals('123456789012', (new Supplier())->setInn('123456789012')->getInn());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о некорректной длине ИНН (10 цифр)
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setInn
|
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
|
|
|
|
|
* @throws InvalidInnLengthException
|
|
|
|
|
*/
|
|
|
|
|
public function testInvalidInn10(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidInnLengthException::class);
|
|
|
|
|
(new Supplier())->setInn('12345678901');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о некорректной длине ИНН (12 цифр)
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier
|
|
|
|
|
* @covers \AtolOnline\Entities\Supplier::setInn
|
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
|
|
|
|
|
* @throws InvalidInnLengthException
|
|
|
|
|
*/
|
|
|
|
|
public function testInvalidInn12(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(InvalidInnLengthException::class);
|
|
|
|
|
(new Supplier())->setInn('1234567890123');
|
2021-11-24 09:57:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|