@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsTrue 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 === true; |
|
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 === true; |
|
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 true'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is true'; |
|
38 | + } |
|
39 | 39 | } |
@@ -16,46 +16,46 @@ |
||
16 | 16 | */ |
17 | 17 | class IsAnything extends Constraint |
18 | 18 | { |
19 | - /** |
|
20 | - * Evaluates the constraint for parameter $other |
|
21 | - * |
|
22 | - * If $returnResult is set to false (the default), an exception is thrown |
|
23 | - * in case of a failure. null is returned otherwise. |
|
24 | - * |
|
25 | - * If $returnResult is true, the result of the evaluation is returned as |
|
26 | - * a boolean value instead: true in case of success, false in case of a |
|
27 | - * failure. |
|
28 | - * |
|
29 | - * @param mixed $other Value or object to evaluate. |
|
30 | - * @param string $description Additional information about the test |
|
31 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - * |
|
35 | - * @throws ExpectationFailedException |
|
36 | - */ |
|
37 | - public function evaluate($other, $description = '', $returnResult = false) |
|
38 | - { |
|
39 | - return $returnResult ? true : null; |
|
40 | - } |
|
19 | + /** |
|
20 | + * Evaluates the constraint for parameter $other |
|
21 | + * |
|
22 | + * If $returnResult is set to false (the default), an exception is thrown |
|
23 | + * in case of a failure. null is returned otherwise. |
|
24 | + * |
|
25 | + * If $returnResult is true, the result of the evaluation is returned as |
|
26 | + * a boolean value instead: true in case of success, false in case of a |
|
27 | + * failure. |
|
28 | + * |
|
29 | + * @param mixed $other Value or object to evaluate. |
|
30 | + * @param string $description Additional information about the test |
|
31 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + * |
|
35 | + * @throws ExpectationFailedException |
|
36 | + */ |
|
37 | + public function evaluate($other, $description = '', $returnResult = false) |
|
38 | + { |
|
39 | + return $returnResult ? true : null; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns a string representation of the constraint. |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function toString() |
|
48 | - { |
|
49 | - return 'is anything'; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Returns a string representation of the constraint. |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function toString() |
|
48 | + { |
|
49 | + return 'is anything'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Counts the number of constraint elements. |
|
54 | - * |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function count() |
|
58 | - { |
|
59 | - return 0; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Counts the number of constraint elements. |
|
54 | + * |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function count() |
|
58 | + { |
|
59 | + return 0; |
|
60 | + } |
|
61 | 61 | } |
@@ -11,16 +11,16 @@ |
||
11 | 11 | |
12 | 12 | class SameSize extends Count |
13 | 13 | { |
14 | - /** |
|
15 | - * @var int |
|
16 | - */ |
|
17 | - protected $expectedCount; |
|
14 | + /** |
|
15 | + * @var int |
|
16 | + */ |
|
17 | + protected $expectedCount; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param \Countable|\Traversable|array $expected |
|
21 | - */ |
|
22 | - public function __construct($expected) |
|
23 | - { |
|
24 | - parent::__construct($this->getCountOf($expected)); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @param \Countable|\Traversable|array $expected |
|
21 | + */ |
|
22 | + public function __construct($expected) |
|
23 | + { |
|
24 | + parent::__construct($this->getCountOf($expected)); |
|
25 | + } |
|
26 | 26 | } |
@@ -14,63 +14,63 @@ |
||
14 | 14 | */ |
15 | 15 | class IsJson 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 | - if ($other === '') { |
|
28 | - return false; |
|
29 | - } |
|
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 | + if ($other === '') { |
|
28 | + return false; |
|
29 | + } |
|
30 | 30 | |
31 | - \json_decode($other); |
|
32 | - if (\json_last_error()) { |
|
33 | - return false; |
|
34 | - } |
|
31 | + \json_decode($other); |
|
32 | + if (\json_last_error()) { |
|
33 | + return false; |
|
34 | + } |
|
35 | 35 | |
36 | - return true; |
|
37 | - } |
|
36 | + return true; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns the description of the failure |
|
41 | - * |
|
42 | - * The beginning of failure messages is "Failed asserting that" in most |
|
43 | - * cases. This method should return the second part of that sentence. |
|
44 | - * |
|
45 | - * @param mixed $other Evaluated value or object. |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - protected function failureDescription($other) |
|
50 | - { |
|
51 | - if ($other === '') { |
|
52 | - return 'an empty string is valid JSON'; |
|
53 | - } |
|
39 | + /** |
|
40 | + * Returns the description of the failure |
|
41 | + * |
|
42 | + * The beginning of failure messages is "Failed asserting that" in most |
|
43 | + * cases. This method should return the second part of that sentence. |
|
44 | + * |
|
45 | + * @param mixed $other Evaluated value or object. |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + protected function failureDescription($other) |
|
50 | + { |
|
51 | + if ($other === '') { |
|
52 | + return 'an empty string is valid JSON'; |
|
53 | + } |
|
54 | 54 | |
55 | - \json_decode($other); |
|
56 | - $error = JsonMatchesErrorMessageProvider::determineJsonError( |
|
57 | - \json_last_error() |
|
58 | - ); |
|
55 | + \json_decode($other); |
|
56 | + $error = JsonMatchesErrorMessageProvider::determineJsonError( |
|
57 | + \json_last_error() |
|
58 | + ); |
|
59 | 59 | |
60 | - return \sprintf( |
|
61 | - '%s is valid JSON (%s)', |
|
62 | - $this->exporter->shortenedExport($other), |
|
63 | - $error |
|
64 | - ); |
|
65 | - } |
|
60 | + return \sprintf( |
|
61 | + '%s is valid JSON (%s)', |
|
62 | + $this->exporter->shortenedExport($other), |
|
63 | + $error |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns a string representation of the constraint. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function toString() |
|
73 | - { |
|
74 | - return 'is valid JSON'; |
|
75 | - } |
|
67 | + /** |
|
68 | + * Returns a string representation of the constraint. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function toString() |
|
73 | + { |
|
74 | + return 'is valid JSON'; |
|
75 | + } |
|
76 | 76 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |