Thursday, October 9, 2025
HomeLanguagesPHPUnit assertFileNotEquals() Function

PHPUnit assertFileNotEquals() Function

The assertFileNotEquals() function is a builtin function in PHPUnit and is used to assert whether the actual file content is different from expected file content or not. This assertion will return true in the case if the expected file content is not-equals to actual file content else returns false. In case of true the asserted test case got passed else test case got failed.

Syntax:

assertFileNotEquals(string $expected, string $actual[, string $message = ''])

Parameters: This function accepts three parameters as mentioned above and described below:

  • $expected: This parameter is of string type that represents the expected file path.
  • $actual:This parameter is of string type that represents the actual file path.
  • $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 assertFileNotEquals() function in PHPUnit:

Example 1:

PHP




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
{ 
    public function testNegativeTestcaseForassertFileNotEquals() 
    { 
        $expected = "/home/bittu/Documents"; 
        $actual = "/home/bittu/Documents"; 
    
        // Assert file not equal function to test whether expected 
        // file content is different to actual file content or not 
        $this->assertFileNotEquals(
            $expected, 
            $actual, 
            "actual file content is equals to expected file content"
        ); 
    } 
} 
    
?>


Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

F                                             1 / 1 (100%)

Time: 116 ms, Memory: 10.00 MB

There was 1 failure:

1) GeeksPhpunitTestCase::testNegativeTestcaseForassertFileNotEquals
actual file content is equals to expected file content
Failed asserting that file "/home/bittu/Documents" exists.

/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 testPositiveTestcaseForassertFileNotEquals() 
    { 
        $expected = "/home/bittu/Documents/php/demo.txt"; 
        $actual = "/home/bittu/Documents/php/file1.php"; 
  
        // Assert file not equal function to test whether expected 
        // file content is different from actual file content or not 
        $this->assertFileNotEquals(
            $expected, 
            $actual, 
            "actual file content is equals to expected file content"
        ); 
    } 
} 
    
?>


Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                             1 / 1 (100%)

Time: 91 ms, Memory: 10.00 MB

OK (1 test, 3 assertions)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32344 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6714 POSTS0 COMMENTS
Nicole Veronica
11877 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6834 POSTS0 COMMENTS
Ted Musemwa
7094 POSTS0 COMMENTS
Thapelo Manthata
6789 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS