Open In App

PHPUnit assertStringNotEqualsFile() Function

The assertStringNotEqualsFile() function is a builtin function in PHPUnit and is used to assert whether the actual string content Doesn’t equal to expected file. This assertion will return true in the case if the expected file content is the not same as the actual string content else returns false. In case of true the asserted test case got passed else test case got failed.

Syntax:



assertStringNotEqualsFile(string $expectedFile, 
string $actualString[, string $message = ''])

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

Below examples illustrate the assertStringNotEqualsFile() function in PHPUnit:



Example 1:




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
    public function testNegativeTestcaseForassertStringNotEqualsFile()
    
        $expectedfile = "/home/lovely/Documents/php/abc";
        $actualstring = "File has not geeksforgeeks"
    
        // Assert function to test whether expected file 
        // content is equal to actual string content
        $this->assertStringNotEqualsFile(
            $expectedfile,
            $actualstring
            "actual string content is equals to
             expected file content"
        ); 
    
    
?>

Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

F                                                  1 / 1 (100%)

Time: 86 ms, Memory: 10.00 MB

There was 1 failure:

1) GeeksPhpunitTestCase::testPositiveTestcaseForassertStringNotEqualsFile
actual string content is equals to expected file content
Failed asserting that 'File does not have not geeksforgeeks' 
is not equal to 'File does not have not geeksforgeeks'.

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

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

Example 2:




<?php 
use PHPUnit\Framework\TestCase; 
    
class GeeksPhpunitTestCase extends TestCase 
    public function testPositiveTestcaseForassertStringNotEqualsFile()
    
        $expectedfile = "/home/lovely/Documents/php/abc";
        $actualstring = "File has geeksforgeeks"
    
        // Assert function to test whether expected file 
        // content is equal to actual string content
        $this->assertStringNotEqualsFile(
            $expectedfile,
            $actualstring
            "actual string content is equals to 
             expected file content"
        ); 
    
}

Output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.

.                                                  1 / 1 (100%)

Time: 88 ms, Memory: 10.00 MB

OK (1 test, 2 assertions)

Article Tags :