lithium\test\Unit::assertNotContains()
Assert that $haystack
does not contain $needle
as a value.
$this->assertNotContains(4, array(1,2,3)); // succeeds
$this->assertNotContains('foo', array('foo', 'bar', 'baz')); // fails
Parameters
-
string
$needle
The needle you are looking for.
-
miexed
$haystack
Array or iterable object or a string.
-
string|boolean
$message
Returns
booleantrue
if the assertion succeeded, false
otherwise.
Source
public function assertNotContains($needle, $haystack, $message = '{:message}') {
if (is_string($haystack)) {
return $this->assert(strpos($haystack, $needle) === false, $message, array(
'expected' => $needle,
'result' => $haystack
));
}
foreach ($haystack as $key => $value) {
if ($value === $needle) {
return $this->assert(false, $message, array(
'expected' => $needle,
'result' => $haystack
));
}
}
return $this->assert(true, $message, array(
'expected' => $needle,
'result' => $haystack
));
}