2021-11-18 04:24:30 +00:00
|
|
|
|
<?php
|
2022-12-14 16:19:55 +00:00
|
|
|
|
|
2021-11-18 04:24:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
namespace AtolOnline\Tests\Entities;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
2022-12-14 16:19:55 +00:00
|
|
|
|
use AtolOnline\{
|
|
|
|
|
Entities\Client,
|
2021-11-18 04:24:30 +00:00
|
|
|
|
Exceptions\InvalidEmailException,
|
|
|
|
|
Exceptions\InvalidInnLengthException,
|
2021-12-01 12:11:08 +00:00
|
|
|
|
Exceptions\InvalidPhoneException,
|
2021-11-22 06:51:10 +00:00
|
|
|
|
Exceptions\TooLongClientNameException,
|
2021-11-18 04:24:30 +00:00
|
|
|
|
Exceptions\TooLongEmailException,
|
2021-11-23 17:30:54 +00:00
|
|
|
|
Helpers,
|
2022-12-14 16:19:55 +00:00
|
|
|
|
Tests\BasicTestCase};
|
2021-12-12 03:09:12 +00:00
|
|
|
|
use BadMethodCallException;
|
2021-12-06 08:14:19 +00:00
|
|
|
|
use Exception;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Набор тестов для проверки работы класса покупателя
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
class ClientTest extends BasicTestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует конструктор без передачи значений и приведение к json
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::jsonSerialize
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws Exception
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithoutArgs(): void
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertIsAtolable(new Client());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует конструктор с передачей значений и приведение к json
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @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
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Client::getName
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getPhone
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getEmail
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getInn
|
2021-12-06 08:14:19 +00:00
|
|
|
|
* @throws Exception
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testConstructorWithArgs(): void
|
|
|
|
|
{
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable(new Client('John Doe'), ['name' => 'John Doe']);
|
|
|
|
|
$this->assertIsAtolable(new Client(phone: '+1/22/99*73s dsdas654 5s6'), ['phone' => '+122997365456']);
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertIsAtolable(new Client(email: 'john@example.com'), ['email' => 'john@example.com']);
|
2021-12-07 12:04:03 +00:00
|
|
|
|
$this->assertIsAtolable(new Client(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
|
2021-12-12 03:09:12 +00:00
|
|
|
|
$this->assertIsAtolable(
|
|
|
|
|
new Client(
|
|
|
|
|
'John Doe',
|
|
|
|
|
'+1/22/99*73s dsdas654 5s6', // +122997365456
|
2022-12-14 16:19:55 +00:00
|
|
|
|
'john@example.com',
|
2021-12-12 03:09:12 +00:00
|
|
|
|
'+fasd3\qe3fs_=nac99013928czc' // 3399013928
|
2022-12-14 16:19:55 +00:00
|
|
|
|
),
|
|
|
|
|
[
|
2021-12-12 03:09:12 +00:00
|
|
|
|
'name' => 'John Doe',
|
|
|
|
|
'phone' => '+122997365456',
|
2022-12-14 16:19:55 +00:00
|
|
|
|
'email' => 'john@example.com',
|
2021-12-12 03:09:12 +00:00
|
|
|
|
'inn' => '3399013928',
|
|
|
|
|
]
|
|
|
|
|
);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку имён, которые приводятся к null
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @param mixed $name
|
|
|
|
|
* @dataProvider providerNullableStrings
|
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::setName
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getName
|
2021-11-22 06:51:10 +00:00
|
|
|
|
* @throws TooLongClientNameException
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testNullableNames(mixed $name): void
|
|
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertNull((new Client())->setName($name)->getName());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку валидного имени
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::setName
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getName
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* @throws TooLongClientNameException
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testValidName(): void
|
|
|
|
|
{
|
|
|
|
|
$name = Helpers::randomStr();
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($name, (new Client())->setName($name)->getName());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку невалидного имени
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::setName
|
2021-11-22 06:51:10 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\TooLongClientNameException
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testInvalidName(): void
|
|
|
|
|
{
|
2021-11-22 06:51:10 +00:00
|
|
|
|
$this->expectException(TooLongClientNameException::class);
|
2021-11-18 04:24:30 +00:00
|
|
|
|
(new Client())->setName(Helpers::randomStr(400));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку телефонов, которые приводятся к null
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @param mixed $phone
|
|
|
|
|
* @dataProvider providerNullablePhones
|
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::setPhone
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getPhone
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testNullablePhones(mixed $phone): void
|
|
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertNull((new Client())->setPhone($phone)->getPhone());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку валидного телефона
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
2021-12-12 03:09:12 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* @todo актуализировать при доработатанной валидации
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @dataProvider providerValidPhones
|
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::setPhone
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::getPhone
|
|
|
|
|
*/
|
|
|
|
|
public function testValidPhone(string $input, string $output): void
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($output, (new Client())->setPhone($input)->getPhone());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку невалидного телефона
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
2021-12-12 03:09:12 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* @todo актуализировать при доработатанной валидации
|
2021-11-18 04:24:30 +00:00
|
|
|
|
* @covers \AtolOnline\Entities\Client
|
|
|
|
|
* @covers \AtolOnline\Entities\Client::setPhone
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @covers \AtolOnline\Exceptions\InvalidPhoneException
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
2021-12-01 12:11:08 +00:00
|
|
|
|
public function testInvalidPhoneException(): void
|
2021-11-18 04:24:30 +00:00
|
|
|
|
{
|
2021-12-01 12:11:08 +00:00
|
|
|
|
$this->expectException(InvalidPhoneException::class);
|
|
|
|
|
(new Client())->setPhone(Helpers::randomStr(500));
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку валидных email-ов
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame($email, (new Client())->setEmail($email)->getEmail());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку слишком длинного email
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-23 17:30:54 +00:00
|
|
|
|
* Тестирует установку невалидного email
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
|
|
{
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame('1234567890', (new Client())->setInn('1234567890')->getInn());
|
|
|
|
|
$this->assertSame('123456789012', (new Client())->setInn('123456789012')->getInn());
|
2021-11-18 04:24:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует исключение о некорректной длине ИНН (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');
|
|
|
|
|
}
|
2021-12-12 03:09:12 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует обращение к атрибутам объекта как к элементам массива
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Entity::offsetGet
|
|
|
|
|
* @covers \AtolOnline\Entities\Entity::offsetExists
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testOffsetGetExists(): void
|
|
|
|
|
{
|
|
|
|
|
$client = new Client('John Doe');
|
2022-12-14 16:19:55 +00:00
|
|
|
|
$this->assertSame('John Doe', $client['name']);
|
2021-12-12 03:09:12 +00:00
|
|
|
|
$this->assertTrue(isset($client['name']));
|
|
|
|
|
$this->assertFalse(isset($client['qwerty']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при попытке задать значение атрибуту объекта как элементу массива
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Entity::offsetSet
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testBadMethodCallExceptionBySet(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(BadMethodCallException::class);
|
|
|
|
|
$client = new Client('John Doe');
|
|
|
|
|
$client['name'] = 'qwerty';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Тестирует выброс исключения при попытке удалить значение атрибута объекта как элемент массива
|
|
|
|
|
*
|
|
|
|
|
* @covers \AtolOnline\Entities\Entity::offsetUnset
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function testBadMethodCallExceptionByUnset(): void
|
|
|
|
|
{
|
|
|
|
|
$this->expectException(BadMethodCallException::class);
|
|
|
|
|
$client = new Client('John Doe');
|
|
|
|
|
unset($client['name']);
|
|
|
|
|
}
|
2021-11-22 06:51:10 +00:00
|
|
|
|
}
|