Класс Supplier обзавёлся name + inn и допокрыт тестами

This commit is contained in:
2021-11-24 18:54:48 +08:00
parent 790831e933
commit 95dbc3a5b7
4 changed files with 173 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Entities\Supplier,
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPhoneException,
Tests\BasicTestCase};
@@ -35,13 +36,45 @@ class SupplierTest extends BasicTestCase
*
* @covers \AtolOnline\Entities\Supplier
* @covers \AtolOnline\Entities\Supplier::jsonSerialize
* @covers \AtolOnline\Entities\Supplier::setName
* @covers \AtolOnline\Entities\Supplier::getName
* @covers \AtolOnline\Entities\Supplier::setPhones
* @covers \AtolOnline\Entities\Supplier::getPhones
* @covers \AtolOnline\Entities\Supplier::setInn
* @covers \AtolOnline\Entities\Supplier::getInn
* @throws InvalidPhoneException
* @throws InvalidInnLengthException
*/
public function testConstructorWithArgs(): void
{
$this->assertAtolable(new Supplier(['+122997365456']), ['phones' => ['+122997365456']]);
$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());
}
/**
@@ -66,10 +99,11 @@ class SupplierTest extends BasicTestCase
* @covers \AtolOnline\Entities\Supplier::setPhones
* @covers \AtolOnline\Entities\Supplier::getPhones
* @throws InvalidPhoneException
* @throws InvalidInnLengthException
*/
public function testNullablePhones(mixed $phones): void
{
$agent = new Supplier($phones);
$agent = new Supplier(phones: $phones);
$this->assertIsCollection($agent->getPhones());
$this->assertTrue($agent->getPhones()->isEmpty());
}
@@ -81,15 +115,58 @@ class SupplierTest extends BasicTestCase
* @covers \AtolOnline\Entities\Supplier::setPhones
* @covers \AtolOnline\Exceptions\InvalidPhoneException
* @throws InvalidPhoneException
* @throws InvalidInnLengthException
*/
public function testInvalidPhoneException(): void
{
$this->expectException(InvalidPhoneException::class);
(new Supplier())->setPhones([
(new Supplier(phones: [
'12345678901234567', // good
'+123456789012345678', // good
'12345678901234567890', // bad
'+12345678901234567890', // bad
]);
]));
}
/**
* Тестирует исключение о корректной длине ИНН
*
* @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');
}
}