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 * @since Class available since Release 3.1.0
14 class PHPUnit_Framework_Constraint_Attribute extends PHPUnit_Framework_Constraint_Composite
19 protected $attributeName;
22 * @param PHPUnit_Framework_Constraint $constraint
23 * @param string $attributeName
25 public function __construct(PHPUnit_Framework_Constraint $constraint, $attributeName)
27 parent::__construct($constraint);
29 $this->attributeName = $attributeName;
33 * Evaluates the constraint for parameter $other
35 * If $returnResult is set to false (the default), an exception is thrown
36 * in case of a failure. null is returned otherwise.
38 * If $returnResult is true, the result of the evaluation is returned as
39 * a boolean value instead: true in case of success, false in case of a
42 * @param mixed $other Value or object to evaluate.
43 * @param string $description Additional information about the test
44 * @param bool $returnResult Whether to return a result or throw an exception
48 * @throws PHPUnit_Framework_ExpectationFailedException
50 public function evaluate($other, $description = '', $returnResult = false)
52 return parent::evaluate(
53 PHPUnit_Framework_Assert::readAttribute(
63 * Returns a string representation of the constraint.
67 public function toString()
69 return 'attribute "' . $this->attributeName . '" ' .
70 $this->innerConstraint->toString();
74 * Returns the description of the failure
76 * The beginning of failure messages is "Failed asserting that" in most
77 * cases. This method should return the second part of that sentence.
79 * @param mixed $other Evaluated value or object.
83 protected function failureDescription($other)
85 return $this->toString();