Repository navigation
Expand file tree
/
Copy pathArrayHelperSortValuesByNaturalTest.php
More file actions
130 lines (115 loc) · 3.26 KB
/
Copy pathArrayHelperSortValuesByNaturalTest.php
File metadata and controls
130 lines (115 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Helpers\Array;
use CodeIgniter\Test\CIUnitTestCase;
use PHPUnit\Framework\Attributes\Group;
/**
* @internal
*/
#[Group('Others')]
final class ArrayHelperSortValuesByNaturalTest extends CIUnitTestCase
{
/**
* @var list<int|string>
*/
private array $arrayWithStringValues = [
'apple10',
'banana',
'apple1',
'банан',
'Banana',
'Apple',
100000,
'яблоко',
1200,
13000,
'Банан',
'Яблоко',
'apple',
];
/**
* @var list<list<int|string>>
*/
private array $arrayWithArrayValues = [
['apple', 'Banana'],
['apple10', 'Apple'],
['Яблоко', 1200],
[13000, 'Банан'],
['Apple', 'apple1'],
['banana', 'банан'],
[100000, 13000],
['Banana', 'Яблоко'],
['Банан', 'banana'],
[1200, 'apple'],
['apple1', 'apple10'],
['яблоко', 100000],
['банан', 'яблоко'],
];
public function testSortWithStringValues(): void
{
shuffle($this->arrayWithStringValues);
ArrayHelper::sortValuesByNatural($this->arrayWithStringValues);
$this->assertSame([
1200,
13000,
100000,
'Apple',
'Banana',
'apple',
'apple1',
'apple10',
'banana',
'Банан',
'Яблоко',
'банан',
'яблоко',
], $this->arrayWithStringValues);
}
public function testSortWithArrayValues(): void
{
shuffle($this->arrayWithArrayValues);
// For first index
ArrayHelper::sortValuesByNatural($this->arrayWithArrayValues, 0);
$this->assertSame([
[1200, 'apple'],
[13000, 'Банан'],
[100000, 13000],
['Apple', 'apple1'],
['Banana', 'Яблоко'],
['apple', 'Banana'],
['apple1', 'apple10'],
['apple10', 'Apple'],
['banana', 'банан'],
['Банан', 'banana'],
['Яблоко', 1200],
['банан', 'яблоко'],
['яблоко', 100000],
], $this->arrayWithArrayValues);
shuffle($this->arrayWithArrayValues);
// For other index
ArrayHelper::sortValuesByNatural($this->arrayWithArrayValues, 1);
$this->assertSame([
['Яблоко', 1200],
[100000, 13000],
['яблоко', 100000],
['apple10', 'Apple'],
['apple', 'Banana'],
[1200, 'apple'],
['Apple', 'apple1'],
['apple1', 'apple10'],
['Банан', 'banana'],
[13000, 'Банан'],
['Banana', 'Яблоко'],
['banana', 'банан'],
['банан', 'яблоко'],
], $this->arrayWithArrayValues);
}
}