@@ -16,44 +16,44 @@ |
||
16 | 16 | */ |
17 | 17 | class IsReadable 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_readable($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_readable($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 readable', |
|
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 readable', |
|
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 readable'; |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns a string representation of the constraint. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function toString() |
|
56 | + { |
|
57 | + return 'is readable'; |
|
58 | + } |
|
59 | 59 | } |
@@ -25,109 +25,109 @@ |
||
25 | 25 | */ |
26 | 26 | class IsIdentical extends Constraint |
27 | 27 | { |
28 | - /** |
|
29 | - * @var float |
|
30 | - */ |
|
31 | - const EPSILON = 0.0000000001; |
|
28 | + /** |
|
29 | + * @var float |
|
30 | + */ |
|
31 | + const EPSILON = 0.0000000001; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var mixed |
|
35 | - */ |
|
36 | - protected $value; |
|
33 | + /** |
|
34 | + * @var mixed |
|
35 | + */ |
|
36 | + protected $value; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param mixed $value |
|
40 | - */ |
|
41 | - public function __construct($value) |
|
42 | - { |
|
43 | - parent::__construct(); |
|
44 | - $this->value = $value; |
|
45 | - } |
|
38 | + /** |
|
39 | + * @param mixed $value |
|
40 | + */ |
|
41 | + public function __construct($value) |
|
42 | + { |
|
43 | + parent::__construct(); |
|
44 | + $this->value = $value; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Evaluates the constraint for parameter $other |
|
49 | - * |
|
50 | - * If $returnResult is set to false (the default), an exception is thrown |
|
51 | - * in case of a failure. null is returned otherwise. |
|
52 | - * |
|
53 | - * If $returnResult is true, the result of the evaluation is returned as |
|
54 | - * a boolean value instead: true in case of success, false in case of a |
|
55 | - * failure. |
|
56 | - * |
|
57 | - * @param mixed $other Value or object to evaluate. |
|
58 | - * @param string $description Additional information about the test |
|
59 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
60 | - * |
|
61 | - * @return mixed |
|
62 | - * |
|
63 | - * @throws ExpectationFailedException |
|
64 | - */ |
|
65 | - public function evaluate($other, $description = '', $returnResult = false) |
|
66 | - { |
|
67 | - if (\is_float($this->value) && \is_float($other) && |
|
68 | - !\is_infinite($this->value) && !\is_infinite($other) && |
|
69 | - !\is_nan($this->value) && !\is_nan($other)) { |
|
70 | - $success = \abs($this->value - $other) < self::EPSILON; |
|
71 | - } else { |
|
72 | - $success = $this->value === $other; |
|
73 | - } |
|
47 | + /** |
|
48 | + * Evaluates the constraint for parameter $other |
|
49 | + * |
|
50 | + * If $returnResult is set to false (the default), an exception is thrown |
|
51 | + * in case of a failure. null is returned otherwise. |
|
52 | + * |
|
53 | + * If $returnResult is true, the result of the evaluation is returned as |
|
54 | + * a boolean value instead: true in case of success, false in case of a |
|
55 | + * failure. |
|
56 | + * |
|
57 | + * @param mixed $other Value or object to evaluate. |
|
58 | + * @param string $description Additional information about the test |
|
59 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
60 | + * |
|
61 | + * @return mixed |
|
62 | + * |
|
63 | + * @throws ExpectationFailedException |
|
64 | + */ |
|
65 | + public function evaluate($other, $description = '', $returnResult = false) |
|
66 | + { |
|
67 | + if (\is_float($this->value) && \is_float($other) && |
|
68 | + !\is_infinite($this->value) && !\is_infinite($other) && |
|
69 | + !\is_nan($this->value) && !\is_nan($other)) { |
|
70 | + $success = \abs($this->value - $other) < self::EPSILON; |
|
71 | + } else { |
|
72 | + $success = $this->value === $other; |
|
73 | + } |
|
74 | 74 | |
75 | - if ($returnResult) { |
|
76 | - return $success; |
|
77 | - } |
|
75 | + if ($returnResult) { |
|
76 | + return $success; |
|
77 | + } |
|
78 | 78 | |
79 | - if (!$success) { |
|
80 | - $f = null; |
|
79 | + if (!$success) { |
|
80 | + $f = null; |
|
81 | 81 | |
82 | - // if both values are strings, make sure a diff is generated |
|
83 | - if (\is_string($this->value) && \is_string($other)) { |
|
84 | - $f = new SebastianBergmann\Comparator\ComparisonFailure( |
|
85 | - $this->value, |
|
86 | - $other, |
|
87 | - \sprintf("'%s'", $this->value), |
|
88 | - \sprintf("'%s'", $other) |
|
89 | - ); |
|
90 | - } |
|
82 | + // if both values are strings, make sure a diff is generated |
|
83 | + if (\is_string($this->value) && \is_string($other)) { |
|
84 | + $f = new SebastianBergmann\Comparator\ComparisonFailure( |
|
85 | + $this->value, |
|
86 | + $other, |
|
87 | + \sprintf("'%s'", $this->value), |
|
88 | + \sprintf("'%s'", $other) |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | |
92 | - $this->fail($other, $description, $f); |
|
93 | - } |
|
94 | - } |
|
92 | + $this->fail($other, $description, $f); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Returns the description of the failure |
|
98 | - * |
|
99 | - * The beginning of failure messages is "Failed asserting that" in most |
|
100 | - * cases. This method should return the second part of that sentence. |
|
101 | - * |
|
102 | - * @param mixed $other Evaluated value or object. |
|
103 | - * |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - protected function failureDescription($other) |
|
107 | - { |
|
108 | - if (\is_object($this->value) && \is_object($other)) { |
|
109 | - return 'two variables reference the same object'; |
|
110 | - } |
|
96 | + /** |
|
97 | + * Returns the description of the failure |
|
98 | + * |
|
99 | + * The beginning of failure messages is "Failed asserting that" in most |
|
100 | + * cases. This method should return the second part of that sentence. |
|
101 | + * |
|
102 | + * @param mixed $other Evaluated value or object. |
|
103 | + * |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + protected function failureDescription($other) |
|
107 | + { |
|
108 | + if (\is_object($this->value) && \is_object($other)) { |
|
109 | + return 'two variables reference the same object'; |
|
110 | + } |
|
111 | 111 | |
112 | - if (\is_string($this->value) && \is_string($other)) { |
|
113 | - return 'two strings are identical'; |
|
114 | - } |
|
112 | + if (\is_string($this->value) && \is_string($other)) { |
|
113 | + return 'two strings are identical'; |
|
114 | + } |
|
115 | 115 | |
116 | - return parent::failureDescription($other); |
|
117 | - } |
|
116 | + return parent::failureDescription($other); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Returns a string representation of the constraint. |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function toString() |
|
125 | - { |
|
126 | - if (\is_object($this->value)) { |
|
127 | - return 'is identical to an object of class "' . |
|
128 | - \get_class($this->value) . '"'; |
|
129 | - } |
|
119 | + /** |
|
120 | + * Returns a string representation of the constraint. |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function toString() |
|
125 | + { |
|
126 | + if (\is_object($this->value)) { |
|
127 | + return 'is identical to an object of class "' . |
|
128 | + \get_class($this->value) . '"'; |
|
129 | + } |
|
130 | 130 | |
131 | - return 'is identical to ' . $this->exporter->export($this->value); |
|
132 | - } |
|
131 | + return 'is identical to ' . $this->exporter->export($this->value); |
|
132 | + } |
|
133 | 133 | } |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsFinite 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_finite($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_finite($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 finite'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is finite'; |
|
38 | + } |
|
39 | 39 | } |
@@ -17,130 +17,130 @@ |
||
17 | 17 | */ |
18 | 18 | class JsonMatches extends Constraint |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $value; |
|
24 | - |
|
25 | - /** |
|
26 | - * Creates a new constraint. |
|
27 | - * |
|
28 | - * @param string $value |
|
29 | - */ |
|
30 | - public function __construct($value) |
|
31 | - { |
|
32 | - parent::__construct(); |
|
33 | - $this->value = $value; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
38 | - * constraint is met, false otherwise. |
|
39 | - * |
|
40 | - * This method can be overridden to implement the evaluation algorithm. |
|
41 | - * |
|
42 | - * @param mixed $other Value or object to evaluate. |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - protected function matches($other) |
|
47 | - { |
|
48 | - list($error, $recodedOther) = $this->canonicalizeJson($other); |
|
49 | - if ($error) { |
|
50 | - return false; |
|
51 | - } |
|
52 | - |
|
53 | - list($error, $recodedValue) = $this->canonicalizeJson($this->value); |
|
54 | - if ($error) { |
|
55 | - return false; |
|
56 | - } |
|
57 | - |
|
58 | - return $recodedOther == $recodedValue; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Throws an exception for the given compared value and test description |
|
63 | - * |
|
64 | - * @param mixed $other Evaluated value or object. |
|
65 | - * @param string $description Additional information about the test |
|
66 | - * @param ComparisonFailure $comparisonFailure |
|
67 | - * |
|
68 | - * @throws ExpectationFailedException |
|
69 | - */ |
|
70 | - protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) |
|
71 | - { |
|
72 | - if ($comparisonFailure === null) { |
|
73 | - list($error) = $this->canonicalizeJson($other); |
|
74 | - if ($error) { |
|
75 | - parent::fail($other, $description); |
|
76 | - |
|
77 | - return; |
|
78 | - } |
|
79 | - |
|
80 | - list($error) = $this->canonicalizeJson($this->value); |
|
81 | - if ($error) { |
|
82 | - parent::fail($other, $description); |
|
83 | - |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $comparisonFailure = new ComparisonFailure( |
|
88 | - \json_decode($this->value), |
|
89 | - \json_decode($other), |
|
90 | - $other, |
|
91 | - $this->value, |
|
92 | - false, |
|
93 | - 'Failed asserting that two json values are equal.' |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - parent::fail($other, $description, $comparisonFailure); |
|
98 | - } |
|
99 | - |
|
100 | - /* |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $value; |
|
24 | + |
|
25 | + /** |
|
26 | + * Creates a new constraint. |
|
27 | + * |
|
28 | + * @param string $value |
|
29 | + */ |
|
30 | + public function __construct($value) |
|
31 | + { |
|
32 | + parent::__construct(); |
|
33 | + $this->value = $value; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
38 | + * constraint is met, false otherwise. |
|
39 | + * |
|
40 | + * This method can be overridden to implement the evaluation algorithm. |
|
41 | + * |
|
42 | + * @param mixed $other Value or object to evaluate. |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + protected function matches($other) |
|
47 | + { |
|
48 | + list($error, $recodedOther) = $this->canonicalizeJson($other); |
|
49 | + if ($error) { |
|
50 | + return false; |
|
51 | + } |
|
52 | + |
|
53 | + list($error, $recodedValue) = $this->canonicalizeJson($this->value); |
|
54 | + if ($error) { |
|
55 | + return false; |
|
56 | + } |
|
57 | + |
|
58 | + return $recodedOther == $recodedValue; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Throws an exception for the given compared value and test description |
|
63 | + * |
|
64 | + * @param mixed $other Evaluated value or object. |
|
65 | + * @param string $description Additional information about the test |
|
66 | + * @param ComparisonFailure $comparisonFailure |
|
67 | + * |
|
68 | + * @throws ExpectationFailedException |
|
69 | + */ |
|
70 | + protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) |
|
71 | + { |
|
72 | + if ($comparisonFailure === null) { |
|
73 | + list($error) = $this->canonicalizeJson($other); |
|
74 | + if ($error) { |
|
75 | + parent::fail($other, $description); |
|
76 | + |
|
77 | + return; |
|
78 | + } |
|
79 | + |
|
80 | + list($error) = $this->canonicalizeJson($this->value); |
|
81 | + if ($error) { |
|
82 | + parent::fail($other, $description); |
|
83 | + |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $comparisonFailure = new ComparisonFailure( |
|
88 | + \json_decode($this->value), |
|
89 | + \json_decode($other), |
|
90 | + $other, |
|
91 | + $this->value, |
|
92 | + false, |
|
93 | + 'Failed asserting that two json values are equal.' |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + parent::fail($other, $description, $comparisonFailure); |
|
98 | + } |
|
99 | + |
|
100 | + /* |
|
101 | 101 | * To allow comparison of JSON strings, first process them into a consistent |
102 | 102 | * format so that they can be compared as strings. |
103 | 103 | * @return array ($error, $canonicalized_json) The $error parameter is used |
104 | 104 | * to indicate an error decoding the json. This is used to avoid ambiguity |
105 | 105 | * with JSON strings consisting entirely of 'null' or 'false'. |
106 | 106 | */ |
107 | - private function canonicalizeJson($json) |
|
108 | - { |
|
109 | - $decodedJson = \json_decode($json, true); |
|
110 | - if (\json_last_error()) { |
|
111 | - return [true, null]; |
|
112 | - } |
|
113 | - $this->recursiveSort($decodedJson); |
|
114 | - $reencodedJson = \json_encode($decodedJson); |
|
115 | - |
|
116 | - return [false, $reencodedJson]; |
|
117 | - } |
|
118 | - |
|
119 | - /* |
|
107 | + private function canonicalizeJson($json) |
|
108 | + { |
|
109 | + $decodedJson = \json_decode($json, true); |
|
110 | + if (\json_last_error()) { |
|
111 | + return [true, null]; |
|
112 | + } |
|
113 | + $this->recursiveSort($decodedJson); |
|
114 | + $reencodedJson = \json_encode($decodedJson); |
|
115 | + |
|
116 | + return [false, $reencodedJson]; |
|
117 | + } |
|
118 | + |
|
119 | + /* |
|
120 | 120 | * JSON object keys are unordered while PHP array keys are ordered. |
121 | 121 | * Sort all array keys to ensure both the expected and actual values have |
122 | 122 | * their keys in the same order. |
123 | 123 | */ |
124 | - private function recursiveSort(&$json) |
|
125 | - { |
|
126 | - if (\is_array($json)) { |
|
127 | - \ksort($json); |
|
128 | - foreach ($json as $key => &$value) { |
|
129 | - $this->recursiveSort($value); |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns a string representation of the object. |
|
136 | - * |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function toString() |
|
140 | - { |
|
141 | - return \sprintf( |
|
142 | - 'matches JSON string "%s"', |
|
143 | - $this->value |
|
144 | - ); |
|
145 | - } |
|
124 | + private function recursiveSort(&$json) |
|
125 | + { |
|
126 | + if (\is_array($json)) { |
|
127 | + \ksort($json); |
|
128 | + foreach ($json as $key => &$value) { |
|
129 | + $this->recursiveSort($value); |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns a string representation of the object. |
|
136 | + * |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function toString() |
|
140 | + { |
|
141 | + return \sprintf( |
|
142 | + 'matches JSON string "%s"', |
|
143 | + $this->value |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | } |
@@ -14,75 +14,75 @@ |
||
14 | 14 | |
15 | 15 | class Attribute extends Composite |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $attributeName; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $attributeName; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param Constraint $constraint |
|
24 | - * @param string $attributeName |
|
25 | - */ |
|
26 | - public function __construct(Constraint $constraint, $attributeName) |
|
27 | - { |
|
28 | - parent::__construct($constraint); |
|
22 | + /** |
|
23 | + * @param Constraint $constraint |
|
24 | + * @param string $attributeName |
|
25 | + */ |
|
26 | + public function __construct(Constraint $constraint, $attributeName) |
|
27 | + { |
|
28 | + parent::__construct($constraint); |
|
29 | 29 | |
30 | - $this->attributeName = $attributeName; |
|
31 | - } |
|
30 | + $this->attributeName = $attributeName; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Evaluates the constraint for parameter $other |
|
35 | - * |
|
36 | - * If $returnResult is set to false (the default), an exception is thrown |
|
37 | - * in case of a failure. null is returned otherwise. |
|
38 | - * |
|
39 | - * If $returnResult is true, the result of the evaluation is returned as |
|
40 | - * a boolean value instead: true in case of success, false in case of a |
|
41 | - * failure. |
|
42 | - * |
|
43 | - * @param mixed $other Value or object to evaluate. |
|
44 | - * @param string $description Additional information about the test |
|
45 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
46 | - * |
|
47 | - * @return mixed |
|
48 | - * |
|
49 | - * @throws ExpectationFailedException |
|
50 | - */ |
|
51 | - public function evaluate($other, $description = '', $returnResult = false) |
|
52 | - { |
|
53 | - return parent::evaluate( |
|
54 | - Assert::readAttribute( |
|
55 | - $other, |
|
56 | - $this->attributeName |
|
57 | - ), |
|
58 | - $description, |
|
59 | - $returnResult |
|
60 | - ); |
|
61 | - } |
|
33 | + /** |
|
34 | + * Evaluates the constraint for parameter $other |
|
35 | + * |
|
36 | + * If $returnResult is set to false (the default), an exception is thrown |
|
37 | + * in case of a failure. null is returned otherwise. |
|
38 | + * |
|
39 | + * If $returnResult is true, the result of the evaluation is returned as |
|
40 | + * a boolean value instead: true in case of success, false in case of a |
|
41 | + * failure. |
|
42 | + * |
|
43 | + * @param mixed $other Value or object to evaluate. |
|
44 | + * @param string $description Additional information about the test |
|
45 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
46 | + * |
|
47 | + * @return mixed |
|
48 | + * |
|
49 | + * @throws ExpectationFailedException |
|
50 | + */ |
|
51 | + public function evaluate($other, $description = '', $returnResult = false) |
|
52 | + { |
|
53 | + return parent::evaluate( |
|
54 | + Assert::readAttribute( |
|
55 | + $other, |
|
56 | + $this->attributeName |
|
57 | + ), |
|
58 | + $description, |
|
59 | + $returnResult |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Returns a string representation of the constraint. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function toString() |
|
69 | - { |
|
70 | - return 'attribute "' . $this->attributeName . '" ' . |
|
71 | - $this->innerConstraint->toString(); |
|
72 | - } |
|
63 | + /** |
|
64 | + * Returns a string representation of the constraint. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function toString() |
|
69 | + { |
|
70 | + return 'attribute "' . $this->attributeName . '" ' . |
|
71 | + $this->innerConstraint->toString(); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Returns the description of the failure |
|
76 | - * |
|
77 | - * The beginning of failure messages is "Failed asserting that" in most |
|
78 | - * cases. This method should return the second part of that sentence. |
|
79 | - * |
|
80 | - * @param mixed $other Evaluated value or object. |
|
81 | - * |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - protected function failureDescription($other) |
|
85 | - { |
|
86 | - return $this->toString(); |
|
87 | - } |
|
74 | + /** |
|
75 | + * Returns the description of the failure |
|
76 | + * |
|
77 | + * The beginning of failure messages is "Failed asserting that" in most |
|
78 | + * cases. This method should return the second part of that sentence. |
|
79 | + * |
|
80 | + * @param mixed $other Evaluated value or object. |
|
81 | + * |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + protected function failureDescription($other) |
|
85 | + { |
|
86 | + return $this->toString(); |
|
87 | + } |
|
88 | 88 | } |
@@ -16,107 +16,107 @@ |
||
16 | 16 | */ |
17 | 17 | class LogicalXor extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * @var Constraint[] |
|
21 | - */ |
|
22 | - protected $constraints = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * @param Constraint[] $constraints |
|
26 | - */ |
|
27 | - public function setConstraints(array $constraints) |
|
28 | - { |
|
29 | - $this->constraints = []; |
|
30 | - |
|
31 | - foreach ($constraints as $constraint) { |
|
32 | - if (!($constraint instanceof Constraint)) { |
|
33 | - $constraint = new IsEqual( |
|
34 | - $constraint |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - $this->constraints[] = $constraint; |
|
39 | - } |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Evaluates the constraint for parameter $other |
|
44 | - * |
|
45 | - * If $returnResult is set to false (the default), an exception is thrown |
|
46 | - * in case of a failure. null is returned otherwise. |
|
47 | - * |
|
48 | - * If $returnResult is true, the result of the evaluation is returned as |
|
49 | - * a boolean value instead: true in case of success, false in case of a |
|
50 | - * failure. |
|
51 | - * |
|
52 | - * @param mixed $other Value or object to evaluate. |
|
53 | - * @param string $description Additional information about the test |
|
54 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
55 | - * |
|
56 | - * @return mixed |
|
57 | - * |
|
58 | - * @throws ExpectationFailedException |
|
59 | - */ |
|
60 | - public function evaluate($other, $description = '', $returnResult = false) |
|
61 | - { |
|
62 | - $success = true; |
|
63 | - $lastResult = null; |
|
64 | - $constraint = null; |
|
65 | - |
|
66 | - foreach ($this->constraints as $constraint) { |
|
67 | - $result = $constraint->evaluate($other, $description, true); |
|
68 | - |
|
69 | - if ($result === $lastResult) { |
|
70 | - $success = false; |
|
71 | - |
|
72 | - break; |
|
73 | - } |
|
74 | - |
|
75 | - $lastResult = $result; |
|
76 | - } |
|
77 | - |
|
78 | - if ($returnResult) { |
|
79 | - return $success; |
|
80 | - } |
|
81 | - |
|
82 | - if (!$success) { |
|
83 | - $this->fail($other, $description); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns a string representation of the constraint. |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function toString() |
|
93 | - { |
|
94 | - $text = ''; |
|
95 | - |
|
96 | - foreach ($this->constraints as $key => $constraint) { |
|
97 | - if ($key > 0) { |
|
98 | - $text .= ' xor '; |
|
99 | - } |
|
100 | - |
|
101 | - $text .= $constraint->toString(); |
|
102 | - } |
|
103 | - |
|
104 | - return $text; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Counts the number of constraint elements. |
|
109 | - * |
|
110 | - * @return int |
|
111 | - */ |
|
112 | - public function count() |
|
113 | - { |
|
114 | - $count = 0; |
|
115 | - |
|
116 | - foreach ($this->constraints as $constraint) { |
|
117 | - $count += \count($constraint); |
|
118 | - } |
|
119 | - |
|
120 | - return $count; |
|
121 | - } |
|
19 | + /** |
|
20 | + * @var Constraint[] |
|
21 | + */ |
|
22 | + protected $constraints = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * @param Constraint[] $constraints |
|
26 | + */ |
|
27 | + public function setConstraints(array $constraints) |
|
28 | + { |
|
29 | + $this->constraints = []; |
|
30 | + |
|
31 | + foreach ($constraints as $constraint) { |
|
32 | + if (!($constraint instanceof Constraint)) { |
|
33 | + $constraint = new IsEqual( |
|
34 | + $constraint |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + $this->constraints[] = $constraint; |
|
39 | + } |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Evaluates the constraint for parameter $other |
|
44 | + * |
|
45 | + * If $returnResult is set to false (the default), an exception is thrown |
|
46 | + * in case of a failure. null is returned otherwise. |
|
47 | + * |
|
48 | + * If $returnResult is true, the result of the evaluation is returned as |
|
49 | + * a boolean value instead: true in case of success, false in case of a |
|
50 | + * failure. |
|
51 | + * |
|
52 | + * @param mixed $other Value or object to evaluate. |
|
53 | + * @param string $description Additional information about the test |
|
54 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
55 | + * |
|
56 | + * @return mixed |
|
57 | + * |
|
58 | + * @throws ExpectationFailedException |
|
59 | + */ |
|
60 | + public function evaluate($other, $description = '', $returnResult = false) |
|
61 | + { |
|
62 | + $success = true; |
|
63 | + $lastResult = null; |
|
64 | + $constraint = null; |
|
65 | + |
|
66 | + foreach ($this->constraints as $constraint) { |
|
67 | + $result = $constraint->evaluate($other, $description, true); |
|
68 | + |
|
69 | + if ($result === $lastResult) { |
|
70 | + $success = false; |
|
71 | + |
|
72 | + break; |
|
73 | + } |
|
74 | + |
|
75 | + $lastResult = $result; |
|
76 | + } |
|
77 | + |
|
78 | + if ($returnResult) { |
|
79 | + return $success; |
|
80 | + } |
|
81 | + |
|
82 | + if (!$success) { |
|
83 | + $this->fail($other, $description); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns a string representation of the constraint. |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function toString() |
|
93 | + { |
|
94 | + $text = ''; |
|
95 | + |
|
96 | + foreach ($this->constraints as $key => $constraint) { |
|
97 | + if ($key > 0) { |
|
98 | + $text .= ' xor '; |
|
99 | + } |
|
100 | + |
|
101 | + $text .= $constraint->toString(); |
|
102 | + } |
|
103 | + |
|
104 | + return $text; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Counts the number of constraint elements. |
|
109 | + * |
|
110 | + * @return int |
|
111 | + */ |
|
112 | + public function count() |
|
113 | + { |
|
114 | + $count = 0; |
|
115 | + |
|
116 | + foreach ($this->constraints as $constraint) { |
|
117 | + $count += \count($constraint); |
|
118 | + } |
|
119 | + |
|
120 | + return $count; |
|
121 | + } |
|
122 | 122 | } |
@@ -20,77 +20,77 @@ |
||
20 | 20 | */ |
21 | 21 | class IsInstanceOf extends Constraint |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $className; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $className; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $className |
|
30 | - */ |
|
31 | - public function __construct($className) |
|
32 | - { |
|
33 | - parent::__construct(); |
|
34 | - $this->className = $className; |
|
35 | - } |
|
28 | + /** |
|
29 | + * @param string $className |
|
30 | + */ |
|
31 | + public function __construct($className) |
|
32 | + { |
|
33 | + parent::__construct(); |
|
34 | + $this->className = $className; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
39 | - * constraint is met, false otherwise. |
|
40 | - * |
|
41 | - * @param mixed $other Value or object to evaluate. |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - protected function matches($other) |
|
46 | - { |
|
47 | - return ($other instanceof $this->className); |
|
48 | - } |
|
37 | + /** |
|
38 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
39 | + * constraint is met, false otherwise. |
|
40 | + * |
|
41 | + * @param mixed $other Value or object to evaluate. |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + protected function matches($other) |
|
46 | + { |
|
47 | + return ($other instanceof $this->className); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns the description of the failure |
|
52 | - * |
|
53 | - * The beginning of failure messages is "Failed asserting that" in most |
|
54 | - * cases. This method should return the second part of that sentence. |
|
55 | - * |
|
56 | - * @param mixed $other Evaluated value or object. |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - protected function failureDescription($other) |
|
61 | - { |
|
62 | - return \sprintf( |
|
63 | - '%s is an instance of %s "%s"', |
|
64 | - $this->exporter->shortenedExport($other), |
|
65 | - $this->getType(), |
|
66 | - $this->className |
|
67 | - ); |
|
68 | - } |
|
50 | + /** |
|
51 | + * Returns the description of the failure |
|
52 | + * |
|
53 | + * The beginning of failure messages is "Failed asserting that" in most |
|
54 | + * cases. This method should return the second part of that sentence. |
|
55 | + * |
|
56 | + * @param mixed $other Evaluated value or object. |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + protected function failureDescription($other) |
|
61 | + { |
|
62 | + return \sprintf( |
|
63 | + '%s is an instance of %s "%s"', |
|
64 | + $this->exporter->shortenedExport($other), |
|
65 | + $this->getType(), |
|
66 | + $this->className |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Returns a string representation of the constraint. |
|
72 | - * |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function toString() |
|
76 | - { |
|
77 | - return \sprintf( |
|
78 | - 'is instance of %s "%s"', |
|
79 | - $this->getType(), |
|
80 | - $this->className |
|
81 | - ); |
|
82 | - } |
|
70 | + /** |
|
71 | + * Returns a string representation of the constraint. |
|
72 | + * |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function toString() |
|
76 | + { |
|
77 | + return \sprintf( |
|
78 | + 'is instance of %s "%s"', |
|
79 | + $this->getType(), |
|
80 | + $this->className |
|
81 | + ); |
|
82 | + } |
|
83 | 83 | |
84 | - private function getType() |
|
85 | - { |
|
86 | - try { |
|
87 | - $reflection = new ReflectionClass($this->className); |
|
88 | - if ($reflection->isInterface()) { |
|
89 | - return 'interface'; |
|
90 | - } |
|
91 | - } catch (ReflectionException $e) { |
|
92 | - } |
|
84 | + private function getType() |
|
85 | + { |
|
86 | + try { |
|
87 | + $reflection = new ReflectionClass($this->className); |
|
88 | + if ($reflection->isInterface()) { |
|
89 | + return 'interface'; |
|
90 | + } |
|
91 | + } catch (ReflectionException $e) { |
|
92 | + } |
|
93 | 93 | |
94 | - return 'class'; |
|
95 | - } |
|
94 | + return 'class'; |
|
95 | + } |
|
96 | 96 | } |
@@ -16,102 +16,102 @@ |
||
16 | 16 | */ |
17 | 17 | class LogicalOr extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * @var Constraint[] |
|
21 | - */ |
|
22 | - protected $constraints = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * @param Constraint[] $constraints |
|
26 | - */ |
|
27 | - public function setConstraints(array $constraints) |
|
28 | - { |
|
29 | - $this->constraints = []; |
|
30 | - |
|
31 | - foreach ($constraints as $constraint) { |
|
32 | - if (!($constraint instanceof Constraint)) { |
|
33 | - $constraint = new IsEqual( |
|
34 | - $constraint |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - $this->constraints[] = $constraint; |
|
39 | - } |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Evaluates the constraint for parameter $other |
|
44 | - * |
|
45 | - * If $returnResult is set to false (the default), an exception is thrown |
|
46 | - * in case of a failure. null is returned otherwise. |
|
47 | - * |
|
48 | - * If $returnResult is true, the result of the evaluation is returned as |
|
49 | - * a boolean value instead: true in case of success, false in case of a |
|
50 | - * failure. |
|
51 | - * |
|
52 | - * @param mixed $other Value or object to evaluate. |
|
53 | - * @param string $description Additional information about the test |
|
54 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
55 | - * |
|
56 | - * @return mixed |
|
57 | - * |
|
58 | - * @throws ExpectationFailedException |
|
59 | - */ |
|
60 | - public function evaluate($other, $description = '', $returnResult = false) |
|
61 | - { |
|
62 | - $success = false; |
|
63 | - $constraint = null; |
|
64 | - |
|
65 | - foreach ($this->constraints as $constraint) { |
|
66 | - if ($constraint->evaluate($other, $description, true)) { |
|
67 | - $success = true; |
|
68 | - |
|
69 | - break; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if ($returnResult) { |
|
74 | - return $success; |
|
75 | - } |
|
76 | - |
|
77 | - if (!$success) { |
|
78 | - $this->fail($other, $description); |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns a string representation of the constraint. |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function toString() |
|
88 | - { |
|
89 | - $text = ''; |
|
90 | - |
|
91 | - foreach ($this->constraints as $key => $constraint) { |
|
92 | - if ($key > 0) { |
|
93 | - $text .= ' or '; |
|
94 | - } |
|
95 | - |
|
96 | - $text .= $constraint->toString(); |
|
97 | - } |
|
98 | - |
|
99 | - return $text; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Counts the number of constraint elements. |
|
104 | - * |
|
105 | - * @return int |
|
106 | - */ |
|
107 | - public function count() |
|
108 | - { |
|
109 | - $count = 0; |
|
110 | - |
|
111 | - foreach ($this->constraints as $constraint) { |
|
112 | - $count += \count($constraint); |
|
113 | - } |
|
114 | - |
|
115 | - return $count; |
|
116 | - } |
|
19 | + /** |
|
20 | + * @var Constraint[] |
|
21 | + */ |
|
22 | + protected $constraints = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * @param Constraint[] $constraints |
|
26 | + */ |
|
27 | + public function setConstraints(array $constraints) |
|
28 | + { |
|
29 | + $this->constraints = []; |
|
30 | + |
|
31 | + foreach ($constraints as $constraint) { |
|
32 | + if (!($constraint instanceof Constraint)) { |
|
33 | + $constraint = new IsEqual( |
|
34 | + $constraint |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + $this->constraints[] = $constraint; |
|
39 | + } |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Evaluates the constraint for parameter $other |
|
44 | + * |
|
45 | + * If $returnResult is set to false (the default), an exception is thrown |
|
46 | + * in case of a failure. null is returned otherwise. |
|
47 | + * |
|
48 | + * If $returnResult is true, the result of the evaluation is returned as |
|
49 | + * a boolean value instead: true in case of success, false in case of a |
|
50 | + * failure. |
|
51 | + * |
|
52 | + * @param mixed $other Value or object to evaluate. |
|
53 | + * @param string $description Additional information about the test |
|
54 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
55 | + * |
|
56 | + * @return mixed |
|
57 | + * |
|
58 | + * @throws ExpectationFailedException |
|
59 | + */ |
|
60 | + public function evaluate($other, $description = '', $returnResult = false) |
|
61 | + { |
|
62 | + $success = false; |
|
63 | + $constraint = null; |
|
64 | + |
|
65 | + foreach ($this->constraints as $constraint) { |
|
66 | + if ($constraint->evaluate($other, $description, true)) { |
|
67 | + $success = true; |
|
68 | + |
|
69 | + break; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if ($returnResult) { |
|
74 | + return $success; |
|
75 | + } |
|
76 | + |
|
77 | + if (!$success) { |
|
78 | + $this->fail($other, $description); |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns a string representation of the constraint. |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function toString() |
|
88 | + { |
|
89 | + $text = ''; |
|
90 | + |
|
91 | + foreach ($this->constraints as $key => $constraint) { |
|
92 | + if ($key > 0) { |
|
93 | + $text .= ' or '; |
|
94 | + } |
|
95 | + |
|
96 | + $text .= $constraint->toString(); |
|
97 | + } |
|
98 | + |
|
99 | + return $text; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Counts the number of constraint elements. |
|
104 | + * |
|
105 | + * @return int |
|
106 | + */ |
|
107 | + public function count() |
|
108 | + { |
|
109 | + $count = 0; |
|
110 | + |
|
111 | + foreach ($this->constraints as $constraint) { |
|
112 | + $count += \count($constraint); |
|
113 | + } |
|
114 | + |
|
115 | + return $count; |
|
116 | + } |
|
117 | 117 | } |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsNull 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 $other === null; |
|
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 $other === null; |
|
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 null'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is null'; |
|
38 | + } |
|
39 | 39 | } |