Friday, June 12, 2026
HomeLanguagesPHPUnit assertEqualsIgnoringCase() Function

PHPUnit assertEqualsIgnoringCase() Function

The assertEqualsIgnoringCase() function is a builtin function in PHPUnit and is used to check whether the expected string is equal to actual string ignoring the string-case of expected string. This assertion will return true in the case if the actual string is equal to expected string  ignoring case-sensitivity, else return false. In case of true the asserted test case got passed else test case got failed.

Syntax:

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

Parameters: This function accepts three parameters as shown in the above syntax. The parameters are described below:

  • $expected: This parameter is a string that represents the expected data.
  • $actual: This parameter is a string that represents the actual data.
  • $message: This parameter takes a string value. When the test case got failed this string message got displayed as an error message.

Below programs illustrate the assertEqualsIgnoringCase() function:

Example 1:

PHP




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
    public function testNegativeTestcaseForAssertequalIgnoringCase() 
    
        $expected = "Geek"
        $actual= "geEks";  
        // assert function to test whether expected string
        // is equal or not to actual ignoring case
        $this->assertEqualsIgnoringCase(
          $actual,
          $expected
          "expected is not equal to actual ignoring case") ; 
    
    
?> 


Output:

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.


Example 2:

PHP




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
    public function testPositiveTestcaseForAssertequalIgnoringCase() 
    
        $expected = "Geeks"
        $actual= "geEks";  
        // assert function to test whether expected
        // is equal or not to actual ignoring case
        $this->assertEqualsIgnoringCase(
          $actual,
          $expected
          "expected is not equal to actual ignoring case") ; 
    
    
?> 


Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                             1 / 1 (100%)

Time: 91 ms, Memory: 10.00 MB

OK (1 test, 1 assertion)

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

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS