lithium\test\Unit::assertContainsOnly()

public method

Assert that $haystack does only contain item of given type.

$this->assertContainsOnly('integer', array(1,2,3)); // succeeds
$this->assertContainsOnly('integer', array('foo', 'bar', 'baz')); // fails

Parameters

  • string $type
  • array|object $haystack

    Array or iterable object.

  • string|boolean $message

Returns

boolean

true if the assertion succeeded, false otherwise.

Source

	public function assertContainsOnly($type, $haystack, $message = '{:message}') {
		$method = self::$_internalTypes[$type];
		foreach ($haystack as $key => $value) {
			if (!$method($value)) {
				return $this->assert(false, $message, array(
					'expected' => $type,
					'result' => $haystack
				));
			}
		}
		return $this->assert(true, $message, array(
			'expected' => $type,
			'result' => $haystack
		));
	}