mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-08 00:47:55 +08:00
Add void return to method in tests. (#20602)
This commit is contained in:
@ -8,6 +8,14 @@
|
||||
|
||||
namespace yiiunit\framework\helpers;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use stdClass;
|
||||
use yii\helpers\UnsetArrayValue;
|
||||
use yii\helpers\ReplaceArrayValue;
|
||||
use ArrayObject;
|
||||
use Throwable;
|
||||
use ReturnTypeWillChange;
|
||||
use ArrayAccess;
|
||||
use Iterator;
|
||||
use yii\base\BaseObject;
|
||||
@ -29,7 +37,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->destroyApplication();
|
||||
}
|
||||
|
||||
public function testToArray()
|
||||
public function testToArray(): void
|
||||
{
|
||||
$dataArrayable = $this->getMockBuilder('yii\\base\\Arrayable')->getMock();
|
||||
$dataArrayable->method('toArray')->willReturn([]);
|
||||
@ -121,10 +129,10 @@ class ArrayHelperTest extends TestCase
|
||||
'date' => '2021-09-13 15:16:17.000000',
|
||||
'timezone_type' => 3,
|
||||
'timezone' => 'UTC',
|
||||
], ArrayHelper::toArray(new \DateTime('2021-09-13 15:16:17', new \DateTimeZone('UTC'))));
|
||||
], ArrayHelper::toArray(new DateTime('2021-09-13 15:16:17', new DateTimeZone('UTC'))));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
public function testRemove(): void
|
||||
{
|
||||
$array = ['name' => 'b', 'age' => 3];
|
||||
$name = ArrayHelper::remove($array, 'name');
|
||||
@ -139,7 +147,7 @@ class ArrayHelperTest extends TestCase
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRemoveWithFloat()
|
||||
public function testRemoveWithFloat(): void
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
|
||||
$this->markTestSkipped('Using floats as array key is deprecated.');
|
||||
@ -159,7 +167,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals('defaultValue', $default);
|
||||
}
|
||||
|
||||
public function testRemoveValueMultiple()
|
||||
public function testRemoveValueMultiple(): void
|
||||
{
|
||||
$array = [
|
||||
'Bob' => 'Dylan',
|
||||
@ -180,7 +188,7 @@ class ArrayHelperTest extends TestCase
|
||||
], $removed);
|
||||
}
|
||||
|
||||
public function testRemoveValueNotExisting()
|
||||
public function testRemoveValueNotExisting(): void
|
||||
{
|
||||
$array = [
|
||||
'Bob' => 'Dylan',
|
||||
@ -200,7 +208,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals([], $removed);
|
||||
}
|
||||
|
||||
public function testMultisort()
|
||||
public function testMultisort(): void
|
||||
{
|
||||
// empty key
|
||||
$dataEmpty = [];
|
||||
@ -250,17 +258,17 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals(['name' => 'B', 'age' => 4], $array[3]);
|
||||
}
|
||||
|
||||
public function testMultisortNestedObjects()
|
||||
public function testMultisortNestedObjects(): void
|
||||
{
|
||||
$obj1 = new \stdClass();
|
||||
$obj1 = new stdClass();
|
||||
$obj1->type = 'def';
|
||||
$obj1->owner = $obj1;
|
||||
|
||||
$obj2 = new \stdClass();
|
||||
$obj2 = new stdClass();
|
||||
$obj2->type = 'abc';
|
||||
$obj2->owner = $obj2;
|
||||
|
||||
$obj3 = new \stdClass();
|
||||
$obj3 = new stdClass();
|
||||
$obj3->type = 'abc';
|
||||
$obj3->owner = $obj3;
|
||||
|
||||
@ -283,7 +291,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($obj3, $models[2]);
|
||||
}
|
||||
|
||||
public function testMultisortUseSort()
|
||||
public function testMultisortUseSort(): void
|
||||
{
|
||||
// single key
|
||||
$sort = new Sort([
|
||||
@ -322,7 +330,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals(['name' => 'b', 'age' => 3], $array[2]);
|
||||
}
|
||||
|
||||
public function testMultisortClosure()
|
||||
public function testMultisortClosure(): void
|
||||
{
|
||||
$changelog = [
|
||||
'- Enh #123: test1',
|
||||
@ -349,21 +357,21 @@ class ArrayHelperTest extends TestCase
|
||||
], $changelog);
|
||||
}
|
||||
|
||||
public function testMultisortInvalidParamExceptionDirection()
|
||||
public function testMultisortInvalidParamExceptionDirection(): void
|
||||
{
|
||||
$this->expectException('yii\base\InvalidParamException');
|
||||
$data = ['foo' => 'bar'];
|
||||
ArrayHelper::multisort($data, ['foo'], []);
|
||||
}
|
||||
|
||||
public function testMultisortInvalidParamExceptionSortFlag()
|
||||
public function testMultisortInvalidParamExceptionSortFlag(): void
|
||||
{
|
||||
$this->expectException('yii\base\InvalidParamException');
|
||||
$data = ['foo' => 'bar'];
|
||||
ArrayHelper::multisort($data, ['foo'], ['foo'], []);
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
public function testMerge(): void
|
||||
{
|
||||
$a = [
|
||||
'name' => 'Yii',
|
||||
@ -415,7 +423,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeWithNumericKeys()
|
||||
public function testMergeWithNumericKeys(): void
|
||||
{
|
||||
$a = [10 => [1]];
|
||||
$b = [10 => [2]];
|
||||
@ -426,7 +434,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeWithUnset()
|
||||
public function testMergeWithUnset(): void
|
||||
{
|
||||
$a = [
|
||||
'name' => 'Yii',
|
||||
@ -441,7 +449,7 @@ class ArrayHelperTest extends TestCase
|
||||
];
|
||||
$b = [
|
||||
'version' => '1.1',
|
||||
'options' => new \yii\helpers\UnsetArrayValue(),
|
||||
'options' => new UnsetArrayValue(),
|
||||
'features' => [
|
||||
'gii',
|
||||
],
|
||||
@ -460,7 +468,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeWithReplace()
|
||||
public function testMergeWithReplace(): void
|
||||
{
|
||||
$a = [
|
||||
'name' => 'Yii',
|
||||
@ -478,7 +486,7 @@ class ArrayHelperTest extends TestCase
|
||||
'options' => [
|
||||
'unittest' => true,
|
||||
],
|
||||
'features' => new \yii\helpers\ReplaceArrayValue([
|
||||
'features' => new ReplaceArrayValue([
|
||||
'gii',
|
||||
]),
|
||||
];
|
||||
@ -499,7 +507,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeWithNullValues()
|
||||
public function testMergeWithNullValues(): void
|
||||
{
|
||||
$a = [
|
||||
'firstValue',
|
||||
@ -521,7 +529,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMergeEmpty()
|
||||
public function testMergeEmpty(): void
|
||||
{
|
||||
$this->assertEquals([], ArrayHelper::merge([], []));
|
||||
$this->assertEquals([], ArrayHelper::merge([], [], []));
|
||||
@ -530,7 +538,7 @@ class ArrayHelperTest extends TestCase
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/pull/11549
|
||||
*/
|
||||
public function testGetValueWithFloatKeys()
|
||||
public function testGetValueWithFloatKeys(): void
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
|
||||
$this->markTestSkipped('Using floats as array key is deprecated.');
|
||||
@ -547,7 +555,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
public function testIndex(): void
|
||||
{
|
||||
$array = [
|
||||
['id' => '123', 'data' => 'abc'],
|
||||
@ -585,7 +593,7 @@ class ArrayHelperTest extends TestCase
|
||||
], $result);
|
||||
}
|
||||
|
||||
public function testIndexGroupBy()
|
||||
public function testIndexGroupBy(): void
|
||||
{
|
||||
$array = [
|
||||
['id' => '123', 'data' => 'abc'],
|
||||
@ -668,7 +676,7 @@ class ArrayHelperTest extends TestCase
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/issues/11739
|
||||
*/
|
||||
public function testIndexFloat()
|
||||
public function testIndexFloat(): void
|
||||
{
|
||||
$array = [
|
||||
['id' => 1e6],
|
||||
@ -689,7 +697,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testGetColumn()
|
||||
public function testGetColumn(): void
|
||||
{
|
||||
$array = [
|
||||
'a' => ['id' => '123', 'data' => 'abc'],
|
||||
@ -710,7 +718,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals(['abc', 'def'], $result);
|
||||
}
|
||||
|
||||
public function testMap()
|
||||
public function testMap(): void
|
||||
{
|
||||
$array = [
|
||||
['id' => '123', 'name' => 'aaa', 'class' => 'x'],
|
||||
@ -790,7 +798,7 @@ class ArrayHelperTest extends TestCase
|
||||
], $result);
|
||||
}
|
||||
|
||||
public function testKeyExists()
|
||||
public function testKeyExists(): void
|
||||
{
|
||||
$array = [
|
||||
'a' => 1,
|
||||
@ -808,7 +816,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertFalse(ArrayHelper::keyExists('c', $array, false));
|
||||
}
|
||||
|
||||
public function testKeyExistsWithFloat()
|
||||
public function testKeyExistsWithFloat(): void
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
|
||||
$this->markTestSkipped('Using floats as array key is deprecated.');
|
||||
@ -829,7 +837,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertTrue(ArrayHelper::keyExists(3.3, $array));
|
||||
}
|
||||
|
||||
public function testKeyExistsArrayAccess()
|
||||
public function testKeyExistsArrayAccess(): void
|
||||
{
|
||||
$array = new TraversableArrayAccessibleObject([
|
||||
'a' => 1,
|
||||
@ -842,7 +850,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertFalse(ArrayHelper::keyExists('c', $array));
|
||||
}
|
||||
|
||||
public function testKeyExistsArrayAccessCaseInsensitiveThrowsError()
|
||||
public function testKeyExistsArrayAccessCaseInsensitiveThrowsError(): void
|
||||
{
|
||||
$this->expectException('yii\base\InvalidArgumentException');
|
||||
$this->expectExceptionMessage('Second parameter($array) cannot be ArrayAccess in case insensitive mode');
|
||||
@ -890,7 +898,7 @@ class ArrayHelperTest extends TestCase
|
||||
* @param $expected
|
||||
* @param null $default
|
||||
*/
|
||||
public function testGetValue($key, $expected, $default = null)
|
||||
public function testGetValue($key, $expected, $default = null): void
|
||||
{
|
||||
$array = [
|
||||
'name' => 'test',
|
||||
@ -919,32 +927,32 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, ArrayHelper::getValue($array, $key, $default));
|
||||
}
|
||||
|
||||
public function testGetValueObjects()
|
||||
public function testGetValueObjects(): void
|
||||
{
|
||||
$arrayObject = new \ArrayObject(['id' => 23], \ArrayObject::ARRAY_AS_PROPS);
|
||||
$arrayObject = new ArrayObject(['id' => 23], ArrayObject::ARRAY_AS_PROPS);
|
||||
$this->assertEquals(23, ArrayHelper::getValue($arrayObject, 'id'));
|
||||
|
||||
$object = new Post1();
|
||||
$this->assertEquals(23, ArrayHelper::getValue($object, 'id'));
|
||||
}
|
||||
|
||||
public function testGetValueNonexistingProperties1()
|
||||
public function testGetValueNonexistingProperties1(): void
|
||||
{
|
||||
try {
|
||||
$object = new Post1();
|
||||
ArrayHelper::getValue($object, 'nonExisting');
|
||||
} catch (\Throwable $th) {
|
||||
} catch (Throwable $th) {
|
||||
$this->assertEquals('Undefined property: yiiunit\framework\helpers\Post1::$nonExisting', $th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetValueNonexistingPropertiesForArrayObject()
|
||||
public function testGetValueNonexistingPropertiesForArrayObject(): void
|
||||
{
|
||||
$arrayObject = new \ArrayObject(['id' => 23], \ArrayObject::ARRAY_AS_PROPS);
|
||||
$arrayObject = new ArrayObject(['id' => 23], ArrayObject::ARRAY_AS_PROPS);
|
||||
$this->assertNull(ArrayHelper::getValue($arrayObject, 'nonExisting'));
|
||||
}
|
||||
|
||||
public function testGetValueFromArrayAccess()
|
||||
public function testGetValueFromArrayAccess(): void
|
||||
{
|
||||
$arrayAccessibleObject = new ArrayAccessibleObject([
|
||||
'one' => 1,
|
||||
@ -957,7 +965,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals(1, ArrayHelper::getValue($arrayAccessibleObject, 'one'));
|
||||
}
|
||||
|
||||
public function testGetValueWithDotsFromArrayAccess()
|
||||
public function testGetValueWithDotsFromArrayAccess(): void
|
||||
{
|
||||
$arrayAccessibleObject = new ArrayAccessibleObject([
|
||||
'one' => 1,
|
||||
@ -970,7 +978,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals('dot', ArrayHelper::getValue($arrayAccessibleObject, 'key.with.dot'));
|
||||
}
|
||||
|
||||
public function testGetValueNonexistingArrayAccess()
|
||||
public function testGetValueNonexistingArrayAccess(): void
|
||||
{
|
||||
$arrayAccessibleObject = new ArrayAccessibleObject([
|
||||
'one' => 1,
|
||||
@ -1217,13 +1225,13 @@ class ArrayHelperTest extends TestCase
|
||||
* @param mixed $value
|
||||
* @param mixed $expected
|
||||
*/
|
||||
public function testSetValue($array_input, $key, $value, $expected)
|
||||
public function testSetValue($array_input, $key, $value, $expected): void
|
||||
{
|
||||
ArrayHelper::setValue($array_input, $key, $value);
|
||||
$this->assertEquals($expected, $array_input);
|
||||
}
|
||||
|
||||
public function testIsAssociative()
|
||||
public function testIsAssociative(): void
|
||||
{
|
||||
$this->assertFalse(ArrayHelper::isAssociative('test'));
|
||||
$this->assertFalse(ArrayHelper::isAssociative([]));
|
||||
@ -1234,7 +1242,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertTrue(ArrayHelper::isAssociative(['name' => 1, 'value' => 'test', 3], false));
|
||||
}
|
||||
|
||||
public function testIsIndexed()
|
||||
public function testIsIndexed(): void
|
||||
{
|
||||
$this->assertFalse(ArrayHelper::isIndexed('test'));
|
||||
$this->assertTrue(ArrayHelper::isIndexed([]));
|
||||
@ -1244,7 +1252,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertFalse(ArrayHelper::isIndexed(['a' => 'b'], false));
|
||||
}
|
||||
|
||||
public function testHtmlEncode()
|
||||
public function testHtmlEncode(): void
|
||||
{
|
||||
$array = [
|
||||
'abc' => '123',
|
||||
@ -1281,7 +1289,7 @@ class ArrayHelperTest extends TestCase
|
||||
], ArrayHelper::htmlEncode($array, false));
|
||||
}
|
||||
|
||||
public function testHtmlDecode()
|
||||
public function testHtmlDecode(): void
|
||||
{
|
||||
$array = [
|
||||
'abc' => '123',
|
||||
@ -1321,70 +1329,70 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, ArrayHelper::htmlDecode($array, false));
|
||||
}
|
||||
|
||||
public function testIsIn()
|
||||
public function testIsIn(): void
|
||||
{
|
||||
$this->assertTrue(ArrayHelper::isIn('a', new \ArrayObject(['a', 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isIn('a', new ArrayObject(['a', 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isIn('a', ['a', 'b']));
|
||||
|
||||
$this->assertTrue(ArrayHelper::isIn('1', new \ArrayObject([1, 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isIn('1', new ArrayObject([1, 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isIn('1', [1, 'b']));
|
||||
|
||||
$this->assertFalse(ArrayHelper::isIn('1', new \ArrayObject([1, 'b']), true));
|
||||
$this->assertFalse(ArrayHelper::isIn('1', new ArrayObject([1, 'b']), true));
|
||||
$this->assertFalse(ArrayHelper::isIn('1', [1, 'b'], true));
|
||||
|
||||
$this->assertTrue(ArrayHelper::isIn(['a'], new \ArrayObject([['a'], 'b'])));
|
||||
$this->assertFalse(ArrayHelper::isIn('a', new \ArrayObject([['a'], 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isIn(['a'], new ArrayObject([['a'], 'b'])));
|
||||
$this->assertFalse(ArrayHelper::isIn('a', new ArrayObject([['a'], 'b'])));
|
||||
$this->assertFalse(ArrayHelper::isIn('a', [['a'], 'b']));
|
||||
}
|
||||
|
||||
public function testIsInStrict()
|
||||
public function testIsInStrict(): void
|
||||
{
|
||||
// strict comparison
|
||||
$this->assertTrue(ArrayHelper::isIn(1, new \ArrayObject([1, 'a']), true));
|
||||
$this->assertTrue(ArrayHelper::isIn(1, new ArrayObject([1, 'a']), true));
|
||||
$this->assertTrue(ArrayHelper::isIn(1, [1, 'a'], true));
|
||||
|
||||
$this->assertFalse(ArrayHelper::isIn('1', new \ArrayObject([1, 'a']), true));
|
||||
$this->assertFalse(ArrayHelper::isIn('1', new ArrayObject([1, 'a']), true));
|
||||
$this->assertFalse(ArrayHelper::isIn('1', [1, 'a'], true));
|
||||
}
|
||||
|
||||
public function testInException()
|
||||
public function testInException(): void
|
||||
{
|
||||
$this->expectException('yii\base\InvalidParamException');
|
||||
$this->expectExceptionMessage('Argument $haystack must be an array or implement Traversable');
|
||||
ArrayHelper::isIn('value', null);
|
||||
}
|
||||
|
||||
public function testIsSubset()
|
||||
public function testIsSubset(): void
|
||||
{
|
||||
$this->assertTrue(ArrayHelper::isSubset(['a'], new \ArrayObject(['a', 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isSubset(new \ArrayObject(['a']), ['a', 'b']));
|
||||
$this->assertTrue(ArrayHelper::isSubset(['a'], new ArrayObject(['a', 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isSubset(new ArrayObject(['a']), ['a', 'b']));
|
||||
|
||||
$this->assertTrue(ArrayHelper::isSubset([1], new \ArrayObject(['1', 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isSubset(new \ArrayObject([1]), ['1', 'b']));
|
||||
$this->assertTrue(ArrayHelper::isSubset([1], new ArrayObject(['1', 'b'])));
|
||||
$this->assertTrue(ArrayHelper::isSubset(new ArrayObject([1]), ['1', 'b']));
|
||||
|
||||
$this->assertFalse(ArrayHelper::isSubset([1], new \ArrayObject(['1', 'b']), true));
|
||||
$this->assertFalse(ArrayHelper::isSubset(new \ArrayObject([1]), ['1', 'b'], true));
|
||||
$this->assertFalse(ArrayHelper::isSubset([1], new ArrayObject(['1', 'b']), true));
|
||||
$this->assertFalse(ArrayHelper::isSubset(new ArrayObject([1]), ['1', 'b'], true));
|
||||
}
|
||||
|
||||
public function testIsSubsetException()
|
||||
public function testIsSubsetException(): void
|
||||
{
|
||||
$this->expectException('yii\base\InvalidParamException');
|
||||
$this->expectExceptionMessage('Argument $needles must be an array or implement Traversable');
|
||||
ArrayHelper::isSubset('a', new \ArrayObject(['a', 'b']));
|
||||
ArrayHelper::isSubset('a', new ArrayObject(['a', 'b']));
|
||||
}
|
||||
|
||||
public function testIsArray()
|
||||
public function testIsArray(): void
|
||||
{
|
||||
$this->assertTrue(ArrayHelper::isTraversable(['a']));
|
||||
$this->assertTrue(ArrayHelper::isTraversable(new \ArrayObject(['1'])));
|
||||
$this->assertFalse(ArrayHelper::isTraversable(new \stdClass()));
|
||||
$this->assertTrue(ArrayHelper::isTraversable(new ArrayObject(['1'])));
|
||||
$this->assertFalse(ArrayHelper::isTraversable(new stdClass()));
|
||||
$this->assertFalse(ArrayHelper::isTraversable('A,B,C'));
|
||||
$this->assertFalse(ArrayHelper::isTraversable(12));
|
||||
$this->assertFalse(ArrayHelper::isTraversable(false));
|
||||
$this->assertFalse(ArrayHelper::isTraversable(null));
|
||||
}
|
||||
|
||||
public function testFilter()
|
||||
public function testFilter(): void
|
||||
{
|
||||
$array = [
|
||||
'A' => [
|
||||
@ -1508,7 +1516,7 @@ class ArrayHelperTest extends TestCase
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/issues/18395
|
||||
*/
|
||||
public function testFilterForIntegerKeys()
|
||||
public function testFilterForIntegerKeys(): void
|
||||
{
|
||||
$array = ['a', 'b', ['c', 'd']];
|
||||
|
||||
@ -1518,18 +1526,18 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals([2 => [1 => 'd']], ArrayHelper::filter($array, [2, '!2.0']));
|
||||
}
|
||||
|
||||
public function testFilterWithInvalidValues()
|
||||
public function testFilterWithInvalidValues(): void
|
||||
{
|
||||
$array = ['a' => 'b'];
|
||||
|
||||
$this->assertEquals([], ArrayHelper::filter($array, [new \stdClass()]));
|
||||
$this->assertEquals([], ArrayHelper::filter($array, [new stdClass()]));
|
||||
$this->assertEquals([], ArrayHelper::filter($array, [['a']]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/yiisoft/yii2/issues/18086
|
||||
*/
|
||||
public function testArrayAccessWithPublicProperty()
|
||||
public function testArrayAccessWithPublicProperty(): void
|
||||
{
|
||||
$data = new ArrayAccessibleObject(['value' => 123]);
|
||||
|
||||
@ -1541,7 +1549,7 @@ class ArrayHelperTest extends TestCase
|
||||
* https://github.com/yiisoft/yii2/commit/35fb9c624893855317e5fe52e6a21f6518a9a31c changed the way
|
||||
* ArrayHelper works with existing object properties in case of ArrayAccess.
|
||||
*/
|
||||
public function testArrayAccessWithMagicProperty()
|
||||
public function testArrayAccessWithMagicProperty(): void
|
||||
{
|
||||
$model = new MagicModel();
|
||||
$this->assertEquals(42, ArrayHelper::getValue($model, 'magic'));
|
||||
@ -1553,7 +1561,7 @@ class ArrayHelperTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRecursiveSort($expected_result, $input_array)
|
||||
public function testRecursiveSort($expected_result, $input_array): void
|
||||
{
|
||||
$actual = ArrayHelper::recursiveSort($input_array);
|
||||
$this->assertEquals($expected_result, $actual);
|
||||
@ -1614,7 +1622,7 @@ class ArrayHelperTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function testFlatten()
|
||||
public function testFlatten(): void
|
||||
{
|
||||
// Test with deeply nested arrays
|
||||
$array = [
|
||||
@ -1703,7 +1711,7 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testFlattenEdgeCases()
|
||||
public function testFlattenEdgeCases(): void
|
||||
{
|
||||
// Empty array
|
||||
$array = [];
|
||||
@ -1758,7 +1766,7 @@ class Post3 extends BaseObject
|
||||
/** @var BaseObject */
|
||||
public $subObject;
|
||||
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
$this->subObject = new Post2();
|
||||
}
|
||||
@ -1774,8 +1782,8 @@ class ArrayAccessibleObject implements ArrayAccess
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value)
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if (is_null($offset)) {
|
||||
$this->container[] = $value;
|
||||
@ -1784,19 +1792,19 @@ class ArrayAccessibleObject implements ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return array_key_exists($offset, $this->container);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($offset)
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
unset($this->container[$offset]);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->offsetExists($offset) ? $this->container[$offset] : null;
|
||||
@ -1820,31 +1828,31 @@ class TraversableArrayAccessibleObject extends ArrayAccessibleObject implements
|
||||
return array_key_exists($keyIndex, $keys) ? $keys[$keyIndex] : false;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
#[ReturnTypeWillChange]
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
#[ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
return $this->offsetGet($this->getContainerKey($this->position));
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
#[ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return $this->getContainerKey($this->position);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function next()
|
||||
#[ReturnTypeWillChange]
|
||||
public function next(): void
|
||||
{
|
||||
++$this->position;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
#[ReturnTypeWillChange]
|
||||
public function valid()
|
||||
{
|
||||
$key = $this->getContainerKey($this->position);
|
||||
|
||||
Reference in New Issue
Block a user