Initial commit, v0.1.0-b
This commit is contained in:
131
tests/Unit/ClientTest.php
Normal file
131
tests/Unit/ClientTest.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) Антон Аксенов (aka Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use AtolOnline\{Entities\Client,
|
||||
Exceptions\AtolEmailTooLongException,
|
||||
Exceptions\AtolEmailValidateException,
|
||||
Exceptions\AtolInnWrongLengthException,
|
||||
Exceptions\AtolNameTooLongException,
|
||||
Exceptions\AtolPhoneTooLongException
|
||||
};
|
||||
|
||||
/**
|
||||
* Class ClientTest
|
||||
*/
|
||||
class ClientTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует установку параметров
|
||||
*
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$customer = new Client(
|
||||
'John Doe',
|
||||
'+1/22/99*73s dsdas654 5s6', // +122997365456
|
||||
'john@example.com',
|
||||
'+fasd3\qe3fs_=nac99013928czc' // 3399013928
|
||||
);
|
||||
$this->checkAtolEntity($customer);
|
||||
$this->assertEquals('John Doe', $customer->getName());
|
||||
$this->assertEquals('+122997365456', $customer->getPhone());
|
||||
$this->assertEquals('john@example.com', $customer->getEmail());
|
||||
$this->assertEquals('3399013928', $customer->getInn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном имени
|
||||
*
|
||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
*/
|
||||
public function testAtolNameTooLongException()
|
||||
{
|
||||
$customer = new Client();
|
||||
$this->expectException(AtolNameTooLongException::class);
|
||||
$customer->setName('John Doe John Doe John Doe John Doe John Doe '.
|
||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
||||
'Doe John Doe John Doe John Doe John DoeJohn Doe John Doe John Doe '.
|
||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
||||
'Doe John Doe John Doe John Doe John Doe John Doe John Doe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном телефоне
|
||||
*
|
||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
*/
|
||||
public function testAtolPhoneTooLongException()
|
||||
{
|
||||
$customer = new Client();
|
||||
$this->expectException(AtolPhoneTooLongException::class);
|
||||
$customer->setPhone('99999999999999999999999999999999999999999999999999999999999999999999999999');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинной почте
|
||||
*
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
*/
|
||||
public function testAtolEmailTooLongException()
|
||||
{
|
||||
$customer = new Client();
|
||||
$this->expectException(AtolEmailTooLongException::class);
|
||||
$customer->setEmail('johnjohnjohnjohnjohnjohndoedoedoedoe@exampleexampleexampleexample.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о некорректной почте
|
||||
*
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
*/
|
||||
public function testAtolEmailValidateException()
|
||||
{
|
||||
$customer = new Client();
|
||||
$this->expectException(AtolEmailValidateException::class);
|
||||
$customer->setEmail('John Doe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о некорректной длине ИНН
|
||||
*
|
||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||
*/
|
||||
public function testAtolInnWrongLengthException()
|
||||
{
|
||||
$company = new Client();
|
||||
$this->expectException(AtolInnWrongLengthException::class);
|
||||
$company->setInn('123456789');
|
||||
$company->setInn('1234567890123');
|
||||
}
|
||||
}
|
||||
110
tests/Unit/CompanyTest.php
Normal file
110
tests/Unit/CompanyTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) Антон Аксенов (aka Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use AtolOnline\{Constants\SnoTypes,
|
||||
Entities\Company,
|
||||
Exceptions\AtolEmailTooLongException,
|
||||
Exceptions\AtolEmailValidateException,
|
||||
Exceptions\AtolInnWrongLengthException,
|
||||
Exceptions\AtolPaymentAddressTooLongException
|
||||
};
|
||||
|
||||
/**
|
||||
* Class CompanyTest
|
||||
*/
|
||||
class CompanyTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует установку параметров через конструктор
|
||||
*
|
||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$company = new Company(
|
||||
SnoTypes::OSN,
|
||||
'5544332219',
|
||||
'https://v4.online.atol.ru',
|
||||
'company@example.com'
|
||||
);
|
||||
$this->checkAtolEntity($company);
|
||||
$this->assertEquals(SnoTypes::OSN, $company->getSno());
|
||||
$this->assertEquals('5544332219', $company->getInn());
|
||||
$this->assertEquals('https://v4.online.atol.ru', $company->getPaymentAddress());
|
||||
$this->assertEquals('company@example.com', $company->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о некорректной длине ИНН
|
||||
*
|
||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
||||
*/
|
||||
public function testAtolInnWrongLengthException()
|
||||
{
|
||||
$company = new Company();
|
||||
$this->expectException(AtolInnWrongLengthException::class);
|
||||
$company->setInn('321');
|
||||
$company->setInn('1234567890123');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинном платёжном адресе
|
||||
*
|
||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
*/
|
||||
public function testAtolPaymentAddressTooLongException()
|
||||
{
|
||||
$company = new Company();
|
||||
$this->expectException(AtolPaymentAddressTooLongException::class);
|
||||
$company->setPaymentAddress('John Doe John Doe John Doe John Doe '.
|
||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
||||
'Doe John Doe John Doe John Doe John DoeJohn Doe John Doe John Doe John Doe '.
|
||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
||||
'Doe John Doe John Doe John Doe John Doe');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о слишком длинной почте
|
||||
*
|
||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
||||
*/
|
||||
public function testAtolEmailTooLongException()
|
||||
{
|
||||
$company = new Company();
|
||||
$this->expectException(AtolEmailTooLongException::class);
|
||||
$company->setEmail('johnjohnjohnjohnjohnjohndoedoedoedoe@exampleexampleexampleexample.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* Тестирует исключение о некорректной почте
|
||||
*
|
||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
||||
*/
|
||||
public function testAtolEmailValidateException()
|
||||
{
|
||||
$company = new Company();
|
||||
$this->expectException(AtolEmailValidateException::class);
|
||||
$company->setEmail('John Doe');
|
||||
}
|
||||
}
|
||||
51
tests/Unit/VatTest.php
Normal file
51
tests/Unit/VatTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) Антон Аксенов (aka Anthony Axenov)
|
||||
*
|
||||
* This code is licensed under MIT.
|
||||
* Этот код распространяется по лицензии MIT.
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use AtolOnline\{Constants\VatTypes, Entities\Vat};
|
||||
|
||||
/**
|
||||
* Class VatTest
|
||||
*/
|
||||
class VatTest extends BasicTestCase
|
||||
{
|
||||
/**
|
||||
* Тестирует каждый тип ставки НДС
|
||||
*
|
||||
* @dataProvider vatProvider
|
||||
* @param string $vat_type Тип НДС
|
||||
* @param float $sum Исходная сумма
|
||||
* @param float $expected_set Ожидаемый результат после установки суммы
|
||||
* @param float $expected_add Ожидаемый результат после прибавления 20р
|
||||
*/
|
||||
public function testVat(string $vat_type, float $sum, float $expected_set, float $expected_add)
|
||||
{
|
||||
$vat = new Vat($vat_type);
|
||||
$this->assertEquals(0, $vat->getFinalSum(), 'Test '.$vat_type.' | 1 step');
|
||||
$vat->setSum($sum);
|
||||
$this->assertEquals($expected_set, $vat->getFinalSum(), 'Test '.$vat_type.' | 2 step');
|
||||
$vat->addSum(20);
|
||||
$this->assertEquals($expected_add, $vat->getFinalSum(), 'Test '.$vat_type.' | 3 step');
|
||||
$vat->addSum(-20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Провайдер данных для тестирования разных типов ставок НДС
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function vatProvider()
|
||||
{
|
||||
return [
|
||||
[VatTypes::NONE, 100, 0, 0],
|
||||
[VatTypes::VAT0, 100, 0, 0],
|
||||
[VatTypes::VAT10, 100, 10, 12],
|
||||
[VatTypes::VAT18, 100, 18, 21.6],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user