@@ -79,6 +79,7 @@ public static function provideIndexOf(): array
79
79
[0 , 'abc ' , 'a ' , 0 ],
80
80
[1 , 'abc ' , 'b ' , 1 ],
81
81
[2 , 'abc ' , 'c ' , 1 ],
82
+ [4 , 'abacabab ' , 'ab ' , 1 ],
82
83
[4 , '123abc ' , 'b ' , -3 ],
83
84
];
84
85
}
@@ -109,6 +110,7 @@ public static function provideIndexOfIgnoreCase(): array
109
110
[1 , 'ABC ' , 'b ' , 1 ],
110
111
[2 , 'ABC ' , 'c ' , 0 ],
111
112
[2 , 'ABC ' , 'c ' , 2 ],
113
+ [4 , 'ABACaBAB ' , 'Ab ' , 1 ],
112
114
[4 , '123abc ' , 'B ' , -3 ],
113
115
];
114
116
}
@@ -173,9 +175,9 @@ public static function provideIndexOfLastIgnoreCase(): array
173
175
/**
174
176
* @dataProvider provideSplit
175
177
*/
176
- public function testSplit (string $ string , string $ delimiter , array $ chunks , ?int $ limit )
178
+ public function testSplit (string $ string , string $ delimiter , array $ chunks , ?int $ limit, int $ flags = null )
177
179
{
178
- $ this ->assertEquals ($ chunks , static ::createFromString ($ string )->split ($ delimiter , $ limit ));
180
+ $ this ->assertEquals ($ chunks , static ::createFromString ($ string )->split ($ delimiter , $ limit, $ flags ));
179
181
}
180
182
181
183
public static function provideSplit (): array
@@ -240,6 +242,44 @@ public static function provideSplit(): array
240
242
],
241
243
null ,
242
244
],
245
+ [
246
+ 'foo,,bar, baz , qux,kix ' ,
247
+ '/\s*,\s*/ ' ,
248
+ [
249
+ static ::createFromString ('foo ' ),
250
+ static ::createFromString ('' ),
251
+ static ::createFromString ('bar ' ),
252
+ static ::createFromString ('baz ' ),
253
+ static ::createFromString ('qux,kix ' ),
254
+ ],
255
+ 5 ,
256
+ AbstractString::PREG_SPLIT ,
257
+ ],
258
+ [
259
+ 'foo ,,bar, baz ' ,
260
+ '/\s*(,)\s*/ ' ,
261
+ [
262
+ static ::createFromString ('foo ' ),
263
+ static ::createFromString (', ' ),
264
+ static ::createFromString (', ' ),
265
+ static ::createFromString ('bar ' ),
266
+ static ::createFromString (', ' ),
267
+ static ::createFromString ('baz ' ),
268
+ ],
269
+ null ,
270
+ AbstractString::PREG_SPLIT_NO_EMPTY |AbstractString::PREG_SPLIT_DELIM_CAPTURE ,
271
+ ],
272
+ [
273
+ 'foo, bar,baz ' ,
274
+ '/\s*(,)\s*/ ' ,
275
+ [
276
+ [static ::createFromString ('foo ' ), 0 ],
277
+ [static ::createFromString ('bar ' ), 5 ],
278
+ [static ::createFromString ('baz ' ), 9 ],
279
+ ],
280
+ null ,
281
+ AbstractString::PREG_SPLIT_OFFSET_CAPTURE ,
282
+ ],
243
283
];
244
284
}
245
285
@@ -351,7 +391,7 @@ public static function provideLower()
351
391
return [
352
392
['hello world ' , 'hello world ' ],
353
393
['hello world ' , 'HELLO WORLD ' ],
354
- ['hello world ' , 'Hello World ' ],
394
+ ['hello world! ' , 'Hello World! ' ],
355
395
['symfony ' , 'symfony ' ],
356
396
['symfony ' , 'Symfony ' ],
357
397
['symfony ' , 'sYmFOny ' ],
@@ -375,7 +415,7 @@ public static function provideUpper()
375
415
return [
376
416
['HELLO WORLD ' , 'hello world ' ],
377
417
['HELLO WORLD ' , 'HELLO WORLD ' ],
378
- ['HELLO WORLD ' , 'Hello World ' ],
418
+ ['HELLO WORLD! ' , 'Hello World! ' ],
379
419
['SYMFONY ' , 'symfony ' ],
380
420
['SYMFONY ' , 'Symfony ' ],
381
421
['SYMFONY ' , 'sYmFOny ' ],
@@ -425,8 +465,11 @@ public static function provideSlice()
425
465
['Symfony ' , 'Symfony is awesome ' , 0 , 7 ],
426
466
[' ' , 'Symfony is awesome ' , 7 , 1 ],
427
467
['is ' , 'Symfony is awesome ' , 8 , 2 ],
468
+ ['is awesome ' , 'Symfony is awesome ' , 8 , null ],
428
469
[' ' , 'Symfony is awesome ' , 10 , 1 ],
429
470
['awesome ' , 'Symfony is awesome ' , 11 , 7 ],
471
+ ['awesome ' , 'Symfony is awesome ' , -7 , null ],
472
+ ['awe ' , 'Symfony is awesome ' , -7 , -4 ],
430
473
];
431
474
}
432
475
@@ -450,6 +493,10 @@ public function testAppend(string $expected, array $suffixes)
450
493
public static function provideAppend ()
451
494
{
452
495
return [
496
+ [
497
+ '' ,
498
+ [],
499
+ ],
453
500
[
454
501
'Symfony ' ,
455
502
['Sym ' , 'fony ' ],
@@ -512,6 +559,11 @@ public static function provideTrim()
512
559
" Symfony IS GREAT \t!!! \n" ,
513
560
" \n! " ,
514
561
],
562
+ [
563
+ "Symfony IS GREAT \t!!! \n" ,
564
+ " Symfony IS GREAT \t!!! \n" ,
565
+ ' ' ,
566
+ ],
515
567
];
516
568
}
517
569
@@ -566,102 +618,125 @@ public static function provideTrimEnd()
566
618
"\n\t<span>Symfony is a PHP framework</span> \n" ,
567
619
"\n" ,
568
620
],
621
+ [
622
+ "\n\t<span>Symfony is a PHP framework</span> \n" ,
623
+ "\n\t<span>Symfony is a PHP framework</span> \n" ,
624
+ ' ' ,
625
+ ],
569
626
];
570
627
}
571
628
572
629
/**
573
630
* @dataProvider provideBeforeAfter
574
631
*/
575
- public function testBeforeAfter (string $ expected , string $ needle , string $ origin , bool $ before )
632
+ public function testBeforeAfter (string $ expected , string $ needle , string $ origin , int $ offset , bool $ before )
576
633
{
577
634
$ result = static ::createFromString ($ origin );
578
- $ result = $ before ? $ result ->before ($ needle , false ) : $ result ->after ($ needle , true );
635
+ $ result = $ before ? $ result ->before ($ needle , false , $ offset ) : $ result ->after ($ needle , true , $ offset );
579
636
$ this ->assertEquals (static ::createFromString ($ expected ), $ result );
580
637
}
581
638
582
639
public static function provideBeforeAfter ()
583
640
{
584
641
return [
585
- ['' , '' , 'hello world ' , true ],
586
- ['' , '' , 'hello world ' , false ],
587
- ['' , 'w ' , 'hello World ' , true ],
588
- ['' , 'w ' , 'hello World ' , false ],
589
- ['hello ' , 'w ' , 'hello world ' , true ],
590
- ['world ' , 'w ' , 'hello world ' , false ],
642
+ ['' , '' , 'hello world ' , 0 , true ],
643
+ ['' , '' , 'hello world ' , 0 , false ],
644
+ ['' , 'w ' , 'hello World ' , 0 , true ],
645
+ ['' , 'w ' , 'hello World ' , 0 , false ],
646
+ ['' , 'o ' , 'hello world ' , 10 , true ],
647
+ ['' , 'o ' , 'hello world ' , 10 , false ],
648
+ ['hello ' , 'w ' , 'hello world ' , 0 , true ],
649
+ ['world ' , 'w ' , 'hello world ' , 0 , false ],
650
+ ['hello W ' , 'O ' , 'hello WORLD ' , 0 , true ],
651
+ ['ORLD ' , 'O ' , 'hello WORLD ' , 0 , false ],
652
+ ['abac ' , 'ab ' , 'abacabab ' , 1 , true ],
653
+ ['abab ' , 'ab ' , 'abacabab ' , 1 , false ],
591
654
];
592
655
}
593
656
594
657
/**
595
658
* @dataProvider provideBeforeAfterIgnoreCase
596
659
*/
597
- public function testBeforeAfterIgnoreCase (string $ expected , string $ needle , string $ origin , bool $ before )
660
+ public function testBeforeAfterIgnoreCase (string $ expected , string $ needle , string $ origin , int $ offset , bool $ before )
598
661
{
599
662
$ result = static ::createFromString ($ origin )->ignoreCase ();
600
- $ result = $ before ? $ result ->before ($ needle , false ) : $ result ->after ($ needle , true );
663
+ $ result = $ before ? $ result ->before ($ needle , false , $ offset ) : $ result ->after ($ needle , true , $ offset );
601
664
$ this ->assertEquals (static ::createFromString ($ expected ), $ result );
602
665
}
603
666
604
667
public static function provideBeforeAfterIgnoreCase ()
605
668
{
606
669
return [
607
- ['' , '' , 'hello world ' , true ],
608
- ['' , '' , 'hello world ' , false ],
609
- ['' , 'foo ' , 'hello world ' , true ],
610
- ['' , 'foo ' , 'hello world ' , false ],
611
- ['hello ' , 'w ' , 'hello world ' , true ],
612
- ['world ' , 'w ' , 'hello world ' , false ],
613
- ['hello ' , 'W ' , 'hello world ' , true ],
614
- ['world ' , 'W ' , 'hello world ' , false ],
670
+ ['' , '' , 'hello world ' , 0 , true ],
671
+ ['' , '' , 'hello world ' , 0 , false ],
672
+ ['' , 'foo ' , 'hello world ' , 0 , true ],
673
+ ['' , 'foo ' , 'hello world ' , 0 , false ],
674
+ ['' , 'o ' , 'hello world ' , 10 , true ],
675
+ ['' , 'o ' , 'hello world ' , 10 , false ],
676
+ ['hello ' , 'w ' , 'hello world ' , 0 , true ],
677
+ ['world ' , 'w ' , 'hello world ' , 0 , false ],
678
+ ['hello ' , 'W ' , 'hello world ' , 0 , true ],
679
+ ['world ' , 'W ' , 'hello world ' , 0 , false ],
680
+ ['Abac ' , 'Ab ' , 'AbacaBAb ' , 1 , true ],
681
+ ['aBAb ' , 'Ab ' , 'AbacaBAb ' , 1 , false ],
615
682
];
616
683
}
617
684
618
685
/**
619
686
* @dataProvider provideBeforeAfterLast
620
687
*/
621
- public function testBeforeAfterLast (string $ expected , string $ needle , string $ origin , bool $ before )
688
+ public function testBeforeAfterLast (string $ expected , string $ needle , string $ origin , int $ offset , bool $ before )
622
689
{
623
690
$ result = static ::createFromString ($ origin );
624
- $ result = $ before ? $ result ->beforeLast ($ needle , false ) : $ result ->afterLast ($ needle , true );
691
+ $ result = $ before ? $ result ->beforeLast ($ needle , false , $ offset ) : $ result ->afterLast ($ needle , true , $ offset );
625
692
$ this ->assertEquals (static ::createFromString ($ expected ), $ result );
626
693
}
627
694
628
695
public static function provideBeforeAfterLast ()
629
696
{
630
697
return [
631
- ['' , '' , 'hello world ' , true ],
632
- ['' , '' , 'hello world ' , false ],
633
- ['' , 'L ' , 'hello world ' , true ],
634
- ['' , 'L ' , 'hello world ' , false ],
635
- ['hello wor ' , 'l ' , 'hello world ' , true ],
636
- ['ld ' , 'l ' , 'hello world ' , false ],
637
- ['hello w ' , 'o ' , 'hello world ' , true ],
638
- ['orld ' , 'o ' , 'hello world ' , false ],
698
+ ['' , '' , 'hello world ' , 0 , true ],
699
+ ['' , '' , 'hello world ' , 0 , false ],
700
+ ['' , 'L ' , 'hello world ' , 0 , true ],
701
+ ['' , 'L ' , 'hello world ' , 0 , false ],
702
+ ['' , 'o ' , 'hello world ' , 10 , true ],
703
+ ['' , 'o ' , 'hello world ' , 10 , false ],
704
+ ['hello wor ' , 'l ' , 'hello world ' , 0 , true ],
705
+ ['ld ' , 'l ' , 'hello world ' , 0 , false ],
706
+ ['hello w ' , 'o ' , 'hello world ' , 0 , true ],
707
+ ['orld ' , 'o ' , 'hello world ' , 0 , false ],
708
+ ['abacab ' , 'ab ' , 'abacabab ' , 1 , true ],
709
+ ['ab ' , 'ab ' , 'abacabab ' , 1 , false ],
639
710
];
640
711
}
641
712
642
713
/**
643
714
* @dataProvider provideBeforeAfterLastIgnoreCase
644
715
*/
645
- public function testBeforeAfterLastIgnoreCase (string $ expected , string $ needle , string $ origin , bool $ before )
716
+ public function testBeforeAfterLastIgnoreCase (string $ expected , string $ needle , string $ origin , int $ offset , bool $ before )
646
717
{
647
718
$ result = static ::createFromString ($ origin )->ignoreCase ();
648
- $ result = $ before ? $ result ->beforeLast ($ needle , false ) : $ result ->afterLast ($ needle , true );
719
+ $ result = $ before ? $ result ->beforeLast ($ needle , false , $ offset ) : $ result ->afterLast ($ needle , true , $ offset );
649
720
$ this ->assertEquals (static ::createFromString ($ expected ), $ result );
650
721
}
651
722
652
723
public static function provideBeforeAfterLastIgnoreCase ()
653
724
{
654
725
return [
655
- ['' , '' , 'hello world ' , true ],
656
- ['' , '' , 'hello world ' , false ],
657
- ['' , 'FOO ' , 'hello world ' , true ],
658
- ['' , 'FOO ' , 'hello world ' , false ],
659
- ['hello wor ' , 'l ' , 'hello world ' , true ],
660
- ['ld ' , 'l ' , 'hello world ' , false ],
661
- ['hello wor ' , 'L ' , 'hello world ' , true ],
662
- ['ld ' , 'L ' , 'hello world ' , false ],
663
- ['hello w ' , 'O ' , 'hello world ' , true ],
664
- ['orld ' , 'O ' , 'hello world ' , false ],
726
+ ['' , '' , 'hello world ' , 0 , true ],
727
+ ['' , '' , 'hello world ' , 0 , false ],
728
+ ['' , 'FOO ' , 'hello world ' , 0 , true ],
729
+ ['' , 'FOO ' , 'hello world ' , 0 , false ],
730
+ ['' , 'o ' , 'hello world ' , 10 , true ],
731
+ ['' , 'o ' , 'hello world ' , 10 , false ],
732
+ ['hello wor ' , 'l ' , 'hello world ' , 0 , true ],
733
+ ['ld ' , 'l ' , 'hello world ' , 0 , false ],
734
+ ['hello wor ' , 'L ' , 'hello world ' , 0 , true ],
735
+ ['ld ' , 'L ' , 'hello world ' , 0 , false ],
736
+ ['hello w ' , 'O ' , 'hello world ' , 0 , true ],
737
+ ['orld ' , 'O ' , 'hello world ' , 0 , false ],
738
+ ['AbacaB ' , 'Ab ' , 'AbacaBaB ' , 1 , true ],
739
+ ['aB ' , 'Ab ' , 'AbacaBaB ' , 1 , false ],
665
740
];
666
741
}
667
742
@@ -729,4 +804,49 @@ public static function provideReplaceIgnoreCase()
729
804
['heMMo worMd ' , 3 , 'hello world ' , 'L ' , 'M ' ],
730
805
];
731
806
}
807
+
808
+ /**
809
+ * @dataProvider provideCamel
810
+ */
811
+ public function testCamel (string $ expectedString , string $ origin )
812
+ {
813
+ $ instance = static ::createFromString ($ origin )->camel ();
814
+
815
+ $ this ->assertEquals (static ::createFromString ($ expectedString ), $ instance );
816
+ }
817
+
818
+ public static function provideCamel ()
819
+ {
820
+ return [
821
+ ['' , '' ],
822
+ ['symfonyIsGreat ' , 'symfony_is_great ' ],
823
+ ['symfony5IsGreat ' , 'symfony_5_is_great ' ],
824
+ ['symfonyIsGreat ' , 'Symfony is great ' ],
825
+ ['symfonyIsAGreatFramework ' , 'Symfony is a great framework ' ],
826
+ ['symfonyIsGREAT ' , '*Symfony* is GREAT!! ' ],
827
+ ];
828
+ }
829
+
830
+ /**
831
+ * @dataProvider provideSnake
832
+ */
833
+ public function testSnake (string $ expectedString , string $ origin )
834
+ {
835
+ $ instance = static ::createFromString ($ origin )->snake ();
836
+
837
+ $ this ->assertEquals (static ::createFromString ($ expectedString ), $ instance );
838
+ }
839
+
840
+ public static function provideSnake ()
841
+ {
842
+ return [
843
+ ['' , '' ],
844
+ ['symfony_is_great ' , 'symfonyIsGreat ' ],
845
+ ['symfony5_is_great ' , 'symfony5IsGreat ' ],
846
+ ['symfony_is_great ' , 'Symfony is great ' ],
847
+ ['symfony_is_a_great_framework ' , 'symfonyIsAGreatFramework ' ],
848
+ ['symfony_is_great ' , 'symfonyIsGREAT ' ],
849
+ ['symfony_is_really_great ' , 'symfonyIsREALLYGreat ' ],
850
+ ];
851
+ }
732
852
}
0 commit comments