📜  PHPUnit | assertStringContainsStringIgnoringCase()函数

📅  最后修改于: 2022-05-13 01:57:40.671000             🧑  作者: Mango

PHPUnit | assertStringContainsStringIgnoringCase()函数

所述assertStringContainsStringIgnoringCase()函数是PHPUnit中内置函数并用于断言含有一个子而忽视子串的情况下的字符串。如果字符串包含子字符串作为忽略大小写敏感的子字符串,则此断言将返回 true,否则返回 false,如果为 true,则断言的测试用例通过,否则测试用例失败。

语法

assertStringContainsStringIgnoringCase(string $substring, string $string, string $message = ''])

参数:此函数接受三个参数,如上述语法所示。参数说明如下:

  1. $子串:该参数表示要串定字符串的字符串。
  2. $ 字符串 :这个参数是一个字符串,断言函数将检查它是否包含子字符串(忽略大小写敏感)。
  3. $message :此参数采用字符串值。当测试用例失败时,此字符串消息显示为错误消息。

下面的程序说明了 assertStringContainsStringIgnoringCase()函数:

程序一



assertStringContainsStringIgnoringCase($substring, $testString, "testString doesn't contains 'geeks' as substring") ;
    }
}
  
?>

输出:

PHPUnit 8.2.5 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 67 ms, Memory: 10.00 MB

There was 1 failure:

1) GeeksPhpunitTestCase::testNegativeTestcaseForAssertStringContainsStringIgnoringCase
testString doesn't contains 'geeks' as substring
Failed asserting that 'geekforgeek' contains "geeks".

/home/shivam/Documents/geeks/phpunit/abc.php:11

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

方案二

assertStringContainsStringIgnoringCase($substring, $testString, "testString doesn't contains 'geEk' as substring") ;
    }
}
  
?>

输出:

PHPUnit 8.2.5 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 67 ms, Memory: 10.00 MB

OK (1 test, 1 assertion)

注意:要使用 phpunit 运行测试用例,请按照此处的步骤操作。此外,phpunit 7 及更高版本支持 assertStringContainsStringIgnoringCase()。