Skip to content

Commit

Permalink
feat: add Str::doesntContain() method and supporting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sts-ryan-holton committed Oct 4, 2024
1 parent 2747a5f commit 98f2c41
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ public static function containsAll($haystack, $needles, $ignoreCase = false)
return true;
}

/**
* Determine if a given string doesn't contain a given substring.
*
* @param string $haystack
* @param string|iterable<string> $needles
* @param bool $ignoreCase
* @return bool
*/
public static function doesntContain($haystack, $needles, $ignoreCase = false)
{
return ! static::contains($haystack, $needles, $ignoreCase);
}

/**
* Convert the case of a string.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ public function testStrContainsAll($haystack, $needles, $expected, $ignoreCase =
$this->assertEquals($expected, Str::containsAll($haystack, $needles, $ignoreCase));
}

#[DataProvider('strDoesntContainProvider')]
public function testStrDoesntContain($haystack, $needles, $expected, $ignoreCase = false)
{
$this->assertEquals($expected, Str::doesntContain($haystack, $needles, $ignoreCase));
}

public function testConvertCase()
{
// Upper Case Conversion
Expand Down Expand Up @@ -1285,6 +1291,13 @@ public static function strContainsAllProvider()
];
}

public static function strDoesntContainProvider()
{
return [
['Tar', 'ylo', true, true],
];
}

public function testMarkdown()
{
$this->assertSame("<p><em>hello world</em></p>\n", Str::markdown('*hello world*'));
Expand Down

0 comments on commit 98f2c41

Please sign in to comment.