PHPUnit assertStringEqualsFile() Function Last Updated : 07 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The assertStringEqualsFile() function is a builtin function in PHPUnit and is used to assert whether the actual string content obtained is equaled to the expected file or not. This assertion will return true in the case if the expected file content is the 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: assertStringEqualsFile(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 assertStringEqualsFile() function in PHPUnit: Example 1: PHP <?php use PHPUnit\Framework\TestCase; class GeeksPhpunitTestCase extends TestCase { public function testNegativeTestcaseForassertStringEqualsFile() { $expectedfile = "/home/lovely/Documents/php/abc"; $actualstring = "File has geeksforgeeks"; // Assert function to test whether // expected file content is equal to // actual string content or not $this->assertStringEqualsFile( $expectedfile, $actualstring, "actual string content is equals to expected file content or not" ); } } ?> Output: PHPUnit 8.5.8 by Sebastian Bergmann and contributors. F 1 / 1 (100%) Time: 89 ms, Memory: 10.00 MB There was 1 failure: 1) GeeksPhpunitTestCase::testNegativeTestcaseForassertStringEqualsFile actual string content is not equals to expected file content Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'File has not geeksforgeeks' +'File has 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 testPositiveTestcaseForassertStringEqualsFile() { $expectedfile = "/home/lovely/Documents/php/abc"; $actualstring = "File has geeksforgeeks"; // Assert function to test whether // expected file content is equal // to actual string content or not $this->assertStringEqualsFile( $expectedfile, $actualstring, "actual string content is equals to expected file content or not" ); } } ?> Output: PHPUnit 8.5.8 by Sebastian Bergmann and contributors. . 1 / 1 (100%) Time: 87 ms, Memory: 10.00 MB OK (1 test, 2 assertions) Reference: https://phpunit.readthedocs.io/en/9.2/assertions.html#assertstringequalsfile Comment More infoAdvertise with us Next Article PHPUnit assertStringNotEqualsFile() Function S shubham_singh Follow Improve Article Tags : Web Technologies PHP PHP-PHPUnit Similar Reads 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. 2 min read PHPUnit assertXmlStringEqualsXmlFile() Function The assertXmlStringEqualsXmlFile() function is a builtin function in PHPUnit and is used to assert whether the actual XML file Content is equals to expected XML string or not. This assertion will return true in the case if the expected XML string is the same as the actual XML file content else retur 2 min read PHPUnit assertXmlStringNotEqualsXmlFile() Function The assertXmlStringNotEqualsXmlFile() function is a builtin function in PHPUnit and is used to assert whether the actual XML file Content is not equals to expected XML string. This assertion will return true in the case if the expected XML string is not the same as the actual XML file content else r 2 min read PHPunit | assertNotEquals() Function The assertNotEquals() function is a builtin function in PHPUnit and is used to assert the actual obtained value to be not-equals to expected value. This assertion will return true in the case if the expected value is not-equals to actual value else returns false. In case of true the asserted test ca 2 min read PHPunit | assertEquals() Function The assertEquals() function is a builtin function in PHPUnit and is used to assert whether the actual obtained value is equals to expected value or not. This assertion will return true in the case if the expected value is the same as the actual value else returns false. In case of true the asserted 2 min read PHPUnit assertXmlStringEqualsXmlString() Function The assertXmlStringEqualsXmlString() function is a builtin function in PHPUnit and is used to assert whether the actual XML string equals to expected XML string or not. This assertion will return true in the case if the expected XML string is the same as the actual XML string else returns false. In 2 min read Like