@@ -763,4 +763,30 @@ public function testInvalidTrimPattern(): void
763
763
764
764
StringHelper::trim ('string ' , "\xC3\x28" );
765
765
}
766
+
767
+ /**
768
+ * @dataProvider dataProviderFindBetween
769
+ */
770
+ public function testFindBetween (string $ string , string $ start , string $ end , string $ expectedResult ): void
771
+ {
772
+ $ this ->assertSame ($ expectedResult , StringHelper::findBetween ($ string , $ start , $ end ));
773
+ }
774
+
775
+ public function dataProviderFindBetween (): array
776
+ {
777
+ return [
778
+ ['hello world hello ' , ' hello ' , ' world ' , null ], // end before start
779
+ ['This is a sample string ' , ' is ' , ' string ' , 'a sample ' ], // normal case
780
+ ['startendstart ' , 'start ' , 'end ' , '' ], // end before start
781
+ ['startmiddleend ' , 'start ' , 'end ' , 'middle ' ], // normal case
782
+ ['startend ' , 'start ' , 'end ' , '' ], // end immediately follows start
783
+ ['multiple start start end end ' , 'start ' , ' end ' , 'start end ' ], // multiple starts and ends
784
+ ['' , 'start ' , 'end ' , null ], // empty string
785
+ ['no delimiters here ' , 'start ' , 'end ' , null ], // no start and end
786
+ ['start only ' , 'start ' , 'end ' , null ], // start found but no end
787
+ ['end only ' , 'start ' , 'end ' , null ], // end found but no start
788
+ ['spécial !@#$%^&*() ' , 'spé ' , '&*() ' , 'cial !@#$%^ ' ], // Special characters
789
+ ['من صالح هاشمی هستم ' , 'من ' , ' هستم ' , 'صالح هاشمی ' ], // other languages
790
+ ];
791
+ }
766
792
}
0 commit comments