lithium\test\Unit::assertContains()

public method

Assert that $haystack contains $needle as a value.

$this->assertContains('foo', ['foo', 'bar', 'baz']); // succeeds
$this->assertContains(4, [1,2,3]); // fails

Parameters

  • string $needle

    The needle you are looking for.

  • mixed $haystack

    An array, iterable object, or string.

  • string|boolean $message

Returns

boolean

true if the assertion succeeded, false otherwise.

Source

	public function assertContains($needle, $haystack, $message = '{:message}') {
		if (is_string($haystack)) {
			return $this->assert(strpos($haystack, $needle) !== false, $message, [
				'expected' => $needle,
				'result' => $haystack
			]);
		}
		foreach ($haystack as $key => $value) {
			if ($value === $needle) {
				return $this->assert(true, $message, [
					'expected' => $needle,
					'result' => $haystack
				]);
			}
		}
		return $this->assert(false, $message, [
			'expected' => $needle,
			'result' => $haystack
		]);
	}