lithium\test\Unit::assertContainsOnlyInstancesOf()

public method

Assert that $haystack contains only instances of given class.

$this->assertContainsOnlyInstancesOf('stdClass', [new \stdClass]); // succeeds
$this->assertContainsOnlyInstancesOf('stdClass', [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 = [];
		foreach ($haystack as $key => &$value) {
			if (!is_a($value, $class)) {
				$result[$key] =& $value;
				break;
			}
		}
		return $this->assert(empty($result), $message, [
			'expected' => $class,
			'result' => $result
		]);
	}