Skip to content

Commit 5106bd5

Browse files
feat: add Str::doesntContain() method and supporting tests (#53035)
1 parent 2747a5f commit 5106bd5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Illuminate/Support/Str.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,19 @@ public static function containsAll($haystack, $needles, $ignoreCase = false)
328328
return true;
329329
}
330330

331+
/**
332+
* Determine if a given string doesn't contain a given substring.
333+
*
334+
* @param string $haystack
335+
* @param string|iterable<string> $needles
336+
* @param bool $ignoreCase
337+
* @return bool
338+
*/
339+
public static function doesntContain($haystack, $needles, $ignoreCase = false)
340+
{
341+
return ! static::contains($haystack, $needles, $ignoreCase);
342+
}
343+
331344
/**
332345
* Convert the case of a string.
333346
*

tests/Support/SupportStrTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ public function testStrContainsAll($haystack, $needles, $expected, $ignoreCase =
377377
$this->assertEquals($expected, Str::containsAll($haystack, $needles, $ignoreCase));
378378
}
379379

380+
#[DataProvider('strDoesntContainProvider')]
381+
public function testStrDoesntContain($haystack, $needles, $expected, $ignoreCase = false)
382+
{
383+
$this->assertEquals($expected, Str::doesntContain($haystack, $needles, $ignoreCase));
384+
}
385+
380386
public function testConvertCase()
381387
{
382388
// Upper Case Conversion
@@ -1285,6 +1291,13 @@ public static function strContainsAllProvider()
12851291
];
12861292
}
12871293

1294+
public static function strDoesntContainProvider()
1295+
{
1296+
return [
1297+
['Tar', 'ylo', true, true],
1298+
];
1299+
}
1300+
12881301
public function testMarkdown()
12891302
{
12901303
$this->assertSame("<p><em>hello world</em></p>\n", Str::markdown('*hello world*'));

0 commit comments

Comments
 (0)