2021-11-18 04:24:30 +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
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-23 17:30:54 +00:00
|
|
|
|
namespace AtolOnline\Tests\Entities;
|
2021-11-18 04:24:30 +00:00
|
|
|
|
|
|
|
|
|
use AtolOnline\{
|
|
|
|
|
Entities\Client,
|
|
|
|
|
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,
|
2021-11-24 10:55:53 +00:00
|
|
|
|
Tests\BasicTestCase};
|
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
|
|
|
|
|
{
|
2021-12-07 12:04:03 +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(email: 'john@example.com'), ['email' => 'john@example.com']);
|
|
|
|
|
$this->assertIsAtolable(new Client(phone: '+1/22/99*73s dsdas654 5s6'), ['phone' => '+122997365456']);
|
|
|
|
|
$this->assertIsAtolable(new Client(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
|
|
|
|
|
$this->assertIsAtolable(new Client(
|
2021-11-18 04:24:30 +00:00
|
|
|
|
'John Doe',
|
|
|
|
|
'john@example.com',
|
|
|
|
|
'+1/22/99*73s dsdas654 5s6', // +122997365456
|
|
|
|
|
'+fasd3\qe3fs_=nac99013928czc' // 3399013928
|
2021-11-23 17:30:54 +00:00
|
|
|
|
), [
|
2021-11-18 04:24:30 +00:00
|
|
|
|
'name' => 'John Doe',
|
|
|
|
|
'email' => 'john@example.com',
|
|
|
|
|
'phone' => '+122997365456',
|
|
|
|
|
'inn' => '3399013928',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
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();
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertEquals($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-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
|
2021-12-01 12:11:08 +00:00
|
|
|
|
* @throws InvalidPhoneException
|
2021-11-18 04:24:30 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testValidPhone(string $input, string $output): void
|
|
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertEquals($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-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
|
|
|
|
|
* @throws 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
|
|
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertEquals($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
|
|
|
|
|
{
|
2021-11-23 17:30:54 +00:00
|
|
|
|
$this->assertEquals('1234567890', (new Client())->setInn('1234567890')->getInn());
|
|
|
|
|
$this->assertEquals('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-11-22 06:51:10 +00:00
|
|
|
|
}
|