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 evaluates against a specified closure.
14 class PHPUnit_Framework_Constraint_Callback extends PHPUnit_Framework_Constraint
19 * @param callable $callback
21 * @throws PHPUnit_Framework_Exception
23 public function __construct($callback)
25 if (!is_callable($callback)) {
26 throw PHPUnit_Util_InvalidArgumentHelper::factory(
32 parent::__construct();
34 $this->callback = $callback;
38 * Evaluates the constraint for parameter $value. Returns true if the
39 * constraint is met, false otherwise.
41 * @param mixed $other Value or object to evaluate.
45 protected function matches($other)
47 return call_user_func($this->callback, $other);
51 * Returns a string representation of the constraint.
55 public function toString()
57 return 'is accepted by specified callback';