lithium\test\Unit::assertContainsOnlyInstancesOf()

public method

Assert that $haystack contains only instances of given class.

$this->assertContainsOnlyInstancesOf('stdClass', array(new \stdClass)); // succeeds
$this->assertContainsOnlyInstancesOf('stdClass', array(new \lithium\test\Unit)); // fails

Parameters

  • string $class
  • array|object $haystack

    Array or iterable object.

  • string|boolean $message

Returns

boolean

true if the assertion succeeded, false otherwise.

Source

	public function assertContainsOnlyInstancesOf($class, $haystack, $message = '{:message}') {
		$result = array();
		foreach ($haystack as $key => &$value) {
			if (!is_a($value, $class)) {
				$result[$key] =& $value;
				break;
			}
		}
		return $this->assert(empty($result), $message, array(
			'expected' => $class,
			'result' => $result
		));
	}