@@ -98,11 +98,11 @@ public function conditionalAdd()
9898 ->addIfNotFalse ('number ' , 1 )
9999 ->addIfNotNull ('type ' , null )
100100 ->addIfNotNull ('test ' , 'Test ' )
101- ->ifTrue (fn () => true )
101+ ->ifTrue (fn () => true )
102102 ->addItem ('test2 ' , 'value2 ' )
103103 ->ifTrue (true )
104104 ->addItem ('test3 ' , 'value3 ' )
105- ->ifTrue (fn () => false )
105+ ->ifTrue (fn () => false )
106106 ->addItem ('test4 ' , 'value4 ' )
107107 ->ifTrue (false )
108108 ->addItem ('test5 ' , 'value5 ' )
@@ -143,16 +143,16 @@ public function mapCollection()
143143 'args ' => [
144144 [
145145 'name ' => 'default ' ,
146- 'type ' => 'string '
146+ 'type ' => 'string ' ,
147147 ],
148148 [
149149 'name ' => 'explicit ' ,
150- 'type ' => 'int '
150+ 'type ' => 'int ' ,
151151 ],
152- ]
152+ ],
153153 ];
154154
155- $ collection = Collection::map ($ array , function ($ val , $ key ) {
155+ $ collection = Collection::map ($ array , function ($ val , $ key ) {
156156 if ('constraints ' === $ key ) {
157157 $ collection = Collection::numeric ()->setMultiline ();
158158
@@ -203,16 +203,15 @@ public function mapCollection()
203203 */
204204 public function stringifyWithCustomConverter ()
205205 {
206- $ converter = new class implements ConverterInterface
207- {
206+ $ converter = new class () implements ConverterInterface {
208207 public function convert ($ value )
209208 {
210209 return new Text (ltrim ($ value , 'pre_ ' ));
211210 }
212211
213212 public function check ($ string ): bool
214213 {
215- if (\is_string ($ string ) && substr ($ string , 0 , 4 ) === ' pre_ ' ) {
214+ if (\is_string ($ string ) && ' pre_ ' === substr ($ string , 0 , 4 )) {
216215 return true ;
217216 }
218217
@@ -249,4 +248,41 @@ public function check($string): bool
249248 Collection::assoc ($ array )->addConverter ($ converter )->generate ()
250249 );
251250 }
251+
252+ /**
253+ * @test
254+ */
255+ public function orderBy ()
256+ {
257+ $ collection = Collection::assoc ();
258+
259+ $ collection
260+ ->addItem ('name ' , 'Timur ' )
261+ ->addItem ('age ' , 30 )
262+ ->addItem ('type ' , 'human ' )
263+ ->addItem ('friends ' , [])
264+ ;
265+
266+ $ collection ->setKeyOrder ('asc ' );
267+
268+ $ this ->assertEquals (<<<CODE
269+ [
270+ 'age' => 30,
271+ 'friends' => [],
272+ 'name' => 'Timur',
273+ 'type' => 'human',
274+ ]
275+ CODE , $ collection ->generate ());
276+
277+ $ collection ->setKeyOrder ('DESC ' );
278+
279+ $ this ->assertEquals (<<<CODE
280+ [
281+ 'type' => 'human',
282+ 'name' => 'Timur',
283+ 'friends' => [],
284+ 'age' => 30,
285+ ]
286+ CODE , $ collection ->generate ());
287+ }
252288}
0 commit comments