5a0c458e51757864a0cec94d5c57368edd99d1b3
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / Attribute.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * @since Class available since Release 3.1.0
13  */
14 class PHPUnit_Framework_Constraint_Attribute extends PHPUnit_Framework_Constraint_Composite
15 {
16     /**
17      * @var string
18      */
19     protected $attributeName;
20
21     /**
22      * @param PHPUnit_Framework_Constraint $constraint
23      * @param string                       $attributeName
24      */
25     public function __construct(PHPUnit_Framework_Constraint $constraint, $attributeName)
26     {
27         parent::__construct($constraint);
28
29         $this->attributeName = $attributeName;
30     }
31
32     /**
33      * Evaluates the constraint for parameter $other
34      *
35      * If $returnResult is set to false (the default), an exception is thrown
36      * in case of a failure. null is returned otherwise.
37      *
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
40      * failure.
41      *
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
45      *
46      * @return mixed
47      *
48      * @throws PHPUnit_Framework_ExpectationFailedException
49      */
50     public function evaluate($other, $description = '', $returnResult = false)
51     {
52         return parent::evaluate(
53             PHPUnit_Framework_Assert::readAttribute(
54                 $other,
55                 $this->attributeName
56             ),
57             $description,
58             $returnResult
59         );
60     }
61
62     /**
63      * Returns a string representation of the constraint.
64      *
65      * @return string
66      */
67     public function toString()
68     {
69         return 'attribute "' . $this->attributeName . '" ' .
70                $this->innerConstraint->toString();
71     }
72
73     /**
74      * Returns the description of the failure
75      *
76      * The beginning of failure messages is "Failed asserting that" in most
77      * cases. This method should return the second part of that sentence.
78      *
79      * @param mixed $other Evaluated value or object.
80      *
81      * @return string
82      */
83     protected function failureDescription($other)
84     {
85         return $this->toString();
86     }
87 }