From 3f5141a87c04c05930b2cd9e29c539ecbd20104b Mon Sep 17 00:00:00 2001 From: Patrick Brueckner Date: Tue, 29 Sep 2015 14:05:52 +0200 Subject: [PATCH 1/2] make sure needle is converted to string before calling strpos --- src/Methods/StringsMethods.php | 2 +- tests/Types/StringTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Methods/StringsMethods.php b/src/Methods/StringsMethods.php index 5d5ef6d..709baa1 100644 --- a/src/Methods/StringsMethods.php +++ b/src/Methods/StringsMethods.php @@ -180,7 +180,7 @@ public static function isUrl($string) public static function startsWith($haystack, $needles) { foreach ((array) $needles as $needle) { - if ($needle !== '' && strpos($haystack, $needle) === 0) { + if ($needle !== '' && strpos($haystack, (string)$needle) === 0) { return true; } } diff --git a/tests/Types/StringTest.php b/tests/Types/StringTest.php index d4d36ec..98908a1 100644 --- a/tests/Types/StringTest.php +++ b/tests/Types/StringTest.php @@ -136,6 +136,13 @@ public function testCanAssertAStringStartsWith() $this->assertFalse(Strings::startsWith('barfoo', 'foo')); } + public function testCanAssertAStringStartsWithInteger() + { + $this->assertTrue(Strings::startsWith('123456.something', 123456)); + $this->assertTrue(Strings::startsWith('123456.something', [123456])); + $this->assertFalse(Strings::startsWith('654321.something', 123456)); + } + public function testCanAssertAStringEndsWith() { $this->assertTrue(Strings::endsWith('foobar', 'bar')); From 73e3a5f6bc997f67bfe01896dc52c753b020512a Mon Sep 17 00:00:00 2001 From: Patrick Brueckner Date: Tue, 29 Sep 2015 16:03:32 +0200 Subject: [PATCH 2/2] add space to make php-cs-fixer happy --- src/Methods/StringsMethods.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Methods/StringsMethods.php b/src/Methods/StringsMethods.php index 709baa1..a851a83 100644 --- a/src/Methods/StringsMethods.php +++ b/src/Methods/StringsMethods.php @@ -180,7 +180,7 @@ public static function isUrl($string) public static function startsWith($haystack, $needles) { foreach ((array) $needles as $needle) { - if ($needle !== '' && strpos($haystack, (string)$needle) === 0) { + if ($needle !== '' && strpos($haystack, (string) $needle) === 0) { return true; } }