lithium\test\Unit::assertContainsOnly()
Assert that $haystack
does only contain item of given type.
$this->assertContainsOnly('integer', [1,2,3]); // succeeds
$this->assertContainsOnly('integer', ['foo', 'bar', 'baz']); // fails
Parameters
-
string
$type
-
array|object
$haystack
Array or iterable object.
-
string|boolean
$message
Returns
booleantrue
if the assertion succeeded, false
otherwise.
Source
public function assertContainsOnly($type, $haystack, $message = '{:message}') {
$method = static::$_internalTypes[$type];
foreach ($haystack as $key => $value) {
if (!$method($value)) {
return $this->assert(false, $message, [
'expected' => $type,
'result' => $haystack
]);
}
}
return $this->assert(true, $message, [
'expected' => $type,
'result' => $haystack
]);
}