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.
21
* @subpackage Framework_Constraint
22
* @author Sebastian Bergmann <sebastian@phpunit.de>
23
* @author Bernhard Schussek <bschussek@2bepublished.at>
24
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
25
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
26
* @link http://www.phpunit.de/
27
* @since Class available since Release 3.0.0
29
class PHPUnit_Framework_Constraint_StringContains extends PHPUnit_Framework_Constraint
39
protected $ignoreCase;
42
* @param string $string
43
* @param boolean $ignoreCase
45
public function __construct($string, $ignoreCase = false)
47
parent::__construct();
49
$this->string = $string;
50
$this->ignoreCase = $ignoreCase;
54
* Evaluates the constraint for parameter $other. Returns true if the
55
* constraint is met, false otherwise.
57
* @param mixed $other Value or object to evaluate.
60
protected function matches($other)
62
if ($this->ignoreCase) {
63
return stripos($other, $this->string) !== false;
65
return strpos($other, $this->string) !== false;
70
* Returns a string representation of the constraint.
74
public function toString()
76
if ($this->ignoreCase) {
77
$string = strtolower($this->string);
79
$string = $this->string;