mirror of
https://git.yoomoney.ru/scm/sdk/yookassa-sdk-php.git
synced 2026-10-24 08:38:58 +00:00
Добавлена поддержка совместимости с PHP 8.5
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
<?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\Model\Notification;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
use YooKassa\Helpers\Random;
|
||||
use YooKassa\Model\Notification\AbstractNotification;
|
||||
|
||||
abstract class AbstractNotificationTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param array $source
|
||||
* @return AbstractNotification
|
||||
*/
|
||||
abstract protected function getTestInstance(array $source);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getExpectedType();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getExpectedEvent();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
abstract public function validDataProvider();
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
* @param array $value
|
||||
*/
|
||||
public function testGetType(array $value)
|
||||
{
|
||||
$instance = $this->getTestInstance($value);
|
||||
self::assertEquals($this->getExpectedType(), $instance->getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidConstructorTypeDataProvider
|
||||
* @param array $source
|
||||
*/
|
||||
public function testInvalidTypeInConstructor(array $source)
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->getTestInstance($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validDataProvider
|
||||
* @param array $value
|
||||
*/
|
||||
public function testGetEvent(array $value)
|
||||
{
|
||||
$instance = $this->getTestInstance($value);
|
||||
self::assertEquals($this->getExpectedEvent(), $instance->getEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidConstructorEventDataProvider
|
||||
* @param array $source
|
||||
*/
|
||||
public function testInvalidEventInConstructor(array $source)
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->getTestInstance($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidTypeDataProvider
|
||||
* @param $value
|
||||
*/
|
||||
public function testInvalidType($value)
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new TestNotification($value, $this->getExpectedEvent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidEventDataProvider
|
||||
* @param $value
|
||||
*/
|
||||
public function testInvalidEvent($value)
|
||||
{
|
||||
$this->expectException('InvalidArgumentException');
|
||||
new TestNotification($this->getExpectedType(), $value);
|
||||
}
|
||||
|
||||
public function invalidConstructorTypeDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(array('event' => $this->getExpectedEvent(), 'type' => 'test')),
|
||||
array(array('event' => $this->getExpectedEvent(), 'type' => null)),
|
||||
array(array('event' => $this->getExpectedEvent(), 'type' => '')),
|
||||
array(array('event' => $this->getExpectedEvent(), 'type' => 1)),
|
||||
array(array('event' => $this->getExpectedEvent(), 'type' => array())),
|
||||
);
|
||||
}
|
||||
|
||||
public function invalidConstructorEventDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(array('type' => $this->getExpectedType(), 'event' => 'test')),
|
||||
array(array('type' => $this->getExpectedType(), 'event' => null)),
|
||||
array(array('type' => $this->getExpectedType(), 'event' => '')),
|
||||
array(array('type' => $this->getExpectedType(), 'event' => 1)),
|
||||
array(array('type' => $this->getExpectedType(), 'event' => array())),
|
||||
);
|
||||
}
|
||||
|
||||
public function invalidTypeDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array(Random::str(40)),
|
||||
array(0),
|
||||
array(array()),
|
||||
array(new stdClass()),
|
||||
);
|
||||
}
|
||||
|
||||
public function invalidEventDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(''),
|
||||
array(null),
|
||||
array(Random::str(40)),
|
||||
array(0),
|
||||
array(array()),
|
||||
array(new stdClass()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TestNotification extends AbstractNotification
|
||||
{
|
||||
public function __construct($type, $event)
|
||||
{
|
||||
$this->setType($type);
|
||||
$this->setEvent($event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user