@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsInfinite extends Constraint |
16 | 16 | { |
17 | - /** |
|
18 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
19 | - * constraint is met, false otherwise. |
|
20 | - * |
|
21 | - * @param mixed $other Value or object to evaluate. |
|
22 | - * |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - protected function matches($other) |
|
26 | - { |
|
27 | - return \is_infinite($other); |
|
28 | - } |
|
17 | + /** |
|
18 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
19 | + * constraint is met, false otherwise. |
|
20 | + * |
|
21 | + * @param mixed $other Value or object to evaluate. |
|
22 | + * |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + protected function matches($other) |
|
26 | + { |
|
27 | + return \is_infinite($other); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Returns a string representation of the constraint. |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function toString() |
|
36 | - { |
|
37 | - return 'is infinite'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is infinite'; |
|
38 | + } |
|
39 | 39 | } |
@@ -19,37 +19,37 @@ |
||
19 | 19 | */ |
20 | 20 | class ClassHasStaticAttribute extends ClassHasAttribute |
21 | 21 | { |
22 | - /** |
|
23 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
24 | - * constraint is met, false otherwise. |
|
25 | - * |
|
26 | - * @param mixed $other Value or object to evaluate. |
|
27 | - * |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - protected function matches($other) |
|
31 | - { |
|
32 | - $class = new ReflectionClass($other); |
|
22 | + /** |
|
23 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
24 | + * constraint is met, false otherwise. |
|
25 | + * |
|
26 | + * @param mixed $other Value or object to evaluate. |
|
27 | + * |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + protected function matches($other) |
|
31 | + { |
|
32 | + $class = new ReflectionClass($other); |
|
33 | 33 | |
34 | - if ($class->hasProperty($this->attributeName)) { |
|
35 | - $attribute = $class->getProperty($this->attributeName); |
|
34 | + if ($class->hasProperty($this->attributeName)) { |
|
35 | + $attribute = $class->getProperty($this->attributeName); |
|
36 | 36 | |
37 | - return $attribute->isStatic(); |
|
38 | - } |
|
37 | + return $attribute->isStatic(); |
|
38 | + } |
|
39 | 39 | |
40 | - return false; |
|
41 | - } |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Returns a string representation of the constraint. |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function toString() |
|
49 | - { |
|
50 | - return \sprintf( |
|
51 | - 'has static attribute "%s"', |
|
52 | - $this->attributeName |
|
53 | - ); |
|
54 | - } |
|
43 | + /** |
|
44 | + * Returns a string representation of the constraint. |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function toString() |
|
49 | + { |
|
50 | + return \sprintf( |
|
51 | + 'has static attribute "%s"', |
|
52 | + $this->attributeName |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | } |
@@ -15,40 +15,40 @@ |
||
15 | 15 | */ |
16 | 16 | class StringEndsWith extends Constraint |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $suffix; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $suffix; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $suffix |
|
25 | - */ |
|
26 | - public function __construct($suffix) |
|
27 | - { |
|
28 | - parent::__construct(); |
|
29 | - $this->suffix = $suffix; |
|
30 | - } |
|
23 | + /** |
|
24 | + * @param string $suffix |
|
25 | + */ |
|
26 | + public function __construct($suffix) |
|
27 | + { |
|
28 | + parent::__construct(); |
|
29 | + $this->suffix = $suffix; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
34 | - * constraint is met, false otherwise. |
|
35 | - * |
|
36 | - * @param mixed $other Value or object to evaluate. |
|
37 | - * |
|
38 | - * @return bool |
|
39 | - */ |
|
40 | - protected function matches($other) |
|
41 | - { |
|
42 | - return \substr($other, 0 - \strlen($this->suffix)) == $this->suffix; |
|
43 | - } |
|
32 | + /** |
|
33 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
34 | + * constraint is met, false otherwise. |
|
35 | + * |
|
36 | + * @param mixed $other Value or object to evaluate. |
|
37 | + * |
|
38 | + * @return bool |
|
39 | + */ |
|
40 | + protected function matches($other) |
|
41 | + { |
|
42 | + return \substr($other, 0 - \strlen($this->suffix)) == $this->suffix; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns a string representation of the constraint. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function toString() |
|
51 | - { |
|
52 | - return 'ends with "' . $this->suffix . '"'; |
|
53 | - } |
|
45 | + /** |
|
46 | + * Returns a string representation of the constraint. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function toString() |
|
51 | + { |
|
52 | + return 'ends with "' . $this->suffix . '"'; |
|
53 | + } |
|
54 | 54 | } |
@@ -49,6 +49,6 @@ |
||
49 | 49 | */ |
50 | 50 | public function toString() |
51 | 51 | { |
52 | - return 'ends with "' . $this->suffix . '"'; |
|
52 | + return 'ends with "'.$this->suffix.'"'; |
|
53 | 53 | } |
54 | 54 | } |
@@ -17,81 +17,81 @@ |
||
17 | 17 | */ |
18 | 18 | class TraversableContainsOnly extends Constraint |
19 | 19 | { |
20 | - /** |
|
21 | - * @var Constraint |
|
22 | - */ |
|
23 | - protected $constraint; |
|
20 | + /** |
|
21 | + * @var Constraint |
|
22 | + */ |
|
23 | + protected $constraint; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $type; |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $type; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $type |
|
32 | - * @param bool $isNativeType |
|
33 | - */ |
|
34 | - public function __construct($type, $isNativeType = true) |
|
35 | - { |
|
36 | - parent::__construct(); |
|
30 | + /** |
|
31 | + * @param string $type |
|
32 | + * @param bool $isNativeType |
|
33 | + */ |
|
34 | + public function __construct($type, $isNativeType = true) |
|
35 | + { |
|
36 | + parent::__construct(); |
|
37 | 37 | |
38 | - if ($isNativeType) { |
|
39 | - $this->constraint = new IsType($type); |
|
40 | - } else { |
|
41 | - $this->constraint = new IsInstanceOf( |
|
42 | - $type |
|
43 | - ); |
|
44 | - } |
|
38 | + if ($isNativeType) { |
|
39 | + $this->constraint = new IsType($type); |
|
40 | + } else { |
|
41 | + $this->constraint = new IsInstanceOf( |
|
42 | + $type |
|
43 | + ); |
|
44 | + } |
|
45 | 45 | |
46 | - $this->type = $type; |
|
47 | - } |
|
46 | + $this->type = $type; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Evaluates the constraint for parameter $other |
|
51 | - * |
|
52 | - * If $returnResult is set to false (the default), an exception is thrown |
|
53 | - * in case of a failure. null is returned otherwise. |
|
54 | - * |
|
55 | - * If $returnResult is true, the result of the evaluation is returned as |
|
56 | - * a boolean value instead: true in case of success, false in case of a |
|
57 | - * failure. |
|
58 | - * |
|
59 | - * @param mixed $other Value or object to evaluate. |
|
60 | - * @param string $description Additional information about the test |
|
61 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
62 | - * |
|
63 | - * @return mixed |
|
64 | - * |
|
65 | - * @throws ExpectationFailedException |
|
66 | - */ |
|
67 | - public function evaluate($other, $description = '', $returnResult = false) |
|
68 | - { |
|
69 | - $success = true; |
|
49 | + /** |
|
50 | + * Evaluates the constraint for parameter $other |
|
51 | + * |
|
52 | + * If $returnResult is set to false (the default), an exception is thrown |
|
53 | + * in case of a failure. null is returned otherwise. |
|
54 | + * |
|
55 | + * If $returnResult is true, the result of the evaluation is returned as |
|
56 | + * a boolean value instead: true in case of success, false in case of a |
|
57 | + * failure. |
|
58 | + * |
|
59 | + * @param mixed $other Value or object to evaluate. |
|
60 | + * @param string $description Additional information about the test |
|
61 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
62 | + * |
|
63 | + * @return mixed |
|
64 | + * |
|
65 | + * @throws ExpectationFailedException |
|
66 | + */ |
|
67 | + public function evaluate($other, $description = '', $returnResult = false) |
|
68 | + { |
|
69 | + $success = true; |
|
70 | 70 | |
71 | - foreach ($other as $item) { |
|
72 | - if (!$this->constraint->evaluate($item, '', true)) { |
|
73 | - $success = false; |
|
71 | + foreach ($other as $item) { |
|
72 | + if (!$this->constraint->evaluate($item, '', true)) { |
|
73 | + $success = false; |
|
74 | 74 | |
75 | - break; |
|
76 | - } |
|
77 | - } |
|
75 | + break; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - if ($returnResult) { |
|
80 | - return $success; |
|
81 | - } |
|
79 | + if ($returnResult) { |
|
80 | + return $success; |
|
81 | + } |
|
82 | 82 | |
83 | - if (!$success) { |
|
84 | - $this->fail($other, $description); |
|
85 | - } |
|
86 | - } |
|
83 | + if (!$success) { |
|
84 | + $this->fail($other, $description); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Returns a string representation of the constraint. |
|
90 | - * |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function toString() |
|
94 | - { |
|
95 | - return 'contains only values of type "' . $this->type . '"'; |
|
96 | - } |
|
88 | + /** |
|
89 | + * Returns a string representation of the constraint. |
|
90 | + * |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function toString() |
|
94 | + { |
|
95 | + return 'contains only values of type "' . $this->type . '"'; |
|
96 | + } |
|
97 | 97 | } |
@@ -92,6 +92,6 @@ |
||
92 | 92 | */ |
93 | 93 | public function toString() |
94 | 94 | { |
95 | - return 'contains only values of type "' . $this->type . '"'; |
|
95 | + return 'contains only values of type "'.$this->type.'"'; |
|
96 | 96 | } |
97 | 97 | } |
@@ -16,47 +16,47 @@ |
||
16 | 16 | */ |
17 | 17 | class Callback extends Constraint |
18 | 18 | { |
19 | - private $callback; |
|
19 | + private $callback; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param callable $callback |
|
23 | - * |
|
24 | - * @throws \PHPUnit\Framework\Exception |
|
25 | - */ |
|
26 | - public function __construct($callback) |
|
27 | - { |
|
28 | - if (!\is_callable($callback)) { |
|
29 | - throw InvalidArgumentHelper::factory( |
|
30 | - 1, |
|
31 | - 'callable' |
|
32 | - ); |
|
33 | - } |
|
21 | + /** |
|
22 | + * @param callable $callback |
|
23 | + * |
|
24 | + * @throws \PHPUnit\Framework\Exception |
|
25 | + */ |
|
26 | + public function __construct($callback) |
|
27 | + { |
|
28 | + if (!\is_callable($callback)) { |
|
29 | + throw InvalidArgumentHelper::factory( |
|
30 | + 1, |
|
31 | + 'callable' |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - parent::__construct(); |
|
35 | + parent::__construct(); |
|
36 | 36 | |
37 | - $this->callback = $callback; |
|
38 | - } |
|
37 | + $this->callback = $callback; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Evaluates the constraint for parameter $value. Returns true if the |
|
42 | - * constraint is met, false otherwise. |
|
43 | - * |
|
44 | - * @param mixed $other Value or object to evaluate. |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - protected function matches($other) |
|
49 | - { |
|
50 | - return \call_user_func($this->callback, $other); |
|
51 | - } |
|
40 | + /** |
|
41 | + * Evaluates the constraint for parameter $value. Returns true if the |
|
42 | + * constraint is met, false otherwise. |
|
43 | + * |
|
44 | + * @param mixed $other Value or object to evaluate. |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + protected function matches($other) |
|
49 | + { |
|
50 | + return \call_user_func($this->callback, $other); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns a string representation of the constraint. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function toString() |
|
59 | - { |
|
60 | - return 'is accepted by specified callback'; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Returns a string representation of the constraint. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function toString() |
|
59 | + { |
|
60 | + return 'is accepted by specified callback'; |
|
61 | + } |
|
62 | 62 | } |
@@ -21,135 +21,135 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class Constraint implements Countable, SelfDescribing |
23 | 23 | { |
24 | - protected $exporter; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->exporter = new Exporter; |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Evaluates the constraint for parameter $other |
|
33 | - * |
|
34 | - * If $returnResult is set to false (the default), an exception is thrown |
|
35 | - * in case of a failure. null is returned otherwise. |
|
36 | - * |
|
37 | - * If $returnResult is true, the result of the evaluation is returned as |
|
38 | - * a boolean value instead: true in case of success, false in case of a |
|
39 | - * failure. |
|
40 | - * |
|
41 | - * @param mixed $other Value or object to evaluate. |
|
42 | - * @param string $description Additional information about the test |
|
43 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
44 | - * |
|
45 | - * @return mixed |
|
46 | - * |
|
47 | - * @throws ExpectationFailedException |
|
48 | - */ |
|
49 | - public function evaluate($other, $description = '', $returnResult = false) |
|
50 | - { |
|
51 | - $success = false; |
|
52 | - |
|
53 | - if ($this->matches($other)) { |
|
54 | - $success = true; |
|
55 | - } |
|
56 | - |
|
57 | - if ($returnResult) { |
|
58 | - return $success; |
|
59 | - } |
|
60 | - |
|
61 | - if (!$success) { |
|
62 | - $this->fail($other, $description); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
68 | - * constraint is met, false otherwise. |
|
69 | - * |
|
70 | - * This method can be overridden to implement the evaluation algorithm. |
|
71 | - * |
|
72 | - * @param mixed $other Value or object to evaluate. |
|
73 | - * |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - protected function matches($other) |
|
77 | - { |
|
78 | - return false; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Counts the number of constraint elements. |
|
83 | - * |
|
84 | - * @return int |
|
85 | - */ |
|
86 | - public function count() |
|
87 | - { |
|
88 | - return 1; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Throws an exception for the given compared value and test description |
|
93 | - * |
|
94 | - * @param mixed $other Evaluated value or object. |
|
95 | - * @param string $description Additional information about the test |
|
96 | - * @param ComparisonFailure $comparisonFailure |
|
97 | - * |
|
98 | - * @throws ExpectationFailedException |
|
99 | - */ |
|
100 | - protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) |
|
101 | - { |
|
102 | - $failureDescription = \sprintf( |
|
103 | - 'Failed asserting that %s.', |
|
104 | - $this->failureDescription($other) |
|
105 | - ); |
|
106 | - |
|
107 | - $additionalFailureDescription = $this->additionalFailureDescription($other); |
|
108 | - |
|
109 | - if ($additionalFailureDescription) { |
|
110 | - $failureDescription .= "\n" . $additionalFailureDescription; |
|
111 | - } |
|
112 | - |
|
113 | - if (!empty($description)) { |
|
114 | - $failureDescription = $description . "\n" . $failureDescription; |
|
115 | - } |
|
116 | - |
|
117 | - throw new ExpectationFailedException( |
|
118 | - $failureDescription, |
|
119 | - $comparisonFailure |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Return additional failure description where needed |
|
125 | - * |
|
126 | - * The function can be overridden to provide additional failure |
|
127 | - * information like a diff |
|
128 | - * |
|
129 | - * @param mixed $other Evaluated value or object. |
|
130 | - * |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - protected function additionalFailureDescription($other) |
|
134 | - { |
|
135 | - return ''; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Returns the description of the failure |
|
140 | - * |
|
141 | - * The beginning of failure messages is "Failed asserting that" in most |
|
142 | - * cases. This method should return the second part of that sentence. |
|
143 | - * |
|
144 | - * To provide additional failure information additionalFailureDescription |
|
145 | - * can be used. |
|
146 | - * |
|
147 | - * @param mixed $other Evaluated value or object. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - protected function failureDescription($other) |
|
152 | - { |
|
153 | - return $this->exporter->export($other) . ' ' . $this->toString(); |
|
154 | - } |
|
24 | + protected $exporter; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->exporter = new Exporter; |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Evaluates the constraint for parameter $other |
|
33 | + * |
|
34 | + * If $returnResult is set to false (the default), an exception is thrown |
|
35 | + * in case of a failure. null is returned otherwise. |
|
36 | + * |
|
37 | + * If $returnResult is true, the result of the evaluation is returned as |
|
38 | + * a boolean value instead: true in case of success, false in case of a |
|
39 | + * failure. |
|
40 | + * |
|
41 | + * @param mixed $other Value or object to evaluate. |
|
42 | + * @param string $description Additional information about the test |
|
43 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
44 | + * |
|
45 | + * @return mixed |
|
46 | + * |
|
47 | + * @throws ExpectationFailedException |
|
48 | + */ |
|
49 | + public function evaluate($other, $description = '', $returnResult = false) |
|
50 | + { |
|
51 | + $success = false; |
|
52 | + |
|
53 | + if ($this->matches($other)) { |
|
54 | + $success = true; |
|
55 | + } |
|
56 | + |
|
57 | + if ($returnResult) { |
|
58 | + return $success; |
|
59 | + } |
|
60 | + |
|
61 | + if (!$success) { |
|
62 | + $this->fail($other, $description); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
68 | + * constraint is met, false otherwise. |
|
69 | + * |
|
70 | + * This method can be overridden to implement the evaluation algorithm. |
|
71 | + * |
|
72 | + * @param mixed $other Value or object to evaluate. |
|
73 | + * |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + protected function matches($other) |
|
77 | + { |
|
78 | + return false; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Counts the number of constraint elements. |
|
83 | + * |
|
84 | + * @return int |
|
85 | + */ |
|
86 | + public function count() |
|
87 | + { |
|
88 | + return 1; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Throws an exception for the given compared value and test description |
|
93 | + * |
|
94 | + * @param mixed $other Evaluated value or object. |
|
95 | + * @param string $description Additional information about the test |
|
96 | + * @param ComparisonFailure $comparisonFailure |
|
97 | + * |
|
98 | + * @throws ExpectationFailedException |
|
99 | + */ |
|
100 | + protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) |
|
101 | + { |
|
102 | + $failureDescription = \sprintf( |
|
103 | + 'Failed asserting that %s.', |
|
104 | + $this->failureDescription($other) |
|
105 | + ); |
|
106 | + |
|
107 | + $additionalFailureDescription = $this->additionalFailureDescription($other); |
|
108 | + |
|
109 | + if ($additionalFailureDescription) { |
|
110 | + $failureDescription .= "\n" . $additionalFailureDescription; |
|
111 | + } |
|
112 | + |
|
113 | + if (!empty($description)) { |
|
114 | + $failureDescription = $description . "\n" . $failureDescription; |
|
115 | + } |
|
116 | + |
|
117 | + throw new ExpectationFailedException( |
|
118 | + $failureDescription, |
|
119 | + $comparisonFailure |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Return additional failure description where needed |
|
125 | + * |
|
126 | + * The function can be overridden to provide additional failure |
|
127 | + * information like a diff |
|
128 | + * |
|
129 | + * @param mixed $other Evaluated value or object. |
|
130 | + * |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + protected function additionalFailureDescription($other) |
|
134 | + { |
|
135 | + return ''; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Returns the description of the failure |
|
140 | + * |
|
141 | + * The beginning of failure messages is "Failed asserting that" in most |
|
142 | + * cases. This method should return the second part of that sentence. |
|
143 | + * |
|
144 | + * To provide additional failure information additionalFailureDescription |
|
145 | + * can be used. |
|
146 | + * |
|
147 | + * @param mixed $other Evaluated value or object. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + protected function failureDescription($other) |
|
152 | + { |
|
153 | + return $this->exporter->export($other) . ' ' . $this->toString(); |
|
154 | + } |
|
155 | 155 | } |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | $additionalFailureDescription = $this->additionalFailureDescription($other); |
108 | 108 | |
109 | 109 | if ($additionalFailureDescription) { |
110 | - $failureDescription .= "\n" . $additionalFailureDescription; |
|
110 | + $failureDescription .= "\n".$additionalFailureDescription; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | if (!empty($description)) { |
114 | - $failureDescription = $description . "\n" . $failureDescription; |
|
114 | + $failureDescription = $description."\n".$failureDescription; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | throw new ExpectationFailedException( |
@@ -150,6 +150,6 @@ discard block |
||
150 | 150 | */ |
151 | 151 | protected function failureDescription($other) |
152 | 152 | { |
153 | - return $this->exporter->export($other) . ' ' . $this->toString(); |
|
153 | + return $this->exporter->export($other).' '.$this->toString(); |
|
154 | 154 | } |
155 | 155 | } |
@@ -16,44 +16,44 @@ |
||
16 | 16 | */ |
17 | 17 | class IsWritable extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
21 | - * constraint is met, false otherwise. |
|
22 | - * |
|
23 | - * @param mixed $other Value or object to evaluate. |
|
24 | - * |
|
25 | - * @return bool |
|
26 | - */ |
|
27 | - protected function matches($other) |
|
28 | - { |
|
29 | - return \is_writable($other); |
|
30 | - } |
|
19 | + /** |
|
20 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
21 | + * constraint is met, false otherwise. |
|
22 | + * |
|
23 | + * @param mixed $other Value or object to evaluate. |
|
24 | + * |
|
25 | + * @return bool |
|
26 | + */ |
|
27 | + protected function matches($other) |
|
28 | + { |
|
29 | + return \is_writable($other); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Returns the description of the failure |
|
34 | - * |
|
35 | - * The beginning of failure messages is "Failed asserting that" in most |
|
36 | - * cases. This method should return the second part of that sentence. |
|
37 | - * |
|
38 | - * @param mixed $other Evaluated value or object. |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function failureDescription($other) |
|
43 | - { |
|
44 | - return \sprintf( |
|
45 | - '"%s" is writable', |
|
46 | - $other |
|
47 | - ); |
|
48 | - } |
|
32 | + /** |
|
33 | + * Returns the description of the failure |
|
34 | + * |
|
35 | + * The beginning of failure messages is "Failed asserting that" in most |
|
36 | + * cases. This method should return the second part of that sentence. |
|
37 | + * |
|
38 | + * @param mixed $other Evaluated value or object. |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function failureDescription($other) |
|
43 | + { |
|
44 | + return \sprintf( |
|
45 | + '"%s" is writable', |
|
46 | + $other |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns a string representation of the constraint. |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function toString() |
|
56 | - { |
|
57 | - return 'is writable'; |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns a string representation of the constraint. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function toString() |
|
56 | + { |
|
57 | + return 'is writable'; |
|
58 | + } |
|
59 | 59 | } |
@@ -19,65 +19,65 @@ |
||
19 | 19 | */ |
20 | 20 | class ClassHasAttribute extends Constraint |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $attributeName; |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $attributeName; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param string $attributeName |
|
29 | - */ |
|
30 | - public function __construct($attributeName) |
|
31 | - { |
|
32 | - parent::__construct(); |
|
33 | - $this->attributeName = $attributeName; |
|
34 | - } |
|
27 | + /** |
|
28 | + * @param string $attributeName |
|
29 | + */ |
|
30 | + public function __construct($attributeName) |
|
31 | + { |
|
32 | + parent::__construct(); |
|
33 | + $this->attributeName = $attributeName; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
38 | - * constraint is met, false otherwise. |
|
39 | - * |
|
40 | - * @param mixed $other Value or object to evaluate. |
|
41 | - * |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - protected function matches($other) |
|
45 | - { |
|
46 | - $class = new ReflectionClass($other); |
|
36 | + /** |
|
37 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
38 | + * constraint is met, false otherwise. |
|
39 | + * |
|
40 | + * @param mixed $other Value or object to evaluate. |
|
41 | + * |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + protected function matches($other) |
|
45 | + { |
|
46 | + $class = new ReflectionClass($other); |
|
47 | 47 | |
48 | - return $class->hasProperty($this->attributeName); |
|
49 | - } |
|
48 | + return $class->hasProperty($this->attributeName); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns a string representation of the constraint. |
|
53 | - * |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function toString() |
|
57 | - { |
|
58 | - return \sprintf( |
|
59 | - 'has attribute "%s"', |
|
60 | - $this->attributeName |
|
61 | - ); |
|
62 | - } |
|
51 | + /** |
|
52 | + * Returns a string representation of the constraint. |
|
53 | + * |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function toString() |
|
57 | + { |
|
58 | + return \sprintf( |
|
59 | + 'has attribute "%s"', |
|
60 | + $this->attributeName |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns the description of the failure |
|
66 | - * |
|
67 | - * The beginning of failure messages is "Failed asserting that" in most |
|
68 | - * cases. This method should return the second part of that sentence. |
|
69 | - * |
|
70 | - * @param mixed $other Evaluated value or object. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - protected function failureDescription($other) |
|
75 | - { |
|
76 | - return \sprintf( |
|
77 | - '%sclass "%s" %s', |
|
78 | - \is_object($other) ? 'object of ' : '', |
|
79 | - \is_object($other) ? \get_class($other) : $other, |
|
80 | - $this->toString() |
|
81 | - ); |
|
82 | - } |
|
64 | + /** |
|
65 | + * Returns the description of the failure |
|
66 | + * |
|
67 | + * The beginning of failure messages is "Failed asserting that" in most |
|
68 | + * cases. This method should return the second part of that sentence. |
|
69 | + * |
|
70 | + * @param mixed $other Evaluated value or object. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + protected function failureDescription($other) |
|
75 | + { |
|
76 | + return \sprintf( |
|
77 | + '%sclass "%s" %s', |
|
78 | + \is_object($other) ? 'object of ' : '', |
|
79 | + \is_object($other) ? \get_class($other) : $other, |
|
80 | + $this->toString() |
|
81 | + ); |
|
82 | + } |
|
83 | 83 | } |
@@ -11,73 +11,73 @@ |
||
11 | 11 | |
12 | 12 | class ExceptionMessage extends Constraint |
13 | 13 | { |
14 | - /** |
|
15 | - * @var int |
|
16 | - */ |
|
17 | - protected $expectedMessage; |
|
14 | + /** |
|
15 | + * @var int |
|
16 | + */ |
|
17 | + protected $expectedMessage; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $expected |
|
21 | - */ |
|
22 | - public function __construct($expected) |
|
23 | - { |
|
24 | - parent::__construct(); |
|
19 | + /** |
|
20 | + * @param string $expected |
|
21 | + */ |
|
22 | + public function __construct($expected) |
|
23 | + { |
|
24 | + parent::__construct(); |
|
25 | 25 | |
26 | - $this->expectedMessage = $expected; |
|
27 | - } |
|
26 | + $this->expectedMessage = $expected; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
31 | - * constraint is met, false otherwise. |
|
32 | - * |
|
33 | - * @param \Throwable $other |
|
34 | - * |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - protected function matches($other) |
|
38 | - { |
|
39 | - if ($this->expectedMessage === '') { |
|
40 | - return $other->getMessage() === ''; |
|
41 | - } |
|
29 | + /** |
|
30 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
31 | + * constraint is met, false otherwise. |
|
32 | + * |
|
33 | + * @param \Throwable $other |
|
34 | + * |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + protected function matches($other) |
|
38 | + { |
|
39 | + if ($this->expectedMessage === '') { |
|
40 | + return $other->getMessage() === ''; |
|
41 | + } |
|
42 | 42 | |
43 | - return \strpos($other->getMessage(), $this->expectedMessage) !== false; |
|
44 | - } |
|
43 | + return \strpos($other->getMessage(), $this->expectedMessage) !== false; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Returns the description of the failure |
|
48 | - * |
|
49 | - * The beginning of failure messages is "Failed asserting that" in most |
|
50 | - * cases. This method should return the second part of that sentence. |
|
51 | - * |
|
52 | - * @param mixed $other Evaluated value or object. |
|
53 | - * |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function failureDescription($other) |
|
57 | - { |
|
58 | - if ($this->expectedMessage === '') { |
|
59 | - return \sprintf( |
|
60 | - "exception message is empty but is '%s'", |
|
61 | - $other->getMessage() |
|
62 | - ); |
|
63 | - } |
|
46 | + /** |
|
47 | + * Returns the description of the failure |
|
48 | + * |
|
49 | + * The beginning of failure messages is "Failed asserting that" in most |
|
50 | + * cases. This method should return the second part of that sentence. |
|
51 | + * |
|
52 | + * @param mixed $other Evaluated value or object. |
|
53 | + * |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function failureDescription($other) |
|
57 | + { |
|
58 | + if ($this->expectedMessage === '') { |
|
59 | + return \sprintf( |
|
60 | + "exception message is empty but is '%s'", |
|
61 | + $other->getMessage() |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | |
65 | - return \sprintf( |
|
66 | - "exception message '%s' contains '%s'", |
|
67 | - $other->getMessage(), |
|
68 | - $this->expectedMessage |
|
69 | - ); |
|
70 | - } |
|
65 | + return \sprintf( |
|
66 | + "exception message '%s' contains '%s'", |
|
67 | + $other->getMessage(), |
|
68 | + $this->expectedMessage |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function toString() |
|
76 | - { |
|
77 | - if ($this->expectedMessage === '') { |
|
78 | - return 'exception message is empty'; |
|
79 | - } |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function toString() |
|
76 | + { |
|
77 | + if ($this->expectedMessage === '') { |
|
78 | + return 'exception message is empty'; |
|
79 | + } |
|
80 | 80 | |
81 | - return 'exception message contains '; |
|
82 | - } |
|
81 | + return 'exception message contains '; |
|
82 | + } |
|
83 | 83 | } |