Files
yookassa-sdk-php/tests/Request/Deals/CreateDealRequestTest.php
Антон Н. Николаев 2db9951ff6 Валидация payment_order.recipient.bank.name и payment_order.payment_period.year. Выплаты самозанятым теперь deprecated
Информация про чеки самозанятых в платежах и возвратах удалена - больше не поддерживаем сервисы для самозанятых
Добавлена возможность выставления счета по смс и email
Добавлена поддержка работы со списками выплат
Обновлен Copyright
2026-02-05 15:36:37 +03:00

346 lines
11 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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\Request\Deals;
use Exception;
use Tests\YooKassa\AbstractTestCase;
use Datetime;
use YooKassa\Common\AbstractRequestBuilder;
use YooKassa\Model\Metadata;
use YooKassa\Request\Deals\CreateDealRequest;
use YooKassa\Request\Deals\CreateDealRequestBuilder;
/**
* CreateDealRequestTest
*
* @category ClassTest
* @author cms@yoomoney.ru
* @link https://yookassa.ru/developers/api
*/
class CreateDealRequestTest extends AbstractTestCase
{
protected CreateDealRequest $object;
/**
* @param mixed|null $value
* @return CreateDealRequest
*/
protected function getTestInstance(mixed $value = null): CreateDealRequest
{
return new CreateDealRequest($value);
}
/**
* @return void
*/
public function testCreateDealRequestClassExists(): void
{
$this->object = $this->getMockBuilder(CreateDealRequest::class)->getMockForAbstractClass();
$this->assertTrue(class_exists(CreateDealRequest::class));
$this->assertInstanceOf(CreateDealRequest::class, $this->object);
}
/**
* 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);
self::assertContains($instance->getType(), ['safe_deal']);
self::assertContains($instance->type, ['safe_deal']);
}
/**
* Test invalid property "type"
* @dataProvider invalidTypeDataProvider
* @param mixed $value
* @param string $exceptionClass
*
* @return void
*/
public function testInvalidType(mixed $value, string $exceptionClass): void
{
$instance = $this->getTestInstance();
$this->expectException($exceptionClass);
$instance->setType($value);
}
/**
* @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 "fee_moment"
* @dataProvider validFeeMomentDataProvider
* @param mixed $value
*
* @return void
* @throws Exception
*/
public function testFeeMoment(mixed $value): void
{
$instance = $this->getTestInstance();
$instance->setFeeMoment($value);
self::assertNotNull($instance->getFeeMoment());
self::assertNotNull($instance->fee_moment);
self::assertEquals($value, is_array($value) ? $instance->getFeeMoment()->toArray() : $instance->getFeeMoment());
self::assertEquals($value, is_array($value) ? $instance->fee_moment->toArray() : $instance->fee_moment);
}
/**
* Test invalid property "fee_moment"
* @dataProvider invalidFeeMomentDataProvider
* @param mixed $value
* @param string $exceptionClass
*
* @return void
*/
public function testInvalidFeeMoment(mixed $value, string $exceptionClass): void
{
$instance = $this->getTestInstance();
$this->expectException($exceptionClass);
$instance->setFeeMoment($value);
}
/**
* @return array[]
* @throws Exception
*/
public function validFeeMomentDataProvider(): array
{
$instance = $this->getTestInstance();
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_fee_moment'));
}
/**
* @return array[]
* @throws Exception
*/
public function invalidFeeMomentDataProvider(): array
{
$instance = $this->getTestInstance();
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_fee_moment'));
}
/**
* 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);
self::assertTrue($instance->hasMetadata());
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'));
}
/**
* Test property "description"
* @dataProvider validDescriptionDataProvider
* @param mixed $value
*
* @return void
* @throws Exception
*/
public function testDescription(mixed $value): void
{
$instance = $this->getTestInstance();
self::assertEmpty($instance->getDescription());
self::assertEmpty($instance->description);
$instance->setDescription($value);
self::assertEquals($value, is_array($value) ? $instance->getDescription()->toArray() : $instance->getDescription());
self::assertEquals($value, is_array($value) ? $instance->description->toArray() : $instance->description);
if (!empty($value)) {
self::assertNotNull($instance->getDescription());
self::assertNotNull($instance->description);
self::assertLessThanOrEqual(128, is_string($instance->getDescription()) ? mb_strlen($instance->getDescription()) : $instance->getDescription());
self::assertLessThanOrEqual(128, is_string($instance->description) ? mb_strlen($instance->description) : $instance->description);
}
}
/**
* Test invalid property "description"
* @dataProvider invalidDescriptionDataProvider
* @param mixed $value
* @param string $exceptionClass
*
* @return void
*/
public function testInvalidDescription(mixed $value, string $exceptionClass): void
{
$instance = $this->getTestInstance();
$this->expectException($exceptionClass);
$instance->setDescription($value);
}
/**
* @return array[]
* @throws Exception
*/
public function validDescriptionDataProvider(): array
{
$instance = $this->getTestInstance();
return $this->getValidDataProviderByType($instance->getValidator()->getRulesByPropName('_description'));
}
/**
* @return array[]
* @throws Exception
*/
public function invalidDescriptionDataProvider(): array
{
$instance = $this->getTestInstance();
return $this->getInvalidDataProviderByType($instance->getValidator()->getRulesByPropName('_description'));
}
/**
* Test valid method "validate"
* @dataProvider validClassDataProvider
* @param mixed $value
*
* @return void
*/
public function testValidate(mixed $value): void
{
$instance = $this->getTestInstance($value);
self::assertTrue($instance->validate());
}
/**
* @return array
* @throws Exception
*/
public function validClassDataProvider(): array
{
$instance = $this->getTestInstance();
return [$this->getValidDataProviderByClass($instance)];
}
/**
* Test valid method "builder"
* @dataProvider validClassDataProvider
* @param mixed $value
*
* @return void
*/
public function testBuilder(mixed $value): void
{
$instance = $this->getTestInstance($value);
self::assertInstanceOf(AbstractRequestBuilder::class, $instance::builder());
}
}