+

PHPUnit | assertContains () function

Syntax :
assertContains (mixed $value, array $array, string $message = ``]) 
Parameters : This function takes three parameters as shown in the above syntax. The parameters are described below:
  • $value : This parameter represents the value that will be contained in the array.
  • $array : This parameter is an array for which the assert function will check if it contains a value or not.
  • $message : This parameter accepts a string value. When the test case failed, this string message was displayed as an error message.
  • The following programs illustrate the assertContains() function: Program 1 : use PHPUnitFrameworkTestCase; class GeeksPhpunitTestCase extends TestCase {< / code> public function testNegativeTestcaseForAssertContains() { $testArray = array ( " a " = > "value b" , "b" = > " value b " ); $value = "value ba" ; // assert function to check if ` value ` array value $this -> assertContains ( $value , $testArray , "testArray doesn`t contains value as value" ); } }  
    ?>
    Output:
     Program 2 :


    use PHPUnitFrameworkTestCase;   class GeeksPhpunitTestCase extends TestCase { public function testPositiveTestcaseForAssertContains() { $testArray = array ( "a" = > "value ba" , "b" = > "value b" ); $value = " value ba " ; // assert function to test whether `value` is a value of array $this -> assertContains ( $value , $testArray , "testArray doesn`t contains value as value" ); } }  ?> Output:
    PHPUnit 6.5.5 by Sebastian Bergmann and contributors. ... 1/1 (100%) Time: 21 ms, Memory: 4.00MB OK (1 test, 1 assertion) 
    Note: To run testcases with PHPUnit steps follows from here .
    Get Solution for free from DataCamp guru