PHPUnit | assertStringContainsString() function Last Updated : 19 Jul, 2019 Comments Improve Suggest changes Like Article Like Report The assertStringContainsString() function is a builtin function in PHPUnit and is used to assert a string containing a substring. This assertion will return true in the case if the string contains the substring as a substring else return false and in case of true the asserted test case got passed else test case got failed. Syntax: assertStringContainsString(string $substring, string $string, string $message = '']) Parameters: This function accepts three parameters as shown in the above syntax. The parameters are described below: $substring: This parameter represents the string to be substring of given string. $string: This parameter is string for which the assert function will check whether it contains substring or not. $message: This parameter takes string value. When the testcase got failed this string message got displayed as error message. Below programs illustrate the assertStringContainsString() function: Program 1: php <?php use PHPUnit\Framework\TestCase; class GeeksPhpunitTestCase extends TestCase { public function testNegativeTestcaseForAssertStringContainsString() { $testString = "geekforgeek"; $substring = "geeks"; // assert function to test whether 'geeks' is a substring of testString $this->assertStringContainsString($substring, $testString, "testString doesn't contains 'geeks' as substring") ; } } ?> Output: PHPUnit 8.2.5 by Sebastian Bergmann and contributors. F 1 / 1 (100%) Time: 65 ms, Memory: 10.00 MB There was 1 failure: 1) GeeksPhpunitTestCase::testNegativeTestcaseForAssertStringContainsString testString doesn't contains 'geeks' as substring Failed asserting that 'geekforgeek' contains "geeks". /home/shivam/Documents/geeks/phpunit/abc.php:11 FAILURES! Tests: 1, Assertions: 1, Failures: 1. Program 2: php <?php use PHPUnit\Framework\TestCase; class GeeksPhpunitTestCase extends TestCase { public function testPositiveTestcaseForAssertStringContainsString() { $testString = "geekforgeek"; $substring = "geek"; // assert function to test whether 'geeks' is a substring of testString $this->assertStringContainsString($substring, $testString, "testString doesn't contains 'geeks' as substring") ; } } ?> Output: PHPUnit 8.2.5 by Sebastian Bergmann and contributors. . 1 / 1 (100%) Time: 67 ms, Memory: 10.00 MB OK (1 test, 1 assertion) Note : To run testcases with phpunit follow steps from here. Also, assertStringContainsString() is supported by phpunit 7 and above. Comment More infoAdvertise with us Next Article PHPUnit | assertStringContainsString() function S Shivam.Pradhan Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-PHPUnit Similar Reads PHPUnit | assertStringNotContainsString() Function The assertStringNotContainsString() function is a builtin function in PHPUnit and is used to assert a string doesn't containing a substring. This assertion will return true in the case if the string doesn't contain the substring as a substring else returns false and in case of true the asserted test 2 min read PHPUnit | assertStringContainsStringIgnoringCase() function The assertStringContainsStringIgnoringCase() function is a builtin function in PHPUnit and is used to assert a string containing a substring but ignoring the case of substring. This assertion will return true in the case if the string contains the substring as a substring ignoring case-sensitivity, 2 min read PHPUnit assertIsNotString() Function The assertIsNotString() function is a builtin function in PHPUnit and is used to assert whether the actually obtained value is Not a string value. This assertion will return true in the case if the actual value is Not a string else returns false. In case of true the asserted test case got passed els 2 min read PHPUnit | assertStringNotContainsStringIgnoringCase() Function The assertStringNotContainsStringIgnoringCase() function is a builtin function in PHPUnit and is used to assert that a string doesn't contains a substring ignoring the case of substring. This assertion will return true in case if the string doesn't contain a substring as a substring ignoring case-se 2 min read PHPUnit assertIsString() Function The assertIsstring() function is a builtin function in PHPUnit and is used to assert whether the actually obtained value is a string value or not. This assertion will return true in the case if the actual value is string else returns false. In case of true the asserted test case got passed else test 2 min read PHPUnit assertXmlStringNotEqualsXmlString() Function The assertXmlStringNotEqualsXmlString() function is a builtin function in PHPUnit and is used to assert whether the actual XML string 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 string else returns fal 2 min read PHPUnit | assertContains() function The assertContains() function is a builtin function in PHPUnit and is used to assert an array having a value. This assertion will return true in the case if the array contains the provided value else return false and in case of true the asserted test case got passed else test case got failed. Syntax 2 min read PHPUnit | assertNotContains() function The assertNotContains() function is a builtin function in PHPUnit and is used to assert an array not having a value. This assertion will return true in the case if the array doesn't contain the provided value else return false and in case of true the asserted test case got passed else test case got 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 PHPUnit | assertContainsOnly() Function The assertContainsOnly() function is a builtin function in PHPUnit and is used to assert an array to contain all its values as the given data type. This assertion will return true in the case if the array contains values of only given data type else return false and in case of true the asserted test 2 min read Like