This repository was archived by the owner on Feb 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 33
44class StringUtils {
55
6+ public static function contains ($ string , $ search ) {
7+ return empty ($ search ) || strpos ($ string , $ search ) !== false ;
8+ }
9+
610 public static function startsWith ($ string , $ prefix ) {
711 return empty ($ prefix ) || strrpos ($ string , $ prefix , -strlen ($ string )) !== false ;
812 }
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Mastercard \Developer \Utils ;
3+
4+ use PHPUnit \Framework \TestCase ;
5+
6+ class StringUtilsTest extends TestCase {
7+
8+ public function testContains () {
9+ $ this ->assertTrue (StringUtils::contains ('Hello ' , '' ));
10+ $ this ->assertTrue (StringUtils::contains ('Hello ' , 'el ' ));
11+ $ this ->assertFalse (StringUtils::contains ('Hello ' , 'le ' ));
12+ $ this ->assertFalse (StringUtils::contains ('Hello ' , '-Hello- ' ));
13+ }
14+
15+ public function testStartWith () {
16+ $ this ->assertTrue (StringUtils::startsWith ('Hello ' , '' ));
17+ $ this ->assertTrue (StringUtils::startsWith ('Hello ' , 'He ' ));
18+ $ this ->assertFalse (StringUtils::startsWith ('Hello ' , 'le ' ));
19+ $ this ->assertFalse (StringUtils::startsWith ('Hello ' , '-Hello- ' ));
20+ }
21+
22+ public function testEndWith () {
23+ $ this ->assertTrue (StringUtils::endsWith ('Hello ' , '' ));
24+ $ this ->assertTrue (StringUtils::endsWith ('Hello ' , 'lo ' ));
25+ $ this ->assertFalse (StringUtils::endsWith ('Hello ' , 'le ' ));
26+ $ this ->assertFalse (StringUtils::endsWith ('Hello ' , '-Hello- ' ));
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments