3 * This file is part of PHPUnit.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Constraint that asserts that the string it is evaluated for contains
15 * Uses strpos() to find the position of the string in the input, if not found
16 * the evaluation fails.
18 * The sub-string is passed in the constructor.
20 * @since Class available since Release 3.0.0
22 class PHPUnit_Framework_Constraint_StringContains extends PHPUnit_Framework_Constraint
32 protected $ignoreCase;
35 * @param string $string
36 * @param bool $ignoreCase
38 public function __construct($string, $ignoreCase = false)
40 parent::__construct();
42 $this->string = $string;
43 $this->ignoreCase = $ignoreCase;
47 * Evaluates the constraint for parameter $other. Returns true if the
48 * constraint is met, false otherwise.
50 * @param mixed $other Value or object to evaluate.
54 protected function matches($other)
56 if ($this->ignoreCase) {
57 return stripos($other, $this->string) !== false;
59 return strpos($other, $this->string) !== false;
64 * Returns a string representation of the constraint.
68 public function toString()
70 if ($this->ignoreCase) {
71 $string = strtolower($this->string);
73 $string = $this->string;