A função assertNotContains() é uma função embutida no PHPUnit e é usada para declarar um array sem valor. Esta afirmação retornará true no caso se o array não contiver o valor fornecido senão retornará false e em caso de true o caso de teste declarado foi aprovado, caso contrário, o caso de teste falhou.

Sintaxe :

assertNotContains(mixed $value, array $array, string $message = ''])

Parâmetros : esta função aceita três parâmetros, conforme mostrado na sintaxe acima. Os parâmetros são descritos abaixo:

  1. $value : este parâmetro representa o valor que não deve estar contido no array.
  2. $array : este parâmetro é um array para o qual a função assert irá verificar se contém valor ou não.
  3. $mensagem : Este parâmetro leva um valor de string. Quando o caso de teste falhou, essa mensagem de string foi exibida como uma mensagem de erro.

Os programas abaixo ilustram a função assertNotContains():

Programa 1 :

<?php
use PHPUnit\Framework\TestCase;
  
class GeeksPhpunitTestCase extends TestCase
{
    public function testNegativeTestcaseForAssertNotContains()
    {
        $testArray = array("a"=>"value ba", "b" =>"value b");
        $value = "value ba"; 
        // assert function to test whether 'value' is a value of array
        $this->assertNotContains($value, $testArray, "testArray contains value as value") ;
    }
}
  
?>

Saída:

PHPUnit 6.5.5 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 21 ms, Memory: 4.00MB

There was 1 failure:

1) GeeksPhpunitTestCase::testNegativeTestcaseForAssertNotContains
testArray contains value as value
Failed asserting that an array does not contain 'value ba'.

/home/shivam/Documents/geeks/phpunit/abc.php:11

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

Programa 2 :

<?php
use PHPUnit\Framework\TestCase;
  
class GeeksPhpunitTestCase extends TestCase
{
    public function testPositiveTestcaseForAssertNotContains()
    {
        $testArray = array("a"=>"value ba", "b" =>"value b");
        $value = "value b"; 
        // assert function to test whether 'value' is a value of array
        $this->assertNotContains($value, $testArray, "testArray contains value as value") ;
    }
}
  
?>

Saída:

PHPUnit 6.5.5 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 21 ms, Memory: 4.00MB

OK (1 test, 1 assertion)

Nota: Para rodar casos de teste com phpunit, siga os passos a partir daqui .