Initial commit, v0.1.0-b

This commit is contained in:
2020-01-11 14:30:25 +08:00
commit 1db2d5b49f
67 changed files with 7680 additions and 0 deletions

48
tests/BasicTestCase.php Normal file
View File

@@ -0,0 +1,48 @@
<?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\AtolEntity;
use PHPUnit\Framework\TestCase;
/**
* Class BasicTestCase
*/
class BasicTestCase extends TestCase
{
/**
*
*/
public function setUp(): void
{
//parent::setUp();
defined('ATOL_KKT_GROUP') ?: define('ATOL_KKT_GROUP', 'v4-online-atol-ru_4179');
defined('ATOL_KKT_LOGIN') ?: define('ATOL_KKT_LOGIN', 'v4-online-atol-ru');
defined('ATOL_KKT_PASS') ?: define('ATOL_KKT_PASS', 'iGFFuihss');
defined('ATOL_CALLBACK_URL') ?: define('ATOL_CALLBACK_URL', 'http://example.com/callback');
}
/**
* @param AtolOnline\Entities\AtolEntity $entity
* @return $this
*/
public function checkAtolEntity(AtolEntity $entity)
{
$this->assertJson((string)$entity);
return $this;
}
/**
*
*/
public function tearDown(): void
{
//parent::tearDown();
}
}

178
tests/Feature/ItemTest.php Normal file
View File

@@ -0,0 +1,178 @@
<?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\PaymentMethods,
Constants\PaymentObjects,
Constants\VatTypes,
Entities\Item,
Exceptions\AtolNameTooLongException,
Exceptions\AtolPriceTooHighException,
Exceptions\AtolQuantityTooHighException,
Exceptions\AtolUnitTooLongException,
Exceptions\AtolUserdataTooLongException
};
/**
* Class ItemTest
*/
class ItemTest extends BasicTestCase
{
/**
* Тестирует установку параметров через конструктор
*
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testConstructor()
{
$item = new Item(
'Банан',
65.99,
2.74,
'кг',
VatTypes::NONE,
PaymentObjects::COMMODITY,
PaymentMethods::FULL_PAYMENT
);
$this->checkAtolEntity($item);
$this->assertEquals('Банан', $item->getName());
$this->assertEquals(65.99, $item->getPrice());
$this->assertEquals(2.74, $item->getQuantity());
$this->assertEquals('кг', $item->getMeasurementUnit());
$this->assertEquals(VatTypes::NONE, $item->getVat()->getType());
$this->assertEquals(PaymentObjects::COMMODITY, $item->getPaymentObject());
$this->assertEquals(PaymentMethods::FULL_PAYMENT, $item->getPaymentMethod());
}
/**
* Тестирует установку параметров через сеттеры
*
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
* @throws AtolOnline\Exceptions\AtolUserdataTooLongException
*/
public function testSetters()
{
$item = new Item();
$item->setName('Банан');
$item->setPrice(65.99);
$item->setQuantity(2.74);
$item->setMeasurementUnit('кг');
$item->setVatType(VatTypes::NONE);
$item->setPaymentObject(PaymentObjects::COMMODITY);
$item->setPaymentMethod(PaymentMethods::FULL_PAYMENT);
$item->setUserData('Some user data');
$this->checkAtolEntity($item);
$this->assertEquals('Банан', $item->getName());
$this->assertEquals(65.99, $item->getPrice());
$this->assertEquals(2.74, $item->getQuantity());
$this->assertEquals('кг', $item->getMeasurementUnit());
$this->assertEquals(VatTypes::NONE, $item->getVat()->getType());
$this->assertEquals(PaymentObjects::COMMODITY, $item->getPaymentObject());
$this->assertEquals(PaymentMethods::FULL_PAYMENT, $item->getPaymentMethod());
$this->assertEquals('Some user data', $item->getUserData());
}
/**
* Тестирует установку ставки НДС разными путями
*
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testSetVat()
{
$item = new Item();
$item->setVatType(VatTypes::NONE);
$this->assertEquals(VatTypes::NONE, $item->getVat()->getType());
$item->setVatType(VatTypes::VAT20);
$this->assertEquals(VatTypes::VAT20, $item->getVat()->getType());
}
/**
* Тестирует исключение о слишком длинном наименовании
*
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testAtolNameTooLongException()
{
$item = new Item();
$this->expectException(AtolNameTooLongException::class);
$item->setName('Банан Банан Банан Банан Банан Банан Банан Банан Банан Банан Банан Банан');
}
/**
* Тестирует исключение о слишком высоком количестве
*
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testAtolQuantityTooHighException()
{
$item = new Item();
$this->expectException(AtolQuantityTooHighException::class);
$item->setQuantity(100000.1);
}
/**
* Тестирует исключение о слишком высокой цене
*
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testAtolPriceTooHighException()
{
$item = new Item();
$this->expectException(AtolPriceTooHighException::class);
$item->setPrice(42949673.1);
}
/**
* Тестирует исключение о слишком длинных польз. данных
*
* @throws AtolOnline\Exceptions\AtolUserdataTooLongException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testAtolUserdataTooLongException()
{
$item = new Item();
$this->expectException(AtolUserdataTooLongException::class);
$item->setUserData('User data User data User data User data User data User data User data');
}
/**
* Тестирует исключение о слишком длинной единице измерения
*
* @throws AtolOnline\Exceptions\AtolNameTooLongException
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
* @throws AtolOnline\Exceptions\AtolQuantityTooHighException
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
*/
public function testAtolUnitTooLongException()
{
$item = new Item();
$this->expectException(AtolUnitTooLongException::class);
$item->setMeasurementUnit('кг кг кг кг кг кг кг кг кг ');
}
}

131
tests/Unit/ClientTest.php Normal file
View 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
View 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
View 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],
];
}
}