@@ -13,58 +13,58 @@ |
||
13 | 13 | |
14 | 14 | abstract class Composite extends Constraint |
15 | 15 | { |
16 | - /** |
|
17 | - * @var Constraint |
|
18 | - */ |
|
19 | - protected $innerConstraint; |
|
16 | + /** |
|
17 | + * @var Constraint |
|
18 | + */ |
|
19 | + protected $innerConstraint; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param Constraint $innerConstraint |
|
23 | - */ |
|
24 | - public function __construct(Constraint $innerConstraint) |
|
25 | - { |
|
26 | - parent::__construct(); |
|
27 | - $this->innerConstraint = $innerConstraint; |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param Constraint $innerConstraint |
|
23 | + */ |
|
24 | + public function __construct(Constraint $innerConstraint) |
|
25 | + { |
|
26 | + parent::__construct(); |
|
27 | + $this->innerConstraint = $innerConstraint; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Evaluates the constraint for parameter $other |
|
32 | - * |
|
33 | - * If $returnResult is set to false (the default), an exception is thrown |
|
34 | - * in case of a failure. null is returned otherwise. |
|
35 | - * |
|
36 | - * If $returnResult is true, the result of the evaluation is returned as |
|
37 | - * a boolean value instead: true in case of success, false in case of a |
|
38 | - * failure. |
|
39 | - * |
|
40 | - * @param mixed $other Value or object to evaluate. |
|
41 | - * @param string $description Additional information about the test |
|
42 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
43 | - * |
|
44 | - * @return mixed |
|
45 | - * |
|
46 | - * @throws ExpectationFailedException |
|
47 | - */ |
|
48 | - public function evaluate($other, $description = '', $returnResult = false) |
|
49 | - { |
|
50 | - try { |
|
51 | - return $this->innerConstraint->evaluate( |
|
52 | - $other, |
|
53 | - $description, |
|
54 | - $returnResult |
|
55 | - ); |
|
56 | - } catch (ExpectationFailedException $e) { |
|
57 | - $this->fail($other, $description, $e->getComparisonFailure()); |
|
58 | - } |
|
59 | - } |
|
30 | + /** |
|
31 | + * Evaluates the constraint for parameter $other |
|
32 | + * |
|
33 | + * If $returnResult is set to false (the default), an exception is thrown |
|
34 | + * in case of a failure. null is returned otherwise. |
|
35 | + * |
|
36 | + * If $returnResult is true, the result of the evaluation is returned as |
|
37 | + * a boolean value instead: true in case of success, false in case of a |
|
38 | + * failure. |
|
39 | + * |
|
40 | + * @param mixed $other Value or object to evaluate. |
|
41 | + * @param string $description Additional information about the test |
|
42 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
43 | + * |
|
44 | + * @return mixed |
|
45 | + * |
|
46 | + * @throws ExpectationFailedException |
|
47 | + */ |
|
48 | + public function evaluate($other, $description = '', $returnResult = false) |
|
49 | + { |
|
50 | + try { |
|
51 | + return $this->innerConstraint->evaluate( |
|
52 | + $other, |
|
53 | + $description, |
|
54 | + $returnResult |
|
55 | + ); |
|
56 | + } catch (ExpectationFailedException $e) { |
|
57 | + $this->fail($other, $description, $e->getComparisonFailure()); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Counts the number of constraint elements. |
|
63 | - * |
|
64 | - * @return int |
|
65 | - */ |
|
66 | - public function count() |
|
67 | - { |
|
68 | - return \count($this->innerConstraint); |
|
69 | - } |
|
61 | + /** |
|
62 | + * Counts the number of constraint elements. |
|
63 | + * |
|
64 | + * @return int |
|
65 | + */ |
|
66 | + public function count() |
|
67 | + { |
|
68 | + return \count($this->innerConstraint); |
|
69 | + } |
|
70 | 70 | } |
@@ -11,58 +11,58 @@ |
||
11 | 11 | |
12 | 12 | class ExceptionCode extends Constraint |
13 | 13 | { |
14 | - /** |
|
15 | - * @var int |
|
16 | - */ |
|
17 | - protected $expectedCode; |
|
14 | + /** |
|
15 | + * @var int |
|
16 | + */ |
|
17 | + protected $expectedCode; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param int $expected |
|
21 | - */ |
|
22 | - public function __construct($expected) |
|
23 | - { |
|
24 | - parent::__construct(); |
|
19 | + /** |
|
20 | + * @param int $expected |
|
21 | + */ |
|
22 | + public function __construct($expected) |
|
23 | + { |
|
24 | + parent::__construct(); |
|
25 | 25 | |
26 | - $this->expectedCode = $expected; |
|
27 | - } |
|
26 | + $this->expectedCode = $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 | - return (string) $other->getCode() == (string) $this->expectedCode; |
|
40 | - } |
|
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 | + return (string) $other->getCode() == (string) $this->expectedCode; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns the description of the failure |
|
44 | - * |
|
45 | - * The beginning of failure messages is "Failed asserting that" in most |
|
46 | - * cases. This method should return the second part of that sentence. |
|
47 | - * |
|
48 | - * @param mixed $other Evaluated value or object. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - protected function failureDescription($other) |
|
53 | - { |
|
54 | - return \sprintf( |
|
55 | - '%s is equal to expected exception code %s', |
|
56 | - $this->exporter->export($other->getCode()), |
|
57 | - $this->exporter->export($this->expectedCode) |
|
58 | - ); |
|
59 | - } |
|
42 | + /** |
|
43 | + * Returns the description of the failure |
|
44 | + * |
|
45 | + * The beginning of failure messages is "Failed asserting that" in most |
|
46 | + * cases. This method should return the second part of that sentence. |
|
47 | + * |
|
48 | + * @param mixed $other Evaluated value or object. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + protected function failureDescription($other) |
|
53 | + { |
|
54 | + return \sprintf( |
|
55 | + '%s is equal to expected exception code %s', |
|
56 | + $this->exporter->export($other->getCode()), |
|
57 | + $this->exporter->export($this->expectedCode) |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function toString() |
|
65 | - { |
|
66 | - return 'exception code is '; |
|
67 | - } |
|
61 | + /** |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function toString() |
|
65 | + { |
|
66 | + return 'exception code is '; |
|
67 | + } |
|
68 | 68 | } |
@@ -16,44 +16,44 @@ |
||
16 | 16 | */ |
17 | 17 | class DirectoryExists 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_dir($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_dir($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 | - 'directory "%s" exists', |
|
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 | + 'directory "%s" exists', |
|
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 'directory exists'; |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns a string representation of the constraint. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function toString() |
|
56 | + { |
|
57 | + return 'directory exists'; |
|
58 | + } |
|
59 | 59 | } |
@@ -14,26 +14,26 @@ |
||
14 | 14 | */ |
15 | 15 | class IsNan 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_nan($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_nan($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 nan'; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Returns a string representation of the constraint. |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function toString() |
|
36 | + { |
|
37 | + return 'is nan'; |
|
38 | + } |
|
39 | 39 | } |
@@ -19,18 +19,18 @@ |
||
19 | 19 | */ |
20 | 20 | class ObjectHasAttribute 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 | - $object = new ReflectionObject($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 | + $object = new ReflectionObject($other); |
|
33 | 33 | |
34 | - return $object->hasProperty($this->attributeName); |
|
35 | - } |
|
34 | + return $object->hasProperty($this->attributeName); |
|
35 | + } |
|
36 | 36 | } |
@@ -20,65 +20,65 @@ |
||
20 | 20 | */ |
21 | 21 | class StringContains extends Constraint |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $string; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $string; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var bool |
|
30 | - */ |
|
31 | - protected $ignoreCase; |
|
28 | + /** |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | + protected $ignoreCase; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param string $string |
|
35 | - * @param bool $ignoreCase |
|
36 | - */ |
|
37 | - public function __construct($string, $ignoreCase = false) |
|
38 | - { |
|
39 | - parent::__construct(); |
|
33 | + /** |
|
34 | + * @param string $string |
|
35 | + * @param bool $ignoreCase |
|
36 | + */ |
|
37 | + public function __construct($string, $ignoreCase = false) |
|
38 | + { |
|
39 | + parent::__construct(); |
|
40 | 40 | |
41 | - $this->string = $string; |
|
42 | - $this->ignoreCase = $ignoreCase; |
|
43 | - } |
|
41 | + $this->string = $string; |
|
42 | + $this->ignoreCase = $ignoreCase; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
47 | - * constraint is met, false otherwise. |
|
48 | - * |
|
49 | - * @param mixed $other Value or object to evaluate. |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - protected function matches($other) |
|
54 | - { |
|
55 | - if ('' === $this->string) { |
|
56 | - return true; |
|
57 | - } |
|
45 | + /** |
|
46 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
47 | + * constraint is met, false otherwise. |
|
48 | + * |
|
49 | + * @param mixed $other Value or object to evaluate. |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + protected function matches($other) |
|
54 | + { |
|
55 | + if ('' === $this->string) { |
|
56 | + return true; |
|
57 | + } |
|
58 | 58 | |
59 | - if ($this->ignoreCase) { |
|
60 | - return \mb_stripos($other, $this->string) !== false; |
|
61 | - } |
|
59 | + if ($this->ignoreCase) { |
|
60 | + return \mb_stripos($other, $this->string) !== false; |
|
61 | + } |
|
62 | 62 | |
63 | - return \mb_strpos($other, $this->string) !== false; |
|
64 | - } |
|
63 | + return \mb_strpos($other, $this->string) !== false; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Returns a string representation of the constraint. |
|
68 | - * |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function toString() |
|
72 | - { |
|
73 | - if ($this->ignoreCase) { |
|
74 | - $string = \mb_strtolower($this->string); |
|
75 | - } else { |
|
76 | - $string = $this->string; |
|
77 | - } |
|
66 | + /** |
|
67 | + * Returns a string representation of the constraint. |
|
68 | + * |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function toString() |
|
72 | + { |
|
73 | + if ($this->ignoreCase) { |
|
74 | + $string = \mb_strtolower($this->string); |
|
75 | + } else { |
|
76 | + $string = $this->string; |
|
77 | + } |
|
78 | 78 | |
79 | - return \sprintf( |
|
80 | - 'contains "%s"', |
|
81 | - $string |
|
82 | - ); |
|
83 | - } |
|
79 | + return \sprintf( |
|
80 | + 'contains "%s"', |
|
81 | + $string |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -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 | } |
@@ -124,10 +124,10 @@ |
||
124 | 124 | public function toString() |
125 | 125 | { |
126 | 126 | if (\is_object($this->value)) { |
127 | - return 'is identical to an object of class "' . |
|
128 | - \get_class($this->value) . '"'; |
|
127 | + return 'is identical to an object of class "'. |
|
128 | + \get_class($this->value).'"'; |
|
129 | 129 | } |
130 | 130 | |
131 | - return 'is identical to ' . $this->exporter->export($this->value); |
|
131 | + return 'is identical to '.$this->exporter->export($this->value); |
|
132 | 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 | } |