Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHPUnit assertStringNotEqualsFile() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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:

  • $expectedfile: This parameter is of any type which represents the expected file.
  • $actualstring: This parameter is of any type which represents the actual string content.
  • $message: This parameter takes a string value. When the test case got failed this string message got displayed as an error message.

Below examples illustrate the assertStringNotEqualsFile() function in PHPUnit:

Example 1:

PHP




<?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




<?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)

My Personal Notes arrow_drop_up
Last Updated : 07 Aug, 2020
Like Article
Save Article
Similar Reads
Related Tutorials