-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SorterTest.php
126 lines (114 loc) · 2.74 KB
/
SorterTest.php
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
<?php
declare(strict_types=1);
namespace Tests\Sorters;
use DragonCode\SizeSorter\Sorter;
use Tests\TestCase;
class SorterTest extends TestCase
{
private array $expected = [
// 1
105 => 'XXS',
138 => 'XXS',
137 => 'XXS/XS',
122 => 'XXS-XS',
108 => 'XS',
114 => 'XS/S',
109 => 'S',
127 => 'S/M',
110 => 'M',
115 => 'M/L',
111 => 'L',
112 => 'L/XL',
103 => 'XL',
113 => 'XL/2XL',
100 => 'XXL',
// 2
132 => '1',
106 => '2',
150 => '3',
149 => '21',
101 => 26,
102 => 28,
133 => '30',
134 => '32',
135 => '34',
121 => '36',
123 => 37,
124 => 38,
125 => '39',
126 => '40',
130 => '44-46',
136 => '44/46',
139 => '52-56',
107 => '54',
146 => '90/94',
147 => '94-98',
148 => '98-102',
140 => '102-104',
141 => '102-106',
142 => '102/106',
143 => '106',
145 => '110-112',
144 => '110-114',
// 3
118 => '70B',
129 => '70C',
119 => '75A',
120 => '75B',
117 => '75C',
116 => '80B',
// 4
156 => '39х38х15 см',
152 => '40х37х19 см',
153 => '40х37х20 см',
154 => '40х38х15 см',
151 => '40х38х19 sm',
128 => '40х38х19 см',
155 => '41х38х15 см',
// 5
104 => 'ONE SIZE',
131 => 'some',
];
public function testArray(): void
{
$this->assertSame(
$this->expected,
Sorter::sort($this->values)->toArray()
);
}
public function testObjects(): void
{
$items = collect($this->values)->map(fn (mixed $value, int $key) => (object) [
'id' => $key,
'value' => $value,
'active' => true,
]);
$this->assertSame(
$this->expected,
Sorter::sort($items)->pluck('value', 'id')->toArray()
);
}
public function testCustomColumn(): void
{
$items = collect($this->values)->map(fn (mixed $value, int $key) => (object) [
'id' => $key,
'some' => $value,
]);
$this->assertSame(
$this->expected,
Sorter::sort($items, 'some')->pluck('some', 'id')->toArray()
);
}
public function testWithSaveKeys(): void
{
$values = [
840 => 'XL',
506 => 'XS',
];
$expected = [
506 => 'XS',
840 => 'XL',
];
$this->assertSame($expected, Sorter::sort($values)->toArray());
}
}