Миграция на php8.1

* enum-ы теперь enum-ы, а не говно -- теперь всё переведено на них, где это было возможно
* некоторые свойства классов объявлены в конструкторе
* некоторые классы перемещены в корневой неймспейс
* исправлен код-стайл, вычищен некоторый мусор, выправлены тесты... работы над этим продолжаются
This commit is contained in:
2022-12-15 00:19:55 +08:00
parent 692ae43f9f
commit 4157ab68f5
120 changed files with 1098 additions and 1401 deletions

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -10,7 +11,7 @@
namespace AtolOnline\Tests\Api;
use AtolOnline\{
Constants\Constraints,
Constraints,
Helpers,
TestEnvParams,
Tests\BasicTestCase};
@@ -79,12 +80,12 @@ class FiscalizerTest extends BasicTestCase
public function testGroup(): void
{
// test mode
$this->assertEquals(
$this->assertSame(
TestEnvParams::FFD105()['group'],
(new Fiscalizer(group: 'group'))->getGroup()
);
// prod mode
$this->assertEquals('group', (new Fiscalizer(false, group: 'group'))->getGroup());
$this->assertSame('group', (new Fiscalizer(false, group: 'group'))->getGroup());
$this->assertNull((new Fiscalizer(false))->getGroup());
}
@@ -164,7 +165,6 @@ class FiscalizerTest extends BasicTestCase
* @throws EmptyLoginException
* @throws EmptyPasswordException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws NegativeItemPriceException
@@ -176,12 +176,13 @@ class FiscalizerTest extends BasicTestCase
* @throws TooLongPaymentAddressException
* @throws TooManyException
* @throws GuzzleException
* @throws InvalidEnumValueException
*/
public function testSell(): void
{
$fisc_result = $this->newReceipt()->sell(new Fiscalizer());
$this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status);
$this->assertSame('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid;
}
@@ -201,7 +202,6 @@ class FiscalizerTest extends BasicTestCase
* @throws EmptyLoginException
* @throws EmptyPasswordException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws NegativeItemPriceException
@@ -213,12 +213,13 @@ class FiscalizerTest extends BasicTestCase
* @throws TooLongPaymentAddressException
* @throws TooManyException
* @throws GuzzleException
* @throws InvalidEnumValueException
*/
public function testSellRefund(): void
{
$fisc_result = $this->newReceipt()->sellRefund(new Fiscalizer());
$this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status);
$this->assertSame('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid;
}
@@ -237,7 +238,6 @@ class FiscalizerTest extends BasicTestCase
* @throws EmptyPasswordException
* @throws GuzzleException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws NegativePaymentSumException
@@ -245,12 +245,13 @@ class FiscalizerTest extends BasicTestCase
* @throws TooLongPaymentAddressException
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEnumValueException
*/
public function testSellCorrect(): void
{
$fisc_result = $this->newCorrection()->sellCorrect(new Fiscalizer());
$this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status);
$this->assertSame('wait', $fisc_result->getContent()->status);
//self::$registered_uuids[] = $fisc_result->getContent()->uuid;
}
@@ -270,7 +271,6 @@ class FiscalizerTest extends BasicTestCase
* @throws EmptyLoginException
* @throws EmptyPasswordException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws NegativeItemPriceException
@@ -282,12 +282,13 @@ class FiscalizerTest extends BasicTestCase
* @throws TooLongPaymentAddressException
* @throws TooManyException
* @throws GuzzleException
* @throws InvalidEnumValueException
*/
public function testBuy(): void
{
$fisc_result = $this->newReceipt()->buy(new Fiscalizer());
$this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status);
$this->assertSame('wait', $fisc_result->getContent()->status);
//self::$registered_uuids[] = $fisc_result->getContent()->uuid;
}
@@ -307,7 +308,6 @@ class FiscalizerTest extends BasicTestCase
* @throws EmptyLoginException
* @throws EmptyPasswordException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws NegativeItemPriceException
@@ -319,12 +319,13 @@ class FiscalizerTest extends BasicTestCase
* @throws TooLongPaymentAddressException
* @throws TooManyException
* @throws GuzzleException
* @throws InvalidEnumValueException
*/
public function testBuyRefund(): void
{
$fisc_result = $this->newReceipt()->buyRefund(new Fiscalizer());
$this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status);
$this->assertSame('wait', $fisc_result->getContent()->status);
//self::$registered_uuids[] = $fisc_result->getContent()->uuid;
}
@@ -356,7 +357,7 @@ class FiscalizerTest extends BasicTestCase
{
$fisc_result = $this->newCorrection()->buyCorrect(new Fiscalizer());
$this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status);
$this->assertSame('wait', $fisc_result->getContent()->status);
//self::$registered_uuids[] = $fisc_result->getContent()->uuid;
}
@@ -395,6 +396,6 @@ class FiscalizerTest extends BasicTestCase
{
$fisc_status = (new Fiscalizer())->pollDocumentStatus(array_shift(self::$registered_uuids));
//$this->assertTrue($fisc_status->isSuccessful());
$this->assertEquals('done', $fisc_status->getContent()->status);
$this->assertSame('done', $fisc_status->getContent()->status);
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -94,13 +95,13 @@ class MonitorTest extends BasicTestCase
public function testLogin(): void
{
$client = new Monitor(false, login: 'login');
$this->assertEquals('login', $client->getLogin());
$this->assertSame('login', $client->getLogin());
$client = new Monitor();
$this->assertEquals(TestEnvParams::FFD105()['login'], $client->getLogin());
$this->assertSame(TestEnvParams::FFD105()['login'], $client->getLogin());
$client->setLogin('login');
$this->assertEquals(TestEnvParams::FFD105()['login'], $client->getLogin());
$this->assertSame(TestEnvParams::FFD105()['login'], $client->getLogin());
}
/**
@@ -145,13 +146,13 @@ class MonitorTest extends BasicTestCase
public function testPassword(): void
{
$client = new Monitor(false, password: 'password');
$this->assertEquals('password', $client->getPassword());
$this->assertSame('password', $client->getPassword());
$client = new Monitor();
$this->assertEquals(TestEnvParams::FFD105()['password'], $client->getPassword());
$this->assertSame(TestEnvParams::FFD105()['password'], $client->getPassword());
$client->setPassword('password');
$this->assertEquals(TestEnvParams::FFD105()['password'], $client->getPassword());
$this->assertSame(TestEnvParams::FFD105()['password'], $client->getPassword());
}
/**
@@ -204,9 +205,6 @@ class MonitorTest extends BasicTestCase
$client = (new Monitor())->setTestMode();
$this->assertTrue($client->isTestMode());
$client = (new Monitor())->setTestMode(true);
$this->assertTrue($client->isTestMode());
$client = (new Monitor())->setTestMode(false);
$this->assertFalse($client->isTestMode());
}
@@ -302,7 +300,6 @@ class MonitorTest extends BasicTestCase
$client = $this->newTestClient();
$client->auth();
$kkts = $client->getAll();
$sss = $kkts->where('deviceNumber', 'KKT014034');
$this->assertNotEmpty($client->getLastResponse()->getContent());
$this->assertIsCollection($kkts);
$this->assertTrue($kkts->count() > 0);
@@ -342,6 +339,6 @@ class MonitorTest extends BasicTestCase
$this->assertIsSameClass(Kkt::class, $kkt);
$this->assertIsAtolable($kkt);
$this->assertNotNull($kkt->serialNumber);
$this->assertEquals($serial_number, $kkt->serialNumber);
$this->assertSame($serial_number, $kkt->serialNumber);
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -7,7 +8,7 @@
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace AtolOnline\Tests;
@@ -24,10 +25,10 @@ use AtolOnline\Entities\Item;
use AtolOnline\Entities\Payment;
use AtolOnline\Entities\Receipt;
use AtolOnline\Entities\Vat;
use AtolOnline\Enums\CorrectionTypes;
use AtolOnline\Enums\PaymentTypes;
use AtolOnline\Enums\SnoTypes;
use AtolOnline\Enums\VatTypes;
use AtolOnline\Enums\CorrectionType;
use AtolOnline\Enums\PaymentType;
use AtolOnline\Enums\SnoType;
use AtolOnline\Enums\VatType;
use AtolOnline\Exceptions\EmptyCorrectionNumberException;
use AtolOnline\Exceptions\EmptyItemNameException;
use AtolOnline\Exceptions\EmptyItemsException;
@@ -112,15 +113,15 @@ class BasicTestCase extends TestCase
* @covers \AtolOnline\Collections\EntityCollection::jsonSerialize
* @throws Exception
*/
public function assertIsAtolable(Entity|EntityCollection $entity, ?array $json_structure = null): void
public function assertIsAtolable(Entity | EntityCollection $entity, ?array $json_structure = []): void
{
$this->assertIsArray($entity->jsonSerialize());
$this->assertIsArray($entity->toArray());
$this->assertEquals($entity->jsonSerialize(), $entity->toArray());
$this->assertSame($entity->jsonSerialize(), $entity->toArray());
$this->assertIsString((string)$entity);
$this->assertJson((string)$entity);
if (!is_null($json_structure)) {
$this->assertEquals(json_encode($json_structure), (string)$entity);
if (!empty($json_structure)) {
$this->assertSame(json_encode($json_structure), (string)$entity);
}
}
@@ -134,7 +135,7 @@ class BasicTestCase extends TestCase
* @param object|string $expected Ожидаемый класс
* @param object|string $actual Фактический класс
*/
public function assertIsSameClass(object|string $expected, object|string $actual): void
public function assertIsSameClass(object | string $expected, object | string $actual): void
{
$this->assertTrue($this->checkisSameClass($expected, $actual));
}
@@ -146,7 +147,7 @@ class BasicTestCase extends TestCase
* @param object|string $class2
* @return bool
*/
private function checkisSameClass(object|string $class1, object|string $class2): bool
private function checkisSameClass(object | string $class1, object | string $class2): bool
{
return (is_object($class1) ? $class1::class : $class1)
=== (is_object($class2) ? $class2::class : $class2);
@@ -158,7 +159,7 @@ class BasicTestCase extends TestCase
* @param array $expected Массив ожидаемых имён классов-родителей
* @param object|string $actual Объект или имя класса для проверки
*/
public function assertExtendsClasses(array $expected, object|string $actual): void
public function assertExtendsClasses(array $expected, object | string $actual): void
{
$this->assertTrue($this->checkExtendsClasses($expected, $actual));
}
@@ -169,7 +170,7 @@ class BasicTestCase extends TestCase
* @param string[] $parents Имена классов-родителей
* @param object|string $class Объект или имя класса для проверки
*/
private function checkExtendsClasses(array $parents, object|string $class): bool
private function checkExtendsClasses(array $parents, object | string $class): bool
{
return !empty(array_intersect($parents, is_object($class) ? class_parents($class) : [$class]));
}
@@ -180,7 +181,7 @@ class BasicTestCase extends TestCase
* @param string[] $expected Массив ожидаемых имён интерфейсов
* @param object|string $actual Объект или имя класса для проверки
*/
public function assertImplementsInterfaces(array $expected, object|string $actual): void
public function assertImplementsInterfaces(array $expected, object | string $actual): void
{
$this->assertTrue($this->checkImplementsInterfaces($expected, $actual));
}
@@ -192,7 +193,7 @@ class BasicTestCase extends TestCase
* @param object|string $class Объект или имя класса для проверки
* @see https://www.php.net/manual/ru/function.class-implements.php
*/
private function checkImplementsInterfaces(array $interfaces, object|string $class): bool
private function checkImplementsInterfaces(array $interfaces, object | string $class): bool
{
return !empty(array_intersect($interfaces, is_object($class) ? class_implements($class) : [$class]));
}
@@ -203,7 +204,7 @@ class BasicTestCase extends TestCase
* @param string[] $expected Массив ожидаемых имён трейтов
* @param object|string $actual Объект или имя класса для проверки
*/
public function assertUsesTraits(array $expected, object|string $actual): void
public function assertUsesTraits(array $expected, object | string $actual): void
{
$this->assertTrue($this->checkUsesTraits($expected, $actual));
}
@@ -216,15 +217,15 @@ class BasicTestCase extends TestCase
* @return bool
* @see https://www.php.net/manual/ru/function.class-uses.php#110752
*/
private function checkUsesTraits(array $traits, object|string $class): bool
private function checkUsesTraits(array $traits, object | string $class): bool
{
$found_traits = [];
$check_class = is_object($class) ? $class::class : $class;
do {
$found_traits = array_merge(class_uses($check_class, true), $found_traits);
$found_traits = array_merge(class_uses($check_class), $found_traits);
} while ($check_class = get_parent_class($check_class));
foreach ($found_traits as $trait => $same) {
$found_traits = array_merge(class_uses($trait, true), $found_traits);
$found_traits = array_merge(class_uses($trait), $found_traits);
}
return !empty(array_intersect(array_unique($found_traits), $traits));
}
@@ -349,13 +350,11 @@ class BasicTestCase extends TestCase
* @throws TooManyException
* @throws Exception
*/
protected function generateItemObjects(int $count = 1): array
protected function generateItemObjects(int $count = 1): iterable
{
$result = [];
for ($i = 0; $i < abs($count); ++$i) {
$result[] = new Item(Helpers::randomStr(), random_int(1, 100), random_int(1, 10));
yield new Item(Helpers::randomStr(), random_int(1, 100), random_int(1, 10));
}
return $result;
}
/**
@@ -363,22 +362,19 @@ class BasicTestCase extends TestCase
*
* @param int $count
* @return Payment[]
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws Exception
*/
protected function generatePaymentObjects(int $count = 1): array
protected function generatePaymentObjects(int $count = 1): iterable
{
$types = PaymentTypes::toArray();
$result = [];
$types = PaymentType::cases();
for ($i = 0; $i < abs($count); ++$i) {
$result[] = new Payment(
array_values($types)[random_int(min($types), max($types))],
yield new Payment(
$types[random_int(0, count($types) - 1)],
random_int(1, 100) * 2 / 3
);
}
return $result;
}
/**
@@ -389,17 +385,15 @@ class BasicTestCase extends TestCase
* @throws InvalidEnumValueException
* @throws Exception
*/
protected function generateVatObjects(int $count = 1): array
protected function generateVatObjects(int $count = 1): iterable
{
$types = VatTypes::toArray();
$result = [];
$types = VatType::cases();
for ($i = 0; $i < abs($count); ++$i) {
$result[] = new Vat(
array_values($types)[random_int(0, count($types) - 1)],
yield new Vat(
$types[random_int(0, count($types) - 1)],
random_int(1, 100) * 2 / 3
);
}
return $result;
}
/**
@@ -409,7 +403,6 @@ class BasicTestCase extends TestCase
* @throws EmptyItemNameException
* @throws EmptyItemsException
* @throws InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws NegativePaymentSumException
@@ -421,8 +414,8 @@ class BasicTestCase extends TestCase
protected function newReceipt(): Receipt
{
return new Receipt(
new Client('John Doe', 'john@example.com', '+79501234567', '1234567890'),
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new Client('John Doe', '+79501234567', 'john@example.com', '1234567890'),
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
new Items($this->generateItemObjects(2)),
new Payments($this->generatePaymentObjects())
);
@@ -442,8 +435,8 @@ class BasicTestCase extends TestCase
protected function newCorrection(): Correction
{
return new Correction(
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new CorrectionInfo(CorrectionTypes::SELF, '01.01.2021', Helpers::randomStr()),
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
new CorrectionInfo(CorrectionType::SELF, '01.01.2021', Helpers::randomStr()),
new Payments($this->generatePaymentObjects(2)),
new Vats($this->generateVatObjects(2)),
);

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -11,7 +12,7 @@ namespace AtolOnline\Tests\Collections;
use AtolOnline\{
Collections\Items,
Constants\Constraints,
Constraints,
Tests\BasicTestCase};
use AtolOnline\Exceptions\{
EmptyItemNameException,

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -11,10 +12,9 @@ namespace AtolOnline\Tests\Collections;
use AtolOnline\{
Collections\Payments,
Constants\Constraints,
Constraints,
Exceptions\EmptyPaymentsException,
Exceptions\InvalidEntityInCollectionException,
Exceptions\InvalidEnumValueException,
Exceptions\NegativePaymentSumException,
Exceptions\TooHighPaymentSumException,
Exceptions\TooManyPaymentsException,
@@ -31,7 +31,6 @@ class PaymentsTest extends BasicTestCase
* @covers \AtolOnline\Collections\EntityCollection
* @covers \AtolOnline\Collections\EntityCollection::checkCount
* @covers \AtolOnline\Exceptions\TooManyPaymentsException
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws InvalidEntityInCollectionException

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -11,9 +12,9 @@ namespace AtolOnline\Tests\Collections;
use AtolOnline\{
Collections\Vats,
Constants\Constraints,
Constraints,
Entities\Payment,
Enums\PaymentTypes,
Enums\PaymentType,
Exceptions\EmptyVatsException,
Exceptions\InvalidEntityInCollectionException,
Exceptions\InvalidEnumValueException,
@@ -42,7 +43,7 @@ class VatsTest extends BasicTestCase
{
$vats = new Vats($this->generateVatObjects(3));
$this->assertIsCollection($vats);
$this->assertEquals(3, $vats->count());
$this->assertSame(3, $vats->count());
$this->assertIsAtolable($vats);
}
@@ -89,6 +90,7 @@ class VatsTest extends BasicTestCase
* @covers \AtolOnline\Exceptions\InvalidEntityInCollectionException
* @throws InvalidEnumValueException
* @throws Exception
* @noinspection PhpParamsInspection
*/
public function testInvalidCollectionItemExceptionScalar(): void
{
@@ -115,7 +117,7 @@ class VatsTest extends BasicTestCase
$this->expectException(InvalidEntityInCollectionException::class);
$this->expectExceptionMessage(Payment::class);
(new Vats($this->generateVatObjects()))
->merge([new Payment(PaymentTypes::PREPAID, 1)])
->merge([new Payment(PaymentType::PREPAID, 1)])
->jsonSerialize();
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -10,7 +11,7 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Constants\Constraints,
Constraints,
Entities\AdditionalUserProps,
Exceptions\EmptyAddUserPropNameException,
Exceptions\EmptyAddUserPropValueException,

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -14,8 +15,7 @@ use AtolOnline\{
Entities\MoneyTransferOperator,
Entities\PayingAgent,
Entities\ReceivePaymentsOperator,
Enums\AgentTypes,
Exceptions\InvalidEnumValueException,
Enums\AgentType,
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPhoneException,
Exceptions\TooLongPayingAgentOperationException,
@@ -36,7 +36,7 @@ class AgentInfoTest extends BasicTestCase
*/
public function testConstructorWithoutArgs(): void
{
$this->assertIsAtolable(new AgentInfo(), []);
$this->assertIsAtolable(new AgentInfo());
}
/**
@@ -58,63 +58,64 @@ class AgentInfoTest extends BasicTestCase
* @throws InvalidPhoneException
* @throws TooLongPayingAgentOperationException
* @throws InvalidInnLengthException
* @throws InvalidEnumValueException
* @throws Exception
*/
public function testConstructorWithArgs(): void
{
$this->assertIsAtolable(new AgentInfo(null), []);
$this->assertIsAtolable(new AgentInfo(AgentTypes::ANOTHER), ['type' => AgentTypes::ANOTHER]);
$this->assertIsAtolable(new AgentInfo(pagent: new PayingAgent()), []);
$this->assertIsAtolable(new AgentInfo(mt_operator: new MoneyTransferOperator()), []);
$this->assertIsAtolable(new AgentInfo(rp_operator: new ReceivePaymentsOperator()), []);
$this->assertIsAtolable(new AgentInfo(null));
$this->assertIsAtolable(
new AgentInfo(AgentType::ANOTHER),
['type' => AgentType::ANOTHER]
);
$this->assertIsAtolable(
new AgentInfo(payingAgent: new PayingAgent())
);
$this->assertIsAtolable(
new AgentInfo(moneyTransferOperator: new MoneyTransferOperator())
);
$this->assertIsAtolable(
new AgentInfo(receivePaymentsOperator: new ReceivePaymentsOperator())
);
$this->assertIsAtolable(new AgentInfo(
AgentTypes::ANOTHER,
new PayingAgent(),
new ReceivePaymentsOperator(),
new MoneyTransferOperator(),
), ['type' => AgentTypes::ANOTHER]);
$this->assertIsAtolable(
new AgentInfo(
AgentType::ANOTHER,
new PayingAgent(),
new ReceivePaymentsOperator(),
new MoneyTransferOperator(),
),
['type' => AgentType::ANOTHER]
);
$this->assertIsAtolable(new AgentInfo(
AgentTypes::ANOTHER,
new PayingAgent('test', ['+79518888888']),
new ReceivePaymentsOperator(['+79519999999']),
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
), [
'type' => AgentTypes::ANOTHER,
'paying_agent' => [
'operation' => 'test',
'phones' => [
'+79518888888',
$this->assertIsAtolable(
new AgentInfo(
AgentType::ANOTHER,
new PayingAgent('test', ['+79518888888']),
new ReceivePaymentsOperator(['+79519999999']),
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
),
[
'type' => AgentType::ANOTHER,
'paying_agent' => [
'operation' => 'test',
'phones' => [
'+79518888888',
],
],
],
'receive_payments_operator' => [
'phones' => [
'+79519999999',
'receive_payments_operator' => [
'phones' => [
'+79519999999',
],
],
],
'money_transfer_operator' => [
'name' => 'MTO Name',
'inn' => '9876543210',
'address' => 'London',
'phones' => [
"+79517777777",
'money_transfer_operator' => [
'name' => 'MTO Name',
'inn' => '9876543210',
'address' => 'London',
'phones' => [
'+79517777777',
],
],
],
]);
}
/**
* Тестирует исключение при некорректном типе
*
* @covers \AtolOnline\Entities\AgentInfo
* @covers \AtolOnline\Enums\AgentTypes::isValid
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
*/
public function testInvalidEnumValueException(): void
{
$this->expectException(InvalidEnumValueException::class);
new AgentInfo('qwerty');
]
);
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -9,15 +10,15 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{Entities\Client,
use AtolOnline\{
Entities\Client,
Exceptions\InvalidEmailException,
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPhoneException,
Exceptions\TooLongClientNameException,
Exceptions\TooLongEmailException,
Helpers,
Tests\BasicTestCase
};
Tests\BasicTestCase};
use BadMethodCallException;
use Exception;
@@ -35,7 +36,7 @@ class ClientTest extends BasicTestCase
*/
public function testConstructorWithoutArgs(): void
{
$this->assertIsAtolable(new Client(), []);
$this->assertIsAtolable(new Client());
}
/**
@@ -56,19 +57,20 @@ class ClientTest extends BasicTestCase
public function testConstructorWithArgs(): void
{
$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(email: 'john@example.com'), ['email' => 'john@example.com']);
$this->assertIsAtolable(new Client(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
$this->assertIsAtolable(
new Client(
'John Doe',
'john@example.com',
'+1/22/99*73s dsdas654 5s6', // +122997365456
'john@example.com',
'+fasd3\qe3fs_=nac99013928czc' // 3399013928
), [
),
[
'name' => 'John Doe',
'email' => 'john@example.com',
'phone' => '+122997365456',
'email' => 'john@example.com',
'inn' => '3399013928',
]
);
@@ -100,7 +102,7 @@ class ClientTest extends BasicTestCase
public function testValidName(): void
{
$name = Helpers::randomStr();
$this->assertEquals($name, (new Client())->setName($name)->getName());
$this->assertSame($name, (new Client())->setName($name)->getName());
}
/**
@@ -143,7 +145,7 @@ class ClientTest extends BasicTestCase
*/
public function testValidPhone(string $input, string $output): void
{
$this->assertEquals($output, (new Client())->setPhone($input)->getPhone());
$this->assertSame($output, (new Client())->setPhone($input)->getPhone());
}
/**
@@ -174,7 +176,7 @@ class ClientTest extends BasicTestCase
*/
public function testValidEmails(mixed $email): void
{
$this->assertEquals($email, (new Client())->setEmail($email)->getEmail());
$this->assertSame($email, (new Client())->setEmail($email)->getEmail());
}
/**
@@ -219,8 +221,8 @@ class ClientTest extends BasicTestCase
*/
public function testValidInn(): void
{
$this->assertEquals('1234567890', (new Client())->setInn('1234567890')->getInn());
$this->assertEquals('123456789012', (new Client())->setInn('123456789012')->getInn());
$this->assertSame('1234567890', (new Client())->setInn('1234567890')->getInn());
$this->assertSame('123456789012', (new Client())->setInn('123456789012')->getInn());
}
/**
@@ -261,7 +263,7 @@ class ClientTest extends BasicTestCase
public function testOffsetGetExists(): void
{
$client = new Client('John Doe');
$this->assertEquals('John Doe', $client['name']);
$this->assertSame('John Doe', $client['name']);
$this->assertTrue(isset($client['name']));
$this->assertFalse(isset($client['qwerty']));
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -11,9 +12,8 @@ namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Entities\Company,
Enums\SnoTypes,
Enums\SnoType,
Exceptions\InvalidEmailException,
Exceptions\InvalidEnumValueException,
Exceptions\InvalidInnLengthException,
Exceptions\InvalidPaymentAddressException,
Exceptions\TooLongEmailException,
@@ -44,17 +44,20 @@ class CompanyTest extends BasicTestCase
*/
public function testConstructor()
{
$this->assertIsAtolable(new Company(
$email = 'company@example.com',
$sno = SnoTypes::OSN,
$inn = '1234567890',
$payment_address = 'https://example.com',
), [
'email' => $email,
'sno' => $sno,
'inn' => $inn,
'payment_address' => $payment_address,
]);
$this->assertIsAtolable(
new Company(
$inn = '1234567890',
$sno = SnoType::OSN,
$paymentAddress = 'https://example.com',
$email = 'company@example.com',
),
[
'inn' => $inn,
'sno' => $sno,
'payment_address' => $paymentAddress,
'email' => $email,
]
);
}
/**
@@ -64,7 +67,6 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company::setEmail
* @covers \AtolOnline\Exceptions\TooLongEmailException
* @throws InvalidEmailException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws TooLongEmailException
@@ -73,7 +75,7 @@ class CompanyTest extends BasicTestCase
public function testEmailTooLongException()
{
$this->expectException(TooLongEmailException::class);
new Company(Helpers::randomStr(65), SnoTypes::OSN, '1234567890', 'https://example.com');
new Company('1234567890', SnoType::OSN, 'https://example.com', Helpers::randomStr(65));
}
/**
@@ -86,20 +88,7 @@ class CompanyTest extends BasicTestCase
public function testInvalidEmailException()
{
$this->expectException(InvalidEmailException::class);
new Company('company@examas%^*.com', SnoTypes::OSN, '1234567890', 'https://example.com');
}
/**
* Тестирует исключение о слишком длинном платёжном адресе
*
* @covers \AtolOnline\Entities\Company
* @covers \AtolOnline\Entities\Company::setSno
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
*/
public function testInvalidSnoException()
{
$this->expectException(InvalidEnumValueException::class);
new Company('company@example.com', 'test', '1234567890', 'https://example.com');
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@examas%^*.com');
}
/**
@@ -109,7 +98,6 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company::setInn
* @covers \AtolOnline\Exceptions\InvalidInnLengthException
* @throws InvalidEmailException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws TooLongEmailException
@@ -118,7 +106,7 @@ class CompanyTest extends BasicTestCase
public function testInvalidInnLengthException()
{
$this->expectException(InvalidInnLengthException::class);
new Company('company@example.com', SnoTypes::OSN, Helpers::randomStr(13), 'https://example.com');
new Company(Helpers::randomStr(13), SnoType::OSN, 'https://example.com', 'company@example.com');
}
/**
@@ -128,7 +116,6 @@ class CompanyTest extends BasicTestCase
* @covers \AtolOnline\Entities\Company::setPaymentAddress
* @covers \AtolOnline\Exceptions\TooLongPaymentAddressException
* @throws InvalidEmailException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPaymentAddressException
* @throws TooLongEmailException
@@ -137,7 +124,7 @@ class CompanyTest extends BasicTestCase
public function testTooLongPaymentAddressException()
{
$this->expectException(TooLongPaymentAddressException::class);
new Company('company@example.com', SnoTypes::OSN, '1234567890', Helpers::randomStr(257));
new Company('1234567890', SnoType::OSN, Helpers::randomStr(257), 'company@example.com');
}
/**
@@ -150,6 +137,6 @@ class CompanyTest extends BasicTestCase
public function testInvalidPaymentAddressException()
{
$this->expectException(InvalidPaymentAddressException::class);
new Company('company@example.com', SnoTypes::OSN, '1234567890', '');
new Company('1234567890', SnoType::OSN, '', 'company@example.com');
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -11,12 +12,13 @@ namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Entities\CorrectionInfo,
Enums\CorrectionTypes,
Enums\CorrectionType,
Exceptions\EmptyCorrectionNumberException,
Exceptions\InvalidCorrectionDateException,
Exceptions\InvalidEnumValueException,
Helpers,
Tests\BasicTestCase};
use DateTime;
use DateTimeImmutable;
use Exception;
/**
@@ -36,7 +38,6 @@ class CorrectionInfoTest extends BasicTestCase
* @covers \AtolOnline\Entities\CorrectionInfo::getNumber
* @covers \AtolOnline\Entities\CorrectionInfo::jsonSerialize
* @return void
* @throws InvalidEnumValueException
* @throws InvalidCorrectionDateException
* @throws EmptyCorrectionNumberException
* @throws Exception
@@ -44,32 +45,35 @@ class CorrectionInfoTest extends BasicTestCase
public function testConstructor(): void
{
$this->assertIsAtolable(
new CorrectionInfo(CorrectionTypes::SELF, '01.01.2021', $number = Helpers::randomStr()),
new CorrectionInfo(CorrectionType::SELF, '01.01.2021', $number = Helpers::randomStr()),
[
'type' => CorrectionTypes::SELF,
'type' => CorrectionType::SELF,
'base_date' => '01.01.2021',
'base_number' => $number,
]
);
}
/**
* Тестирует исключение при некорректном типе
*
* @covers \AtolOnline\Entities\CorrectionInfo
* @covers \AtolOnline\Entities\CorrectionInfo::setType
* @covers \AtolOnline\Enums\CorrectionTypes::isValid
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
* @return void
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEnumValueException
*/
public function testInvalidEnumValueException(): void
{
$this->expectException(InvalidEnumValueException::class);
$this->expectExceptionMessage('Некорректное значение AtolOnline\Enums\CorrectionTypes::wrong_value');
new CorrectionInfo('wrong_value', '01.01.2021', Helpers::randomStr());
$this->assertIsAtolable(
new CorrectionInfo(CorrectionType::SELF, new DateTime('02.02.2022'), $number = Helpers::randomStr()),
[
'type' => CorrectionType::SELF,
'base_date' => '02.02.2022',
'base_number' => $number,
]
);
$this->assertIsAtolable(
new CorrectionInfo(
CorrectionType::SELF,
new DateTimeImmutable('03.03.2023'),
$number = Helpers::randomStr()
),
[
'type' => CorrectionType::SELF,
'base_date' => '03.03.2023',
'base_number' => $number,
]
);
}
/**
@@ -77,17 +81,15 @@ class CorrectionInfoTest extends BasicTestCase
*
* @covers \AtolOnline\Entities\CorrectionInfo
* @covers \AtolOnline\Entities\CorrectionInfo::setDate
* @covers \AtolOnline\Enums\CorrectionTypes::isValid
* @covers \AtolOnline\Exceptions\InvalidCorrectionDateException
* @return void
* @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException
* @throws InvalidEnumValueException
*/
public function testInvalidCorrectionDateException(): void
{
$this->expectException(InvalidCorrectionDateException::class);
new CorrectionInfo(CorrectionTypes::SELF, Helpers::randomStr(), Helpers::randomStr());
new CorrectionInfo(CorrectionType::SELF, Helpers::randomStr(), Helpers::randomStr());
}
/**
@@ -95,13 +97,12 @@ class CorrectionInfoTest extends BasicTestCase
*
* @covers \AtolOnline\Entities\CorrectionInfo
* @covers \AtolOnline\Entities\CorrectionInfo::setNumber
* @covers \AtolOnline\Enums\CorrectionTypes::isValid
* @covers \AtolOnline\Exceptions\EmptyCorrectionNumberException
* @return void
*/
public function testEmptyCorrectionNumberException(): void
{
$this->expectException(EmptyCorrectionNumberException::class);
new CorrectionInfo(CorrectionTypes::SELF, '01.01.2021', "\n\r\t\0");
new CorrectionInfo(CorrectionType::SELF, '01.01.2021', "\n\r\t\0");
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -10,7 +11,7 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Constants\Constraints,
Constraints,
Helpers,
Tests\BasicTestCase};
use AtolOnline\Exceptions\{
@@ -71,7 +72,7 @@ class CorrectionTest extends BasicTestCase
{
$correction = $this->newCorrection()->setCashier(Helpers::randomStr());
$this->assertArrayHasKey('cashier', $correction->jsonSerialize());
$this->assertEquals($correction->getCashier(), $correction->jsonSerialize()['cashier']);
$this->assertSame($correction->getCashier(), $correction->jsonSerialize()['cashier']);
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -10,38 +11,40 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Constants\Constraints,
Entities\AgentInfo,
Entities\Item,
Entities\MoneyTransferOperator,
Entities\PayingAgent,
Entities\ReceivePaymentsOperator,
Entities\Supplier,
Entities\Vat,
Enums\AgentTypes,
Enums\PaymentMethods,
Enums\PaymentObjects,
Enums\VatTypes,
Exceptions\EmptyItemNameException,
Exceptions\InvalidDeclarationNumberException,
Exceptions\InvalidEnumValueException,
Exceptions\InvalidInnLengthException,
Exceptions\InvalidOKSMCodeException,
Exceptions\InvalidPhoneException,
Exceptions\NegativeItemExciseException,
Exceptions\NegativeItemPriceException,
Exceptions\NegativeItemQuantityException,
Exceptions\TooHighItemPriceException,
Exceptions\TooHighItemQuantityException,
Exceptions\TooHighItemSumException,
Exceptions\TooLongItemCodeException,
Exceptions\TooLongItemNameException,
Exceptions\TooLongMeasurementUnitException,
Exceptions\TooLongPayingAgentOperationException,
Exceptions\TooLongUserdataException,
Exceptions\TooManyException,
Constraints,
Helpers,
Tests\BasicTestCase};
use AtolOnline\Entities\{
AgentInfo,
Item,
MoneyTransferOperator,
PayingAgent,
ReceivePaymentsOperator,
Supplier,
Vat,};
use AtolOnline\Enums\{
AgentType,
PaymentMethod,
PaymentObject,
VatType,};
use AtolOnline\Exceptions\{
EmptyItemNameException,
InvalidDeclarationNumberException,
InvalidInnLengthException,
InvalidOKSMCodeException,
InvalidPhoneException,
NegativeItemExciseException,
NegativeItemPriceException,
NegativeItemQuantityException,
TooHighItemPriceException,
TooHighItemQuantityException,
TooHighItemSumException,
TooLongItemCodeException,
TooLongItemNameException,
TooLongMeasurementUnitException,
TooLongPayingAgentOperationException,
TooLongUserdataException,
TooManyException,};
use Exception;
/**
@@ -258,7 +261,6 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getPaymentObject
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws TooManyException
* @throws NegativeItemPriceException
* @throws TooHighItemPriceException
@@ -269,13 +271,13 @@ class ItemTest extends BasicTestCase
public function testValidEnums(): void
{
$item = new Item('test item', 2, 3);
$this->assertEquals(
PaymentMethods::ADVANCE,
$item->setPaymentMethod(PaymentMethods::ADVANCE)->getPaymentMethod()
$this->assertSame(
PaymentMethod::ADVANCE,
$item->setPaymentMethod(PaymentMethod::ADVANCE)->getPaymentMethod()
);
$this->assertEquals(
PaymentObjects::COMMODITY,
$item->setPaymentObject(PaymentObjects::COMMODITY)->getPaymentObject()
$this->assertSame(
PaymentObject::COMMODITY,
$item->setPaymentObject(PaymentObject::COMMODITY)->getPaymentObject()
);
$this->assertIsAtolable($item, [
'name' => 'test item',
@@ -287,80 +289,6 @@ class ItemTest extends BasicTestCase
]);
}
/**
* Тестирует установку невалидного способа оплаты
*
* @covers \AtolOnline\Entities\Item::setPaymentMethod
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws TooManyException
* @throws NegativeItemPriceException
* @throws TooHighItemPriceException
* @throws NegativeItemQuantityException
* @throws TooLongItemNameException
*/
public function testInvalidPaymentMethod(): void
{
$this->expectException(InvalidEnumValueException::class);
$this->expectExceptionMessage('Некорректное значение AtolOnline\Enums\PaymentMethods::wrong_value');
(new Item('test item', 2, 3))->setPaymentMethod('wrong_value');
}
/**
* Тестирует установку невалидного предмета расчёта
*
* @covers \AtolOnline\Entities\Item::setPaymentObject
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws TooManyException
* @throws NegativeItemPriceException
* @throws TooHighItemPriceException
* @throws NegativeItemQuantityException
* @throws TooLongItemNameException
*/
public function testInvalidPaymentObject(): void
{
$this->expectException(InvalidEnumValueException::class);
$this->expectExceptionMessage('Некорректное значение AtolOnline\Enums\PaymentObjects::wrong_value');
(new Item('test item', 2, 3))->setPaymentObject('wrong_value');
}
/**
* Тестирует установку ставки НДС по строковой константе типа ставки
*
* @covers \AtolOnline\Entities\Item::setVat
* @covers \AtolOnline\Entities\Item::getVat
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighItemPriceException
* @throws TooHighItemSumException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws Exception
*/
public function testValidVatByString(): void
{
$item = (new Item('test item', 2, 3))->setVat(VatTypes::VAT20);
$this->assertIsSameClass(Vat::class, $item->getVat());
$this->assertEquals(VatTypes::VAT20, $item->getVat()->getType());
$this->assertEquals($item->getSum(), $item->getVat()->getSum());
$this->assertIsAtolable($item, [
'name' => 'test item',
'price' => 2,
'quantity' => 3,
'sum' => 6,
'vat' => [
'type' => 'vat20',
'sum' => 1.2,
],
]);
}
/**
* Тестирует установку ставки НДС объектом
*
@@ -368,7 +296,6 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getVat
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighItemPriceException
@@ -379,11 +306,11 @@ class ItemTest extends BasicTestCase
*/
public function testValidVatByObject(): void
{
$vat = new Vat(VatTypes::VAT20, 4000);
$vat = new Vat(VatType::VAT20, 4000);
$item = (new Item('test item', 2, 3))->setVat($vat);
$this->assertIsSameClass(Vat::class, $item->getVat());
$this->assertEquals(VatTypes::VAT20, $item->getVat()->getType());
$this->assertEquals($item->getSum(), $item->getVat()->getSum());
$this->assertSame(VatType::VAT20, $item->getVat()->getType());
$this->assertSame($item->getSum(), $item->getVat()->getSum());
$this->assertIsAtolable($item, [
'name' => 'test item',
'price' => 2,
@@ -396,28 +323,6 @@ class ItemTest extends BasicTestCase
]);
}
/**
* Тестирует обнуление ставки НДС
*
* @param mixed $vat
* @dataProvider providerNullableStrings
* @covers \AtolOnline\Entities\Item::setVat
* @covers \AtolOnline\Entities\Item::getVat
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws NegativeItemPriceException
* @throws NegativeItemQuantityException
* @throws TooHighItemPriceException
* @throws TooLongItemNameException
* @throws TooManyException
* @throws InvalidEnumValueException
*/
public function testNullableVatByString(mixed $vat): void
{
$item = (new Item('test item', 2, 3))->setVat($vat);
$this->assertNull($item->getVat());
}
/**
* Тестирует установку атрибутов агента
*
@@ -425,7 +330,6 @@ class ItemTest extends BasicTestCase
* @covers \AtolOnline\Entities\Item::getAgentInfo
* @covers \AtolOnline\Entities\Item::jsonSerialize
* @throws EmptyItemNameException
* @throws InvalidEnumValueException
* @throws InvalidInnLengthException
* @throws InvalidPhoneException
* @throws NegativeItemPriceException
@@ -438,13 +342,13 @@ class ItemTest extends BasicTestCase
public function testAgentInfo(): void
{
$agent_info = new AgentInfo(
AgentTypes::ANOTHER,
AgentType::ANOTHER,
new PayingAgent('test', ['+79518888888']),
new ReceivePaymentsOperator(['+79519999999']),
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
);
$item = (new Item('test item', 2, 3))->setAgentInfo($agent_info);
$this->assertEquals($agent_info, $item->getAgentInfo());
$this->assertSame($agent_info, $item->getAgentInfo());
}
/**
@@ -471,7 +375,7 @@ class ItemTest extends BasicTestCase
['+122997365456'],
);
$item = (new Item('test item', 2, 3))->setSupplier($supplier);
$this->assertEquals($supplier, $item->getSupplier());
$this->assertSame($supplier, $item->getSupplier());
$this->assertIsAtolable($item, [
'name' => 'test item',
'price' => 2,
@@ -744,11 +648,11 @@ class ItemTest extends BasicTestCase
$encoded = trim(preg_replace('/([\dA-Fa-f]{2})/', '$1 ', bin2hex($code)));
$item = (new Item('test item', 2, 3))->setCode($code);
$this->assertEquals($code, $item->getCode());
$this->assertEquals($encoded, $item->getCodeHex());
$this->assertSame($code, $item->getCode());
$this->assertSame($encoded, $item->getCodeHex());
$decoded = hex2bin(str_replace(' ', '', $item->getCodeHex()));
$this->assertEquals($decoded, $item->getCode());
$this->assertSame($decoded, $item->getCode());
$this->assertIsAtolable($item, [
'name' => 'test item',

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -7,7 +8,7 @@
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace AtolOnline\Tests\Entities;
@@ -85,9 +86,11 @@ class KktEntityTest extends BasicTestCase
public function testNotEnoughMonitorDataException(): void
{
$this->expectException(NotEnoughMonitorDataException::class);
new Kkt((object)[
'fiscalizationDate' => '2021-11-20T10:21:00+00:00',
]);
new Kkt(
(object)[
'fiscalizationDate' => '2021-11-20T10:21:00+00:00',
]
);
}
/**
@@ -104,7 +107,7 @@ class KktEntityTest extends BasicTestCase
// string
$this->assertNotNull($kkt->serialNumber);
$this->assertIsString($kkt->serialNumber);
$this->assertEquals($this->sample_data['serialNumber'], $kkt->serialNumber);
$this->assertSame($this->sample_data['serialNumber'], $kkt->serialNumber);
// int
$this->assertNotNull($kkt->signedDocuments);

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -29,7 +30,7 @@ class MoneyTransferOperatorTest extends BasicTestCase
*/
public function testConstructorWithoutArgs(): void
{
$this->assertEquals('[]', (string)(new MoneyTransferOperator()));
$this->assertSame('[]', (string)(new MoneyTransferOperator()));
}
/**
@@ -52,20 +53,26 @@ class MoneyTransferOperatorTest extends BasicTestCase
public function testConstructorWithArgs(): void
{
$this->assertIsAtolable(new MoneyTransferOperator('some name'), ['name' => 'some name']);
$this->assertIsAtolable(new MoneyTransferOperator(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
$this->assertIsAtolable(
new MoneyTransferOperator(inn: '+fasd3\qe3fs_=nac99013928czc'),
['inn' => '3399013928']
);
$this->assertIsAtolable(new MoneyTransferOperator(address: 'London'), ['address' => 'London']);
$this->assertIsAtolable(new MoneyTransferOperator(phones: ['+122997365456']), ['phones' => ['+122997365456']]);
$this->assertIsAtolable(new MoneyTransferOperator(
'some name',
'+fasd3\qe3fs_=nac99013928czc',
'London',
['+122997365456'],
), [
'name' => 'some name',
'inn' => '3399013928',
'address' => 'London',
'phones' => ['+122997365456'],
]);
$this->assertIsAtolable(
new MoneyTransferOperator(
'some name',
'+fasd3\qe3fs_=nac99013928czc',
'London',
['+122997365456'],
),
[
'name' => 'some name',
'inn' => '3399013928',
'address' => 'London',
'phones' => ['+122997365456'],
]
);
}
/**
@@ -145,8 +152,8 @@ class MoneyTransferOperatorTest extends BasicTestCase
*/
public function testValidInn(): void
{
$this->assertEquals('1234567890', (new MoneyTransferOperator())->setInn('1234567890')->getInn());
$this->assertEquals('123456789012', (new MoneyTransferOperator())->setInn('123456789012')->getInn());
$this->assertSame('1234567890', (new MoneyTransferOperator())->setInn('1234567890')->getInn());
$this->assertSame('123456789012', (new MoneyTransferOperator())->setInn('123456789012')->getInn());
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -30,7 +31,7 @@ class PayingAgentTest extends BasicTestCase
*/
public function testConstructorWithoutArgs(): void
{
$this->assertEquals('[]', (string)(new PayingAgent()));
$this->assertSame('[]', (string)(new PayingAgent()));
}
/**
@@ -49,13 +50,16 @@ class PayingAgentTest extends BasicTestCase
public function testConstructorWithArgs(): void
{
$operation = Helpers::randomStr();
$this->assertIsAtolable(new PayingAgent(
$operation,
['+122997365456'],
), [
'operation' => $operation,
'phones' => ['+122997365456'],
]);
$this->assertIsAtolable(
new PayingAgent(
$operation,
['+122997365456'],
),
[
'operation' => $operation,
'phones' => ['+122997365456'],
]
);
$this->assertIsAtolable(
new PayingAgent($operation),
['operation' => $operation]

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -10,12 +11,11 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Constants\Constraints,
Constraints,
Entities\Payment,
Enums\PaymentTypes,
Enums\PaymentType,
Tests\BasicTestCase};
use AtolOnline\Exceptions\{
InvalidEnumValueException,
NegativePaymentSumException,
TooHighPaymentSumException,};
use Exception;
@@ -35,7 +35,6 @@ class PaymentTest extends BasicTestCase
* @covers \AtolOnline\Entities\Payment::getSum
* @covers \AtolOnline\Entities\Payment::jsonSerialize
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
* @throws Exception
@@ -43,33 +42,14 @@ class PaymentTest extends BasicTestCase
public function testConstructor(): void
{
$this->assertIsAtolable(
new Payment(PaymentTypes::ELECTRON, 123.456789),
new Payment(PaymentType::ELECTRON, 123.456789),
[
'type' => PaymentTypes::ELECTRON,
'type' => PaymentType::ELECTRON,
'sum' => 123.46,
]
);
}
/**
* Тестирует исключение при некорректном типе
*
* @covers \AtolOnline\Entities\Payment
* @covers \AtolOnline\Entities\Payment::setType
* @covers \AtolOnline\Enums\PaymentTypes::isValid
* @covers \AtolOnline\Exceptions\InvalidEnumValueException
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testInvalidEnumValueException(): void
{
$this->expectException(InvalidEnumValueException::class);
$this->expectExceptionMessage('Некорректное значение AtolOnline\Enums\PaymentTypes::123');
new Payment(123, 123.456789);
}
/**
* Тестирует исключение при слишком большой сумме
*
@@ -77,13 +57,12 @@ class PaymentTest extends BasicTestCase
* @covers \AtolOnline\Entities\Payment::setSum
* @covers \AtolOnline\Exceptions\TooHighPaymentSumException
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
*/
public function testTooHighPaymentSumException(): void
{
$this->expectException(TooHighPaymentSumException::class);
new Payment(PaymentTypes::ELECTRON, Constraints::MAX_COUNT_PAYMENT_SUM + 1);
new Payment(PaymentType::ELECTRON, Constraints::MAX_COUNT_PAYMENT_SUM + 1);
}
/**
@@ -93,13 +72,12 @@ class PaymentTest extends BasicTestCase
* @covers \AtolOnline\Entities\Payment::setSum
* @covers \AtolOnline\Exceptions\NegativePaymentSumException
* @return void
* @throws InvalidEnumValueException
* @throws NegativePaymentSumException
* @throws TooHighPaymentSumException
*/
public function testNegativePaymentSumException(): void
{
$this->expectException(NegativePaymentSumException::class);
new Payment(PaymentTypes::ELECTRON, -1);
new Payment(PaymentType::ELECTRON, -1);
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -10,7 +11,7 @@
namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Constants\Constraints,
Constraints,
Helpers,
Tests\BasicTestCase};
use AtolOnline\Collections\{
@@ -30,8 +31,8 @@ use AtolOnline\Entities\{
Supplier,
Vat,};
use AtolOnline\Enums\{
AgentTypes,
SnoTypes,};
AgentType,
SnoType,};
use AtolOnline\Exceptions\{
EmptyItemNameException,
EmptyItemsException,
@@ -120,14 +121,14 @@ class ReceiptTest extends BasicTestCase
public function testAgentInfo(): void
{
$agent_info = new AgentInfo(
AgentTypes::ANOTHER,
AgentType::ANOTHER,
new PayingAgent('test', ['+79518888888']),
new ReceivePaymentsOperator(['+79519999999']),
new MoneyTransferOperator('MTO Name', '9876543210', 'London', ['+79517777777']),
);
$receipt = $this->newReceipt()->setAgentInfo($agent_info);
$this->assertArrayHasKey('agent_info', $receipt->jsonSerialize());
$this->assertEquals($receipt->getAgentInfo()->jsonSerialize(), $receipt->jsonSerialize()['agent_info']);
$this->assertSame($receipt->getAgentInfo()->jsonSerialize(), $receipt->jsonSerialize()['agent_info']);
$this->assertArrayNotHasKey('agent_info', $receipt->setAgentInfo(null)->jsonSerialize());
}
@@ -159,7 +160,7 @@ class ReceiptTest extends BasicTestCase
$supplier = new Supplier('some name', '+fasd3\qe3fs_=nac99013928czc', ['+122997365456']);
$receipt = $this->newReceipt()->setSupplier($supplier);
$this->assertArrayHasKey('supplier_info', $receipt->jsonSerialize());
$this->assertEquals($receipt->getSupplier()->jsonSerialize(), $receipt->jsonSerialize()['supplier_info']);
$this->assertSame($receipt->getSupplier()->jsonSerialize(), $receipt->jsonSerialize()['supplier_info']);
$this->assertArrayNotHasKey('supplier_info', $receipt->setSupplier(null)->jsonSerialize());
}
@@ -181,8 +182,8 @@ class ReceiptTest extends BasicTestCase
{
$this->expectException(EmptyItemsException::class);
new Receipt(
new Client('John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', '+fasd3\qe3fs_=nac99013928czc'),
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new Client('John Doe', '+1/22/99*73s dsdas654 5s6', 'john@example.com', '+fasd3\qe3fs_=nac99013928czc'),
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
new Items([]),
new Payments($this->generatePaymentObjects())
);
@@ -211,8 +212,8 @@ class ReceiptTest extends BasicTestCase
'Коллекция AtolOnline\Collections\Items должна содержать объекты AtolOnline\Entities\Item'
);
new Receipt(
new Client('John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', '+fasd3\qe3fs_=nac99013928czc'),
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new Client('John Doe', '+1/22/99*73s dsdas654 5s6', 'john@example.com', '+fasd3\qe3fs_=nac99013928czc'),
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
new Items(['qwerty']),
new Payments($this->generatePaymentObjects())
);
@@ -240,8 +241,8 @@ class ReceiptTest extends BasicTestCase
{
$this->expectException(EmptyPaymentsException::class);
new Receipt(
new Client('John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', '+fasd3\qe3fs_=nac99013928czc'),
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new Client('John Doe', '+1/22/99*73s dsdas654 5s6', 'john@example.com', '+fasd3\qe3fs_=nac99013928czc'),
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
new Items([new Item('test item', 2, 3)]),
new Payments([])
);
@@ -273,8 +274,8 @@ class ReceiptTest extends BasicTestCase
'Коллекция AtolOnline\Collections\Payments должна содержать объекты AtolOnline\Entities\Payment'
);
(string)new Receipt(
new Client('John Doe', 'john@example.com', '+1/22/99*73s dsdas654 5s6', '+fasd3\qe3fs_=nac99013928czc'),
new Company('company@example.com', SnoTypes::OSN, '1234567890', 'https://example.com'),
new Client('John Doe', '+1/22/99*73s dsdas654 5s6', 'john@example.com', '+fasd3\qe3fs_=nac99013928czc'),
new Company('1234567890', SnoType::OSN, 'https://example.com', 'company@example.com'),
new Items([new Item('test item', 2, 3)]),
new Payments(['qwerty'])
);
@@ -365,11 +366,11 @@ class ReceiptTest extends BasicTestCase
{
$receipt = $this->newReceipt();
$items_total = $receipt->getItems()->pluck('sum')->sum();
$this->assertEquals($items_total, $receipt->getTotal());
$this->assertSame($items_total, $receipt->getTotal());
/** @var Vat $vat */
$receipt->setVats(new Vats($this->generateVatObjects(2)))->getVats()
->each(fn($vat) => $this->assertEquals($items_total, $vat->getSum()));
->each(fn ($vat) => $this->assertSame($items_total, $vat->getSum()));
}
/**
@@ -398,7 +399,7 @@ class ReceiptTest extends BasicTestCase
{
$receipt = $this->newReceipt()->setCashier(Helpers::randomStr());
$this->assertArrayHasKey('cashier', $receipt->jsonSerialize());
$this->assertEquals($receipt->getCashier(), $receipt->jsonSerialize()['cashier']);
$this->assertSame($receipt->getCashier(), $receipt->jsonSerialize()['cashier']);
}
/**
@@ -480,7 +481,7 @@ class ReceiptTest extends BasicTestCase
{
$receipt = $this->newReceipt()->setAddCheckProps(Helpers::randomStr());
$this->assertArrayHasKey('additional_check_props', $receipt->jsonSerialize());
$this->assertEquals($receipt->getAddCheckProps(), $receipt->jsonSerialize()['additional_check_props']);
$this->assertSame($receipt->getAddCheckProps(), $receipt->jsonSerialize()['additional_check_props']);
}
/**
@@ -562,7 +563,7 @@ class ReceiptTest extends BasicTestCase
$aup = new AdditionalUserProps('name', 'value');
$receipt = $this->newReceipt()->setAddUserProps($aup);
$this->assertArrayHasKey('additional_user_props', $receipt->jsonSerialize());
$this->assertEquals(
$this->assertSame(
$receipt->getAddUserProps()->jsonSerialize(),
$receipt->jsonSerialize()['additional_user_props']
);

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -28,7 +29,7 @@ class ReceivePaymentsOperatorTest extends BasicTestCase
*/
public function testConstructorWithoutArgs(): void
{
$this->assertEquals('[]', (string)(new ReceivePaymentsOperator()));
$this->assertSame('[]', (string)(new ReceivePaymentsOperator()));
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -29,7 +30,7 @@ class SupplierTest extends BasicTestCase
*/
public function testConstructorWithoutArgs(): void
{
$this->assertEquals('[]', (string)(new Supplier()));
$this->assertSame('[]', (string)(new Supplier()));
}
/**
@@ -52,15 +53,18 @@ class SupplierTest extends BasicTestCase
$this->assertIsAtolable(new Supplier('some name'), ['name' => 'some name']);
$this->assertIsAtolable(new Supplier(inn: '+fasd3\qe3fs_=nac99013928czc'), ['inn' => '3399013928']);
$this->assertIsAtolable(new Supplier(phones: ['+122997365456']), ['phones' => ['+122997365456']]);
$this->assertIsAtolable(new Supplier(
'some name',
'+fasd3\qe3fs_=nac99013928czc',
['+122997365456'],
), [
'name' => 'some name',
'inn' => '3399013928',
'phones' => ['+122997365456'],
]);
$this->assertIsAtolable(
new Supplier(
'some name',
'+fasd3\qe3fs_=nac99013928czc',
['+122997365456'],
),
[
'name' => 'some name',
'inn' => '3399013928',
'phones' => ['+122997365456'],
]
);
}
/**
@@ -140,8 +144,8 @@ class SupplierTest extends BasicTestCase
*/
public function testValidInn(): void
{
$this->assertEquals('1234567890', (new Supplier())->setInn('1234567890')->getInn());
$this->assertEquals('123456789012', (new Supplier())->setInn('123456789012')->getInn());
$this->assertSame('1234567890', (new Supplier())->setInn('1234567890')->getInn());
$this->assertSame('123456789012', (new Supplier())->setInn('123456789012')->getInn());
}
/**

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -11,8 +12,7 @@ namespace AtolOnline\Tests\Entities;
use AtolOnline\{
Entities\Vat,
Enums\VatTypes,
Exceptions\InvalidEnumValueException,
Enums\VatType,
Tests\BasicTestCase};
use Exception;
@@ -29,14 +29,14 @@ class VatTest extends BasicTestCase
public function providerVatsSet(): array
{
return [
[VatTypes::NONE, 0],
[VatTypes::VAT0, 0],
[VatTypes::VAT10, 10],
[VatTypes::VAT18, 18],
[VatTypes::VAT20, 20],
[VatTypes::VAT110, 9.09],
[VatTypes::VAT118, 15.25],
[VatTypes::VAT120, 16.67],
[VatType::NONE, 0],
[VatType::VAT0, 0],
[VatType::VAT10, 10],
[VatType::VAT18, 18],
[VatType::VAT20, 20],
[VatType::VAT110, 9.09],
[VatType::VAT118, 15.25],
[VatType::VAT120, 16.67],
];
}
@@ -48,20 +48,21 @@ class VatTest extends BasicTestCase
public function providerVatsAdd(): array
{
return [
[VatTypes::VAT10, 12, 10],
[VatTypes::VAT18, 21.6, 18],
[VatTypes::VAT20, 24, 20],
[VatTypes::VAT110, 10.91, 9.09],
[VatTypes::VAT118, 18.31, 15.25],
[VatTypes::VAT120, 20, 16.67],
[VatType::VAT10, 12, 10],
[VatType::VAT18, 21.6, 18],
[VatType::VAT20, 24, 20],
[VatType::VAT110, 10.91, 9.09],
[VatType::VAT118, 18.31, 15.25],
[VatType::VAT120, 20, 16.67],
];
}
/**
* Тестирует конструктор без передачи значений и приведение к json
*
* @param string $type Тип НДС
* @param VatType $type Тип НДС
* @param float $sum Исходная сумма
* @throws Exception
* @dataProvider providerVatsSet
* @covers \AtolOnline\Entities\Vat
* @covers \AtolOnline\Entities\Vat::setType
@@ -70,36 +71,33 @@ class VatTest extends BasicTestCase
* @covers \AtolOnline\Entities\Vat::getSum
* @covers \AtolOnline\Entities\Vat::getCalculated
* @covers \AtolOnline\Entities\Vat::jsonSerialize
* @throws InvalidEnumValueException
* @throws Exception
*/
public function testConstructor(string $type, float $sum): void
public function testConstructor(VatType $type, float $sum): void
{
$vat = new Vat($type, $sum);
$this->assertIsAtolable($vat, [
'type' => $vat->getType(),
'sum' => $vat->getCalculated(),
]);
$this->assertEquals($type, $vat->getType());
$this->assertEquals($sum, $vat->getSum());
$this->assertSame($type, $vat->getType());
$this->assertSame($sum, $vat->getSum());
}
/**
* Тестирует расчёт суммы НДС от суммы 100+20р и 100-20р
*
* @dataProvider providerVatsAdd
* @param string $type Тип НДС
* @param VatType $type Тип НДС
* @param float $after_plus Результат после +20р
* @param float $after_minus Результат после -20р
* @covers \AtolOnline\Entities\Vat::addSum
* @covers \AtolOnline\Entities\Vat::getCalculated
* @throws InvalidEnumValueException
*/
public function testVatAdd(string $type, float $after_plus, float $after_minus)
public function testVatAdd(VatType $type, float $after_plus, float $after_minus)
{
$vat = (new Vat($type, 100))->addSum(20); // 120р
$this->assertEquals($after_plus, $vat->getCalculated());
$this->assertSame($after_plus, $vat->getCalculated());
$vat->addSum(-20); // 100р
$this->assertEquals($after_minus, $vat->getCalculated());
$this->assertSame($after_minus, $vat->getCalculated());
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
@@ -90,7 +91,7 @@ class HelpersTest extends BasicTestCase
{
$result = Helpers::toRub($kopeks);
$this->assertIsFloat($result);
$this->assertEquals($result, $rubles);
$this->assertSame($result, $rubles);
}
/**
@@ -103,7 +104,7 @@ class HelpersTest extends BasicTestCase
{
$result = Helpers::toKop($rubles);
$this->assertIsInt($result);
$this->assertEquals($result, $kopeks);
$this->assertSame($result, $kopeks);
}
/**
@@ -117,7 +118,7 @@ class HelpersTest extends BasicTestCase
{
$result = Helpers::randomStr($input);
$this->assertIsString($result);
$this->assertEquals($output, strlen($result));
$this->assertSame($output, strlen($result));
// тестировать на наличие цифр быссмысленно
}
}