Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit a138bad

Browse files
committed
Updated StringUtils class and tests
1 parent a525296 commit a138bad

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Developer/Utils/StringUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
class 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
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)