📜  PHPUnit assertEqualsIgnoringCase()函数

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

PHPUnit assertEqualsIgnoringCase()函数

assertEqualsIgnoringCase()函数是 PHPUnit 中的内置函数,用于检查预期字符串是否等于实际字符串,忽略预期字符串的字符串大小写。如果实际字符串等于忽略大小写敏感的预期字符串,则此断言将返回 true,否则返回 false。如果为真,则断言的测试用例通过,否则测试用例失败。

句法:

assertEqualsIgnoringCase(mixed $expected, 
      mixed $actual[, string $message = '']

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

  • $expected:这个参数是一个字符串,代表预期的数据。
  • $ actual:这个参数是一个字符串,代表实际的数据。
  • $message:此参数采用字符串值。当测试用例失败时,此字符串消息显示为错误消息。

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

示例 1:

PHP
assertEqualsIgnoringCase(
          $actual,
          $expected, 
          "expected is not equal to actual ignoring case") ; 
    } 
} 
    
?>


PHP
assertEqualsIgnoringCase(
          $actual,
          $expected, 
          "expected is not equal to actual ignoring case") ; 
    } 
} 
    
?>


输出:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

F                                                         1 / 1 (100%)

Time: 88 ms, Memory: 10.00 MB

There was 1 failure:

1) GeeksPhpunitTestCase::testNegativeTestcaseForAssertequalIgnoringCase
expected is not equal to actual ignoring case
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'geEks'
+'Geek'

/home/lovely/Documents/php/test.php:17

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


示例 2:

PHP

assertEqualsIgnoringCase(
          $actual,
          $expected, 
          "expected is not equal to actual ignoring case") ; 
    } 
} 
    
?> 

输出:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                             1 / 1 (100%)

Time: 91 ms, Memory: 10.00 MB

OK (1 test, 1 assertion)

参考: https://phpunit.readthedocs.io/en/9.2/assertions.html#assertequalsignoringcase