mirror of
https://git.yoomoney.ru/scm/sdk/yookassa-sdk-php.git
synced 2026-08-22 07:23:26 +00:00
2db9951ff6
Информация про чеки самозанятых в платежах и возвратах удалена - больше не поддерживаем сервисы для самозанятых Добавлена возможность выставления счета по смс и email Добавлена поддержка работы со списками выплат Обновлен Copyright
264 lines
8.4 KiB
PHP
264 lines
8.4 KiB
PHP
<?php
|
||
/*
|
||
* The MIT License
|
||
*
|
||
* Copyright (c) 2026 "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\Common;
|
||
|
||
use DateTime;
|
||
use PHPUnit\Framework\TestCase;
|
||
use stdClass;
|
||
use YooKassa\Common\AbstractObject;
|
||
|
||
/**
|
||
* @internal
|
||
*/
|
||
class AbstractObjectTest extends TestCase
|
||
{
|
||
/**
|
||
* @dataProvider offsetDataProvider
|
||
*
|
||
* @param mixed $value
|
||
* @param mixed $exists
|
||
*/
|
||
public function testOffsetExists(mixed $value, mixed $exists): void
|
||
{
|
||
$instance = $this->getTestInstance();
|
||
if (!$exists) {
|
||
self::assertFalse($instance->offsetExists($value));
|
||
self::assertFalse(isset($instance[$value]));
|
||
self::assertFalse(isset($instance->{$value}));
|
||
|
||
$instance->offsetSet($value, $value);
|
||
}
|
||
self::assertTrue($instance->offsetExists($value));
|
||
self::assertTrue(isset($instance[$value]));
|
||
self::assertTrue(isset($instance->{$value}));
|
||
}
|
||
|
||
/**
|
||
* @dataProvider offsetDataProvider
|
||
*
|
||
* @param mixed $value
|
||
*/
|
||
public function testOffsetGet(mixed $value): void
|
||
{
|
||
$instance = $this->getTestInstance();
|
||
|
||
$tmp = $instance->offsetGet($value);
|
||
self::assertNull($tmp);
|
||
$tmp = $instance[$value];
|
||
self::assertNull($tmp);
|
||
$tmp = $instance->{$value};
|
||
self::assertNull($tmp);
|
||
|
||
$instance->offsetSet($value, $value);
|
||
|
||
$tmp = $instance->offsetGet($value);
|
||
self::assertEquals($value, $tmp);
|
||
$tmp = $instance[$value];
|
||
self::assertEquals($value, $tmp);
|
||
$tmp = $instance->{$value};
|
||
self::assertEquals($value, $tmp);
|
||
}
|
||
|
||
/**
|
||
* @dataProvider offsetDataProvider
|
||
*
|
||
* @param mixed $value
|
||
* @param mixed $exists
|
||
*/
|
||
public function testOffsetUnset(mixed $value, mixed $exists): void
|
||
{
|
||
$instance = $this->getTestInstance();
|
||
if ($exists) {
|
||
self::assertTrue($instance->offsetExists($value));
|
||
$instance->offsetUnset($value);
|
||
self::assertTrue($instance->offsetExists($value));
|
||
unset($instance[$value]);
|
||
self::assertTrue($instance->offsetExists($value));
|
||
unset($instance->{$value});
|
||
self::assertTrue($instance->offsetExists($value));
|
||
} else {
|
||
self::assertFalse($instance->offsetExists($value));
|
||
$instance->offsetUnset($value);
|
||
self::assertFalse($instance->offsetExists($value));
|
||
unset($instance[$value]);
|
||
self::assertFalse($instance->offsetExists($value));
|
||
unset($instance->{$value});
|
||
self::assertFalse($instance->offsetExists($value));
|
||
|
||
$instance->{$value} = $value;
|
||
self::assertTrue($instance->offsetExists($value));
|
||
$instance->offsetUnset($value);
|
||
self::assertFalse($instance->offsetExists($value));
|
||
|
||
$instance->{$value} = $value;
|
||
self::assertTrue($instance->offsetExists($value));
|
||
unset($instance[$value]);
|
||
self::assertFalse($instance->offsetExists($value));
|
||
|
||
$instance->{$value} = $value;
|
||
self::assertTrue($instance->offsetExists($value));
|
||
unset($instance->{$value});
|
||
self::assertFalse($instance->offsetExists($value));
|
||
}
|
||
}
|
||
|
||
public static function offsetDataProvider(): array
|
||
{
|
||
return [
|
||
['property', true],
|
||
['propertyCamelCase', true],
|
||
['property_camel_case', true],
|
||
['Property', true],
|
||
['PropertyCamelCase', true],
|
||
['Property_Camel_Case', true],
|
||
['not_exists', false],
|
||
];
|
||
}
|
||
|
||
public function testJsonSerialize(): void
|
||
{
|
||
$instance = $this->getTestInstance();
|
||
|
||
$data = $instance->jsonSerialize();
|
||
$expected = [];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->setProperty('propertyValue');
|
||
$data = $instance->jsonSerialize();
|
||
$expected = [
|
||
'property' => 'propertyValue',
|
||
];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->setPropertyCamelCase($this->getTestInstance());
|
||
$data = $instance->jsonSerialize();
|
||
$expected = [
|
||
'property' => 'propertyValue',
|
||
'property_camel_case' => [],
|
||
];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->getPropertyCamelCase()->setProperty(['test', 1, 2, 3]);
|
||
$data = $instance->jsonSerialize();
|
||
$expected = [
|
||
'property' => 'propertyValue',
|
||
'property_camel_case' => [
|
||
'property' => ['test', 1, 2, 3],
|
||
],
|
||
];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$date = new DateTime();
|
||
$instance->getPropertyCamelCase()->setPropertyCamelCase($date);
|
||
$data = $instance->jsonSerialize();
|
||
$expected = [
|
||
'property' => 'propertyValue',
|
||
'property_camel_case' => [
|
||
'property' => ['test', 1, 2, 3],
|
||
'property_camel_case' => $date->format(YOOKASSA_DATE),
|
||
],
|
||
];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->getPropertyCamelCase()->unknown_obj = $this->getTestInstance();
|
||
$data = $instance->jsonSerialize();
|
||
$expected = [
|
||
'property' => 'propertyValue',
|
||
'property_camel_case' => [
|
||
'property' => ['test', 1, 2, 3],
|
||
'property_camel_case' => $date->format(YOOKASSA_DATE),
|
||
'unknown_obj' => [],
|
||
],
|
||
];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->unknown_property = true;
|
||
$data = $instance->jsonSerialize();
|
||
$expected['unknown_property'] = true;
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->unknown_array = [false];
|
||
$data = $instance->jsonSerialize();
|
||
$expected['unknown_array'] = [false];
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->unknown_date = $date;
|
||
$data = $instance->jsonSerialize();
|
||
$expected['unknown_date'] = $date->format(YOOKASSA_DATE);
|
||
self::assertEquals($expected, $data);
|
||
|
||
$obj = new stdClass();
|
||
$obj->test = 'test1';
|
||
$instance->unknown_obj = $obj;
|
||
$data = $instance->jsonSerialize();
|
||
$expected['unknown_obj'] = $obj;
|
||
self::assertEquals($expected, $data);
|
||
|
||
$obj = new stdClass();
|
||
$obj->test = 'test2';
|
||
$instance->property_camel_case = $obj;
|
||
$data = $instance->jsonSerialize();
|
||
$expected['property_camel_case'] = $obj;
|
||
self::assertEquals($expected, $data);
|
||
|
||
$instance->property_camel_case = null;
|
||
$data = $instance->jsonSerialize();
|
||
unset($expected['property_camel_case']);
|
||
self::assertEquals($expected, $data);
|
||
}
|
||
|
||
protected function getTestInstance(): TestAbstractObject
|
||
{
|
||
return new TestAbstractObject();
|
||
}
|
||
}
|
||
|
||
class TestAbstractObject extends AbstractObject
|
||
{
|
||
private $_property;
|
||
private $_anotherProperty;
|
||
|
||
public function getProperty()
|
||
{
|
||
return $this->_property;
|
||
}
|
||
|
||
public function setProperty($value): void
|
||
{
|
||
$this->_property = $value;
|
||
}
|
||
|
||
public function getPropertyCamelCase()
|
||
{
|
||
return $this->_anotherProperty;
|
||
}
|
||
|
||
public function setPropertyCamelCase($value): void
|
||
{
|
||
$this->_anotherProperty = $value;
|
||
}
|
||
}
|