Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / phpunit / phpunit / src / Framework / Constraint / ClassHasAttribute.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  * Constraint that asserts that the class it is evaluated for has a given
13  * attribute.
14  *
15  * The attribute name is passed in the constructor.
16  *
17  * @since Class available since Release 3.1.0
18  */
19 class PHPUnit_Framework_Constraint_ClassHasAttribute extends PHPUnit_Framework_Constraint
20 {
21     /**
22      * @var string
23      */
24     protected $attributeName;
25
26     /**
27      * @param string $attributeName
28      */
29     public function __construct($attributeName)
30     {
31         parent::__construct();
32         $this->attributeName = $attributeName;
33     }
34
35     /**
36      * Evaluates the constraint for parameter $other. Returns true if the
37      * constraint is met, false otherwise.
38      *
39      * @param mixed $other Value or object to evaluate.
40      *
41      * @return bool
42      */
43     protected function matches($other)
44     {
45         $class = new ReflectionClass($other);
46
47         return $class->hasProperty($this->attributeName);
48     }
49
50     /**
51      * Returns a string representation of the constraint.
52      *
53      * @return string
54      */
55     public function toString()
56     {
57         return sprintf(
58             'has attribute "%s"',
59             $this->attributeName
60         );
61     }
62
63     /**
64      * Returns the description of the failure
65      *
66      * The beginning of failure messages is "Failed asserting that" in most
67      * cases. This method should return the second part of that sentence.
68      *
69      * @param mixed $other Evaluated value or object.
70      *
71      * @return string
72      */
73     protected function failureDescription($other)
74     {
75         return sprintf(
76             '%sclass "%s" %s',
77             is_object($other) ? 'object of ' : '',
78             is_object($other) ? get_class($other) : $other,
79             $this->toString()
80         );
81     }
82 }