mirror of
https://git.yoomoney.ru/scm/sdk/yookassa-sdk-php.git
synced 2026-08-18 03:33:43 +00:00
Устанавливаем cms_name = yookassa_sdk_php_3 если он не установлен в запросе. Обновлены тесты
Исправлены неточности в типах и описаниях
This commit is contained in:
@@ -1,116 +1,175 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2024 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Tests\YooKassa\Model\PersonalData;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use YooKassa\Common\Exceptions\EmptyPropertyValueException;
|
||||
use YooKassa\Common\Exceptions\InvalidPropertyValueTypeException;
|
||||
use Exception;
|
||||
use Tests\YooKassa\AbstractTestCase;
|
||||
use Datetime;
|
||||
use YooKassa\Model\Metadata;
|
||||
use YooKassa\Model\PersonalData\PersonalDataCancellationDetails;
|
||||
use YooKassa\Model\PersonalData\PersonalDataCancellationDetailsPartyCode;
|
||||
use YooKassa\Model\PersonalData\PersonalDataCancellationDetailsReasonCode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* PersonalDataCancellationDetailsTest
|
||||
*
|
||||
* @category ClassTest
|
||||
* @author cms@yoomoney.ru
|
||||
* @link https://yookassa.ru/developers/api
|
||||
*/
|
||||
class PersonalDataCancellationDetailsTest extends TestCase
|
||||
class PersonalDataCancellationDetailsTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*
|
||||
* @param null|mixed $value
|
||||
*/
|
||||
public function testConstructor($value = null): void
|
||||
{
|
||||
$instance = self::getInstance($value);
|
||||
|
||||
self::assertEquals($value['party'], $instance->getParty());
|
||||
self::assertEquals($value['reason'], $instance->getReason());
|
||||
}
|
||||
protected PersonalDataCancellationDetails $object;
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*
|
||||
* @param null|mixed $value
|
||||
*/
|
||||
public function testGetSetParty($value): void
|
||||
{
|
||||
$instance = self::getInstance($value);
|
||||
self::assertEquals($value['party'], $instance->getParty());
|
||||
|
||||
$instance = self::getInstance([]);
|
||||
$instance->setParty($value['party']);
|
||||
self::assertEquals($value['party'], $instance->getParty());
|
||||
self::assertEquals($value['party'], $instance->party);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*
|
||||
* @param null $value
|
||||
*/
|
||||
public function testGetSetReason($value = null): void
|
||||
{
|
||||
$instance = self::getInstance($value);
|
||||
self::assertEquals($value['reason'], $instance->getReason());
|
||||
|
||||
$instance = self::getInstance([]);
|
||||
$instance->setReason($value['reason']);
|
||||
self::assertEquals($value['reason'], $instance->getReason());
|
||||
self::assertEquals($value['reason'], $instance->reason);
|
||||
}
|
||||
|
||||
public static function validDataProvider(): array
|
||||
{
|
||||
$result = [];
|
||||
$cancellationDetailsParties = PersonalDataCancellationDetailsPartyCode::getValidValues();
|
||||
$countCancellationDetailsParties = count($cancellationDetailsParties);
|
||||
$cancellationDetailsReasons = PersonalDataCancellationDetailsReasonCode::getValidValues();
|
||||
$countCancellationDetailsReasons = count($cancellationDetailsReasons);
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$result[] = [
|
||||
[
|
||||
'party' => $cancellationDetailsParties[$i % $countCancellationDetailsParties],
|
||||
'reason' => $cancellationDetailsReasons[$i % $countCancellationDetailsReasons],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function invalidValueDataProvider()
|
||||
{
|
||||
return [
|
||||
[null, EmptyPropertyValueException::class],
|
||||
['', EmptyPropertyValueException::class],
|
||||
[[], InvalidPropertyValueTypeException::class],
|
||||
[fopen(__FILE__, 'rb'), InvalidPropertyValueTypeException::class],
|
||||
[true, InvalidPropertyValueTypeException::class],
|
||||
[false, InvalidPropertyValueTypeException::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*
|
||||
* @param null $value
|
||||
*/
|
||||
public function testJsonSerialize($value = null): void
|
||||
{
|
||||
$instance = new PersonalDataCancellationDetails($value);
|
||||
$expected = [
|
||||
'party' => $value['party'],
|
||||
'reason' => $value['reason'],
|
||||
];
|
||||
self::assertEquals($expected, $instance->jsonSerialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return PersonalDataCancellationDetails
|
||||
*/
|
||||
protected static function getInstance(mixed $value): PersonalDataCancellationDetails
|
||||
protected function getTestInstance(): PersonalDataCancellationDetails
|
||||
{
|
||||
return new PersonalDataCancellationDetails($value);
|
||||
return new PersonalDataCancellationDetails();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testPersonalDataCancellationDetailsClassExists(): void
|
||||
{
|
||||
$this->object = $this->getMockBuilder(PersonalDataCancellationDetails::class)->getMockForAbstractClass();
|
||||
$this->assertTrue(class_exists(PersonalDataCancellationDetails::class));
|
||||
$this->assertInstanceOf(PersonalDataCancellationDetails::class, $this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "party"
|
||||
* @dataProvider validPartyDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testParty(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
$instance->setParty($value);
|
||||
self::assertNotNull($instance->getParty());
|
||||
self::assertNotNull($instance->party);
|
||||
self::assertEquals($value, is_array($value) ? $instance->getParty()->toArray() : $instance->getParty());
|
||||
self::assertEquals($value, is_array($value) ? $instance->party->toArray() : $instance->party);
|
||||
self::assertContains($instance->getParty(), ['yoo_money']);
|
||||
self::assertContains($instance->party, ['yoo_money']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid property "party"
|
||||
* @dataProvider invalidPartyDataProvider
|
||||
* @param mixed $value
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidParty(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setParty($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validPartyDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_party'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidPartyDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_party'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "reason"
|
||||
* @dataProvider validReasonDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testReason(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
$instance->setReason($value);
|
||||
self::assertNotNull($instance->getReason());
|
||||
self::assertNotNull($instance->reason);
|
||||
self::assertEquals($value, is_array($value) ? $instance->getReason()->toArray() : $instance->getReason());
|
||||
self::assertEquals($value, is_array($value) ? $instance->reason->toArray() : $instance->reason);
|
||||
self::assertContains($instance->getReason(), ['expired_by_timeout']);
|
||||
self::assertContains($instance->reason, ['expired_by_timeout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid property "reason"
|
||||
* @dataProvider invalidReasonDataProvider
|
||||
* @param mixed $value
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidReason(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setReason($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validReasonDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_reason'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidReasonDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_reason'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,445 +1,483 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright (c) 2024 "YooMoney", NBСO LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Tests\YooKassa\Model\PersonalData;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
use YooKassa\Helpers\Random;
|
||||
use Exception;
|
||||
use Tests\YooKassa\AbstractTestCase;
|
||||
use Datetime;
|
||||
use YooKassa\Model\Metadata;
|
||||
use YooKassa\Model\PersonalData\PersonalData;
|
||||
use YooKassa\Model\PersonalData\PersonalDataCancellationDetails;
|
||||
use YooKassa\Model\PersonalData\PersonalDataCancellationDetailsPartyCode;
|
||||
use YooKassa\Model\PersonalData\PersonalDataCancellationDetailsReasonCode;
|
||||
use YooKassa\Model\PersonalData\PersonalDataStatus;
|
||||
use YooKassa\Model\PersonalData\PersonalDataType;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* PersonalDataTest
|
||||
*
|
||||
* @category ClassTest
|
||||
* @author cms@yoomoney.ru
|
||||
* @link https://yookassa.ru/developers/api
|
||||
*/
|
||||
class PersonalDataTest extends TestCase
|
||||
class PersonalDataTest extends AbstractTestCase
|
||||
{
|
||||
protected PersonalData $object;
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
* @return PersonalData
|
||||
*/
|
||||
public function testGetSetId(array $options): void
|
||||
protected function getTestInstance(): PersonalData
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
|
||||
$instance->setId($options['id']);
|
||||
self::assertEquals($options['id'], $instance->getId());
|
||||
self::assertEquals($options['id'], $instance->id);
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->id = $options['id'];
|
||||
self::assertEquals($options['id'], $instance->getId());
|
||||
self::assertEquals($options['id'], $instance->id);
|
||||
return new PersonalData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPersonalDataClassExists(): void
|
||||
{
|
||||
$this->object = $this->getMockBuilder(PersonalData::class)->getMockForAbstractClass();
|
||||
$this->assertTrue(class_exists(PersonalData::class));
|
||||
$this->assertInstanceOf(PersonalData::class, $this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "id"
|
||||
* @dataProvider validIdDataProvider
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testSetInvalidId($value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->setId($value['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testId(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
$instance->setId($value);
|
||||
self::assertNotNull($instance->getId());
|
||||
self::assertNotNull($instance->id);
|
||||
self::assertEquals($value, is_array($value) ? $instance->getId()->toArray() : $instance->getId());
|
||||
self::assertEquals($value, is_array($value) ? $instance->id->toArray() : $instance->id);
|
||||
self::assertLessThanOrEqual(50, is_string($instance->getId()) ? mb_strlen($instance->getId()) : $instance->getId());
|
||||
self::assertLessThanOrEqual(50, is_string($instance->id) ? mb_strlen($instance->id) : $instance->id);
|
||||
self::assertGreaterThanOrEqual(36, is_string($instance->getId()) ? mb_strlen($instance->getId()) : $instance->getId());
|
||||
self::assertGreaterThanOrEqual(36, is_string($instance->id) ? mb_strlen($instance->id) : $instance->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid property "id"
|
||||
* @dataProvider invalidIdDataProvider
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testSetterInvalidId($value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->id = $value['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*/
|
||||
public function testGetSetStatus(array $options): void
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
|
||||
$instance->setStatus($options['status']);
|
||||
self::assertEquals($options['status'], $instance->getStatus());
|
||||
self::assertEquals($options['status'], $instance->status);
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->status = $options['status'];
|
||||
self::assertEquals($options['status'], $instance->getStatus());
|
||||
self::assertEquals($options['status'], $instance->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInvalidStatus($value): void
|
||||
public function testInvalidId(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->setStatus($value['status']);
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setId($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validIdDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidIdDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "type"
|
||||
* @dataProvider validTypeDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testType(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
$instance->setType($value);
|
||||
self::assertNotNull($instance->getType());
|
||||
self::assertNotNull($instance->type);
|
||||
self::assertEquals($value, is_array($value) ? $instance->getType()->toArray() : $instance->getType());
|
||||
self::assertEquals($value, is_array($value) ? $instance->type->toArray() : $instance->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid property "type"
|
||||
* @dataProvider invalidTypeDataProvider
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testSetterInvalidStatus($value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->status = $value['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*/
|
||||
public function testGetSetType(array $options): void
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
|
||||
$instance->setType($options['type']);
|
||||
self::assertSame($options['type'], $instance->getType());
|
||||
self::assertSame($options['type'], $instance->type);
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->type = $options['type'];
|
||||
self::assertSame($options['type'], $instance->getType());
|
||||
self::assertSame($options['type'], $instance->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInvalidType($value): void
|
||||
public function testInvalidType(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->setType($value['type']);
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setType($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validTypeDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidTypeDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "status"
|
||||
* @dataProvider validStatusDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStatus(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
$instance->setStatus($value);
|
||||
self::assertNotNull($instance->getStatus());
|
||||
self::assertNotNull($instance->status);
|
||||
self::assertEquals($value, is_array($value) ? $instance->getStatus()->toArray() : $instance->getStatus());
|
||||
self::assertEquals($value, is_array($value) ? $instance->status->toArray() : $instance->status);
|
||||
self::assertContains($instance->getStatus(), ['waiting_for_operation', 'active', 'canceled']);
|
||||
self::assertContains($instance->status, ['waiting_for_operation', 'active', 'canceled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid property "status"
|
||||
* @dataProvider invalidStatusDataProvider
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testSetterInvalidType($value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->type = $value['type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*/
|
||||
public function testGetSetCreatedAt(array $options): void
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
|
||||
$instance->setCreatedAt($options['created_at']);
|
||||
self::assertSame($options['created_at'], $instance->getCreatedAt()->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['created_at'], $instance->createdAt->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['created_at'], $instance->created_at->format(YOOKASSA_DATE));
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->createdAt = $options['created_at'];
|
||||
self::assertSame($options['created_at'], $instance->getCreatedAt()->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['created_at'], $instance->createdAt->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['created_at'], $instance->created_at->format(YOOKASSA_DATE));
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->created_at = $options['created_at'];
|
||||
self::assertSame($options['created_at'], $instance->getCreatedAt()->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['created_at'], $instance->createdAt->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['created_at'], $instance->created_at->format(YOOKASSA_DATE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInvalidCreatedAt($value): void
|
||||
public function testInvalidStatus(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->setCreatedAt($value['created_at']);
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setStatus($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validStatusDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_status'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidStatusDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_status'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "cancellation_details"
|
||||
* @dataProvider validCancellationDetailsDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSetterInvalidCreatedAt($value): void
|
||||
public function testCancellationDetails(mixed $value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->createdAt = $value['created_at'];
|
||||
$instance = $this->getTestInstance();
|
||||
self::assertEmpty($instance->getCancellationDetails());
|
||||
self::assertEmpty($instance->cancellation_details);
|
||||
$instance->setCancellationDetails($value);
|
||||
self::assertEquals($value, is_array($value) ? $instance->getCancellationDetails()->toArray() : $instance->getCancellationDetails());
|
||||
self::assertEquals($value, is_array($value) ? $instance->cancellation_details->toArray() : $instance->cancellation_details);
|
||||
if (!empty($value)) {
|
||||
self::assertNotNull($instance->getCancellationDetails());
|
||||
self::assertNotNull($instance->cancellation_details);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* Test invalid property "cancellation_details"
|
||||
* @dataProvider invalidCancellationDetailsDataProvider
|
||||
* @param mixed $value
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function testSetterInvalidSnakeCreatedAt($value): void
|
||||
public function testInvalidCancellationDetails(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->created_at = $value['created_at'];
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setCancellationDetails($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetSetExpiresAt(array $options): void
|
||||
public function validCancellationDetailsDataProvider(): array
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_cancellation_details'));
|
||||
}
|
||||
|
||||
$instance->setExpiresAt($options['expires_at']);
|
||||
if (!empty($options['expires_at'])) {
|
||||
self::assertSame($options['expires_at'], $instance->getExpiresAt()->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['expires_at'], $instance->expiresAt->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['expires_at'], $instance->expires_at->format(YOOKASSA_DATE));
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidCancellationDetailsDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_cancellation_details'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "created_at"
|
||||
* @dataProvider validCreatedAtDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testCreatedAt(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
$instance->setCreatedAt($value);
|
||||
self::assertNotNull($instance->getCreatedAt());
|
||||
self::assertNotNull($instance->created_at);
|
||||
if ($value instanceof Datetime) {
|
||||
self::assertEquals($value, $instance->getCreatedAt());
|
||||
self::assertEquals($value, $instance->created_at);
|
||||
} else {
|
||||
self::assertNull($instance->getExpiresAt());
|
||||
self::assertNull($instance->expiresAt);
|
||||
self::assertNull($instance->expires_at);
|
||||
}
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->expiresAt = $options['expires_at'];
|
||||
if (!empty($options['expires_at'])) {
|
||||
self::assertSame($options['expires_at'], $instance->getExpiresAt()->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['expires_at'], $instance->expiresAt->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['expires_at'], $instance->expires_at->format(YOOKASSA_DATE));
|
||||
} else {
|
||||
self::assertNull($instance->getExpiresAt());
|
||||
self::assertNull($instance->expiresAt);
|
||||
self::assertNull($instance->expires_at);
|
||||
}
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->expires_at = $options['expires_at'];
|
||||
if (!empty($options['expires_at'])) {
|
||||
self::assertSame($options['expires_at'], $instance->getExpiresAt()->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['expires_at'], $instance->expiresAt->format(YOOKASSA_DATE));
|
||||
self::assertSame($options['expires_at'], $instance->expires_at->format(YOOKASSA_DATE));
|
||||
} else {
|
||||
self::assertNull($instance->getExpiresAt());
|
||||
self::assertNull($instance->expiresAt);
|
||||
self::assertNull($instance->expires_at);
|
||||
self::assertEquals(new Datetime($value), $instance->getCreatedAt());
|
||||
self::assertEquals(new Datetime($value), $instance->created_at);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
*
|
||||
* Test invalid property "created_at"
|
||||
* @dataProvider invalidCreatedAtDataProvider
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testSetInvalidExpiresAt($value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->setExpiresAt($value['expires_at']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function testSetterInvalidExpiresAt($value): void
|
||||
public function testInvalidCreatedAt(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->expiresAt = $value['expires_at'];
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setCreatedAt($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validCreatedAtDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_created_at'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidCreatedAtDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_created_at'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test property "expires_at"
|
||||
* @dataProvider validExpiresAtDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSetterInvalidSnakeExpiresAt($value): void
|
||||
public function testExpiresAt(mixed $value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->expires_at = $value['expires_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*/
|
||||
public function testGetSetCancellationDetails(array $options): void
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
|
||||
$instance->setCancellationDetails($options['cancellation_details']);
|
||||
self::assertSame($options['cancellation_details'], $instance->getCancellationDetails());
|
||||
self::assertSame($options['cancellation_details'], $instance->cancellationDetails);
|
||||
self::assertSame($options['cancellation_details'], $instance->cancellation_details);
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->cancellationDetails = $options['cancellation_details'];
|
||||
self::assertSame($options['cancellation_details'], $instance->getCancellationDetails());
|
||||
self::assertSame($options['cancellation_details'], $instance->cancellationDetails);
|
||||
self::assertSame($options['cancellation_details'], $instance->cancellation_details);
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->cancellation_details = $options['cancellation_details'];
|
||||
self::assertSame($options['cancellation_details'], $instance->getCancellationDetails());
|
||||
self::assertSame($options['cancellation_details'], $instance->cancellationDetails);
|
||||
self::assertSame($options['cancellation_details'], $instance->cancellation_details);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function testSetterInvalidCancellationDetails($value): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->cancellation_details = $value['cancellation_details'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
*/
|
||||
public function testGetSetMetadata(array $options): void
|
||||
{
|
||||
$instance = new PersonalData();
|
||||
|
||||
if (is_array($options['metadata'])) {
|
||||
$instance->setMetadata($options['metadata']);
|
||||
self::assertSame($options['metadata'], $instance->getMetadata()->toArray());
|
||||
self::assertSame($options['metadata'], $instance->metadata->toArray());
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->metadata = $options['metadata'];
|
||||
self::assertSame($options['metadata'], $instance->getMetadata()->toArray());
|
||||
self::assertSame($options['metadata'], $instance->metadata->toArray());
|
||||
} elseif ($options['metadata'] instanceof Metadata || empty($options['metadata'])) {
|
||||
$instance->setMetadata($options['metadata']);
|
||||
self::assertSame($options['metadata'], $instance->getMetadata());
|
||||
self::assertSame($options['metadata'], $instance->metadata);
|
||||
|
||||
$instance = new PersonalData();
|
||||
$instance->metadata = $options['metadata'];
|
||||
self::assertSame($options['metadata'], $instance->getMetadata());
|
||||
self::assertSame($options['metadata'], $instance->metadata);
|
||||
$instance = $this->getTestInstance();
|
||||
self::assertEmpty($instance->getExpiresAt());
|
||||
self::assertEmpty($instance->expires_at);
|
||||
$instance->setExpiresAt($value);
|
||||
if (!empty($value)) {
|
||||
self::assertNotNull($instance->getExpiresAt());
|
||||
self::assertNotNull($instance->expires_at);
|
||||
if ($value instanceof Datetime) {
|
||||
self::assertEquals($value, $instance->getExpiresAt());
|
||||
self::assertEquals($value, $instance->expires_at);
|
||||
} else {
|
||||
self::assertEquals(new Datetime($value), $instance->getExpiresAt());
|
||||
self::assertEquals(new Datetime($value), $instance->expires_at);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidDataProvider
|
||||
*
|
||||
* Test invalid property "expires_at"
|
||||
* @dataProvider invalidExpiresAtDataProvider
|
||||
* @param mixed $value
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetterInvalidMetadata($value): void
|
||||
public function testInvalidExpiresAt(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$instance = new PersonalData();
|
||||
$instance->metadata = $value['metadata'];
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setExpiresAt($value);
|
||||
}
|
||||
|
||||
public static function validDataProvider(): array
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validExpiresAtDataProvider(): array
|
||||
{
|
||||
$result = [];
|
||||
$cancellationDetailsParties = PersonalDataCancellationDetailsPartyCode::getValidValues();
|
||||
$countCancellationDetailsParties = count($cancellationDetailsParties);
|
||||
$cancellationDetailsReasons = PersonalDataCancellationDetailsReasonCode::getValidValues();
|
||||
$countCancellationDetailsReasons = count($cancellationDetailsReasons);
|
||||
|
||||
$result[] = [
|
||||
[
|
||||
'id' => Random::str(36, 50),
|
||||
'status' => Random::value(PersonalDataStatus::getValidValues()),
|
||||
'type' => Random::value(PersonalDataType::getValidValues()),
|
||||
'created_at' => date(YOOKASSA_DATE, Random::int(111111111, time())),
|
||||
'expires_at' => null,
|
||||
'metadata' => ['order_id' => '37'],
|
||||
'cancellation_details' => new PersonalDataCancellationDetails([
|
||||
'party' => Random::value($cancellationDetailsParties),
|
||||
'reason' => Random::value($cancellationDetailsReasons),
|
||||
]),
|
||||
],
|
||||
];
|
||||
$result[] = [
|
||||
[
|
||||
'id' => Random::str(36, 50),
|
||||
'status' => Random::value(PersonalDataStatus::getValidValues()),
|
||||
'type' => Random::value(PersonalDataType::getValidValues()),
|
||||
'created_at' => date(YOOKASSA_DATE, Random::int(1, time())),
|
||||
'expires_at' => date(YOOKASSA_DATE, Random::int(1, time())),
|
||||
'metadata' => null,
|
||||
'cancellation_details' => null,
|
||||
],
|
||||
];
|
||||
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$payment = [
|
||||
'id' => Random::str(36, 50),
|
||||
'type' => Random::value(PersonalDataType::getValidValues()),
|
||||
'status' => Random::value(PersonalDataStatus::getValidValues()),
|
||||
'created_at' => date(YOOKASSA_DATE, Random::int(1, time())),
|
||||
'expires_at' => date(YOOKASSA_DATE, Random::int(1, time())),
|
||||
'metadata' => new Metadata(),
|
||||
'cancellation_details' => new PersonalDataCancellationDetails([
|
||||
'party' => $cancellationDetailsParties[$i % $countCancellationDetailsParties],
|
||||
'reason' => $cancellationDetailsReasons[$i % $countCancellationDetailsReasons],
|
||||
]),
|
||||
];
|
||||
$result[] = [$payment];
|
||||
}
|
||||
|
||||
return $result;
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_expires_at'));
|
||||
}
|
||||
|
||||
public static function invalidDataProvider(): array
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidExpiresAtDataProvider(): array
|
||||
{
|
||||
$result = [
|
||||
[
|
||||
[
|
||||
'id' => '',
|
||||
'type' => 'null',
|
||||
'status' => '',
|
||||
'created_at' => 'null',
|
||||
'expires_at' => 'null',
|
||||
'cancellation_details' => new stdClass(),
|
||||
'metadata' => new stdClass(),
|
||||
],
|
||||
],
|
||||
];
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$personalData = [
|
||||
'id' => Random::str($i < 5 ? Random::int(1, 35) : Random::int(51, 64)),
|
||||
'type' => Random::str(10),
|
||||
'status' => Random::str(2, 35),
|
||||
'created_at' => 0 === $i ? '23423-234-32' : -Random::int(),
|
||||
'expires_at' => 0 === $i ? '23423-234-32' : -Random::int(),
|
||||
'cancellation_details' => 'null',
|
||||
'metadata' => 'null',
|
||||
];
|
||||
$result[] = [$personalData];
|
||||
}
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_expires_at'));
|
||||
}
|
||||
|
||||
return $result;
|
||||
/**
|
||||
* Test property "metadata"
|
||||
* @dataProvider validMetadataDataProvider
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testMetadata(mixed $value): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
self::assertEmpty($instance->getMetadata());
|
||||
self::assertEmpty($instance->metadata);
|
||||
$instance->setMetadata($value);
|
||||
if (!empty($value)) {
|
||||
self::assertNotNull($instance->getMetadata());
|
||||
self::assertNotNull($instance->metadata);
|
||||
foreach ($value as $key => $element) {
|
||||
if (!empty($element)) {
|
||||
self::assertEquals($element, $instance->getMetadata()[$key]);
|
||||
self::assertEquals($element, $instance->metadata[$key]);
|
||||
self::assertIsObject($instance->getMetadata());
|
||||
self::assertIsObject($instance->metadata);
|
||||
}
|
||||
}
|
||||
self::assertCount(count($value), $instance->getMetadata());
|
||||
self::assertCount(count($value), $instance->metadata);
|
||||
if ($instance->getMetadata() instanceof Metadata) {
|
||||
self::assertEquals($value, $instance->getMetadata()->toArray());
|
||||
self::assertEquals($value, $instance->metadata->toArray());
|
||||
self::assertCount(count($value), $instance->getMetadata());
|
||||
self::assertCount(count($value), $instance->metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid property "metadata"
|
||||
* @dataProvider invalidMetadataDataProvider
|
||||
* @param mixed $value
|
||||
* @param string $exceptionClass
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidMetadata(mixed $value, string $exceptionClass): void
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
|
||||
$this->expectException($exceptionClass);
|
||||
$instance->setMetadata($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validMetadataDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_metadata'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function invalidMetadataDataProvider(): array
|
||||
{
|
||||
$instance = $this->getTestInstance();
|
||||
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_metadata'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user