@@ -16,52 +16,52 @@ |
||
16 | 16 | */ |
17 | 17 | class IsEmpty 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 | - if ($other instanceof Countable) { |
|
30 | - return \count($other) === 0; |
|
31 | - } |
|
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 | + if ($other instanceof Countable) { |
|
30 | + return \count($other) === 0; |
|
31 | + } |
|
32 | 32 | |
33 | - return empty($other); |
|
34 | - } |
|
33 | + return empty($other); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Returns a string representation of the constraint. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function toString() |
|
42 | - { |
|
43 | - return 'is empty'; |
|
44 | - } |
|
36 | + /** |
|
37 | + * Returns a string representation of the constraint. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function toString() |
|
42 | + { |
|
43 | + return 'is empty'; |
|
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 | - $type = \gettype($other); |
|
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 | + $type = \gettype($other); |
|
59 | 59 | |
60 | - return \sprintf( |
|
61 | - '%s %s %s', |
|
62 | - $type[0] == 'a' || $type[0] == 'o' ? 'an' : 'a', |
|
63 | - $type, |
|
64 | - $this->toString() |
|
65 | - ); |
|
66 | - } |
|
60 | + return \sprintf( |
|
61 | + '%s %s %s', |
|
62 | + $type[0] == 'a' || $type[0] == 'o' ? 'an' : 'a', |
|
63 | + $type, |
|
64 | + $this->toString() |
|
65 | + ); |
|
66 | + } |
|
67 | 67 | } |
@@ -16,44 +16,44 @@ |
||
16 | 16 | */ |
17 | 17 | class FileExists 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 \file_exists($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 \file_exists($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 | - 'file "%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 | + 'file "%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 'file exists'; |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns a string representation of the constraint. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function toString() |
|
56 | + { |
|
57 | + return 'file exists'; |
|
58 | + } |
|
59 | 59 | } |
@@ -20,122 +20,122 @@ |
||
20 | 20 | */ |
21 | 21 | class ArraySubset extends Constraint |
22 | 22 | { |
23 | - /** |
|
24 | - * @var array|\Traversable |
|
25 | - */ |
|
26 | - protected $subset; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var bool |
|
30 | - */ |
|
31 | - protected $strict; |
|
32 | - |
|
33 | - /** |
|
34 | - * @param array|\Traversable $subset |
|
35 | - * @param bool $strict Check for object identity |
|
36 | - */ |
|
37 | - public function __construct($subset, $strict = false) |
|
38 | - { |
|
39 | - parent::__construct(); |
|
40 | - |
|
41 | - $this->strict = $strict; |
|
42 | - $this->subset = $subset; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Evaluates the constraint for parameter $other |
|
47 | - * |
|
48 | - * If $returnResult is set to false (the default), an exception is thrown |
|
49 | - * in case of a failure. null is returned otherwise. |
|
50 | - * |
|
51 | - * If $returnResult is true, the result of the evaluation is returned as |
|
52 | - * a boolean value instead: true in case of success, false in case of a |
|
53 | - * failure. |
|
54 | - * |
|
55 | - * @param mixed $other Value or object to evaluate. |
|
56 | - * @param string $description Additional information about the test |
|
57 | - * @param bool $returnResult Whether to return a result or throw an exception |
|
58 | - * |
|
59 | - * @return mixed |
|
60 | - * |
|
61 | - * @throws ExpectationFailedException |
|
62 | - */ |
|
63 | - public function evaluate($other, $description = '', $returnResult = false) |
|
64 | - { |
|
65 | - //type cast $other & $this->subset as an array to allow |
|
66 | - //support in standard array functions. |
|
67 | - $other = $this->toArray($other); |
|
68 | - $this->subset = $this->toArray($this->subset); |
|
69 | - |
|
70 | - $patched = \array_replace_recursive($other, $this->subset); |
|
71 | - |
|
72 | - if ($this->strict) { |
|
73 | - $result = $other === $patched; |
|
74 | - } else { |
|
75 | - $result = $other == $patched; |
|
76 | - } |
|
77 | - |
|
78 | - if ($returnResult) { |
|
79 | - return $result; |
|
80 | - } |
|
81 | - |
|
82 | - if (!$result) { |
|
83 | - $f = new ComparisonFailure( |
|
84 | - $patched, |
|
85 | - $other, |
|
86 | - \print_r($patched, true), |
|
87 | - \print_r($other, true) |
|
88 | - ); |
|
89 | - |
|
90 | - $this->fail($other, $description, $f); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Returns a string representation of the constraint. |
|
96 | - * |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function toString() |
|
100 | - { |
|
101 | - return 'has the subset ' . $this->exporter->export($this->subset); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns the description of the failure |
|
106 | - * |
|
107 | - * The beginning of failure messages is "Failed asserting that" in most |
|
108 | - * cases. This method should return the second part of that sentence. |
|
109 | - * |
|
110 | - * @param mixed $other Evaluated value or object. |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - protected function failureDescription($other) |
|
115 | - { |
|
116 | - return 'an array ' . $this->toString(); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param array|\Traversable $other |
|
121 | - * |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - private function toArray($other) |
|
125 | - { |
|
126 | - if (\is_array($other)) { |
|
127 | - return $other; |
|
128 | - } |
|
129 | - |
|
130 | - if ($other instanceof \ArrayObject) { |
|
131 | - return $other->getArrayCopy(); |
|
132 | - } |
|
133 | - |
|
134 | - if ($other instanceof \Traversable) { |
|
135 | - return \iterator_to_array($other); |
|
136 | - } |
|
137 | - |
|
138 | - // Keep BC even if we know that array would not be the expected one |
|
139 | - return (array) $other; |
|
140 | - } |
|
23 | + /** |
|
24 | + * @var array|\Traversable |
|
25 | + */ |
|
26 | + protected $subset; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | + protected $strict; |
|
32 | + |
|
33 | + /** |
|
34 | + * @param array|\Traversable $subset |
|
35 | + * @param bool $strict Check for object identity |
|
36 | + */ |
|
37 | + public function __construct($subset, $strict = false) |
|
38 | + { |
|
39 | + parent::__construct(); |
|
40 | + |
|
41 | + $this->strict = $strict; |
|
42 | + $this->subset = $subset; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Evaluates the constraint for parameter $other |
|
47 | + * |
|
48 | + * If $returnResult is set to false (the default), an exception is thrown |
|
49 | + * in case of a failure. null is returned otherwise. |
|
50 | + * |
|
51 | + * If $returnResult is true, the result of the evaluation is returned as |
|
52 | + * a boolean value instead: true in case of success, false in case of a |
|
53 | + * failure. |
|
54 | + * |
|
55 | + * @param mixed $other Value or object to evaluate. |
|
56 | + * @param string $description Additional information about the test |
|
57 | + * @param bool $returnResult Whether to return a result or throw an exception |
|
58 | + * |
|
59 | + * @return mixed |
|
60 | + * |
|
61 | + * @throws ExpectationFailedException |
|
62 | + */ |
|
63 | + public function evaluate($other, $description = '', $returnResult = false) |
|
64 | + { |
|
65 | + //type cast $other & $this->subset as an array to allow |
|
66 | + //support in standard array functions. |
|
67 | + $other = $this->toArray($other); |
|
68 | + $this->subset = $this->toArray($this->subset); |
|
69 | + |
|
70 | + $patched = \array_replace_recursive($other, $this->subset); |
|
71 | + |
|
72 | + if ($this->strict) { |
|
73 | + $result = $other === $patched; |
|
74 | + } else { |
|
75 | + $result = $other == $patched; |
|
76 | + } |
|
77 | + |
|
78 | + if ($returnResult) { |
|
79 | + return $result; |
|
80 | + } |
|
81 | + |
|
82 | + if (!$result) { |
|
83 | + $f = new ComparisonFailure( |
|
84 | + $patched, |
|
85 | + $other, |
|
86 | + \print_r($patched, true), |
|
87 | + \print_r($other, true) |
|
88 | + ); |
|
89 | + |
|
90 | + $this->fail($other, $description, $f); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Returns a string representation of the constraint. |
|
96 | + * |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function toString() |
|
100 | + { |
|
101 | + return 'has the subset ' . $this->exporter->export($this->subset); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns the description of the failure |
|
106 | + * |
|
107 | + * The beginning of failure messages is "Failed asserting that" in most |
|
108 | + * cases. This method should return the second part of that sentence. |
|
109 | + * |
|
110 | + * @param mixed $other Evaluated value or object. |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + protected function failureDescription($other) |
|
115 | + { |
|
116 | + return 'an array ' . $this->toString(); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param array|\Traversable $other |
|
121 | + * |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + private function toArray($other) |
|
125 | + { |
|
126 | + if (\is_array($other)) { |
|
127 | + return $other; |
|
128 | + } |
|
129 | + |
|
130 | + if ($other instanceof \ArrayObject) { |
|
131 | + return $other->getArrayCopy(); |
|
132 | + } |
|
133 | + |
|
134 | + if ($other instanceof \Traversable) { |
|
135 | + return \iterator_to_array($other); |
|
136 | + } |
|
137 | + |
|
138 | + // Keep BC even if we know that array would not be the expected one |
|
139 | + return (array) $other; |
|
140 | + } |
|
141 | 141 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function toString() |
100 | 100 | { |
101 | - return 'has the subset ' . $this->exporter->export($this->subset); |
|
101 | + return 'has the subset '.$this->exporter->export($this->subset); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function failureDescription($other) |
115 | 115 | { |
116 | - return 'an array ' . $this->toString(); |
|
116 | + return 'an array '.$this->toString(); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -17,126 +17,126 @@ |
||
17 | 17 | */ |
18 | 18 | class IsType extends Constraint |
19 | 19 | { |
20 | - const TYPE_ARRAY = 'array'; |
|
21 | - const TYPE_BOOL = 'bool'; |
|
22 | - const TYPE_FLOAT = 'float'; |
|
23 | - const TYPE_INT = 'int'; |
|
24 | - const TYPE_NULL = 'null'; |
|
25 | - const TYPE_NUMERIC = 'numeric'; |
|
26 | - const TYPE_OBJECT = 'object'; |
|
27 | - const TYPE_RESOURCE = 'resource'; |
|
28 | - const TYPE_STRING = 'string'; |
|
29 | - const TYPE_SCALAR = 'scalar'; |
|
30 | - const TYPE_CALLABLE = 'callable'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $types = [ |
|
36 | - 'array' => true, |
|
37 | - 'boolean' => true, |
|
38 | - 'bool' => true, |
|
39 | - 'double' => true, |
|
40 | - 'float' => true, |
|
41 | - 'integer' => true, |
|
42 | - 'int' => true, |
|
43 | - 'null' => true, |
|
44 | - 'numeric' => true, |
|
45 | - 'object' => true, |
|
46 | - 'real' => true, |
|
47 | - 'resource' => true, |
|
48 | - 'string' => true, |
|
49 | - 'scalar' => true, |
|
50 | - 'callable' => true |
|
51 | - ]; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $type; |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $type |
|
60 | - * |
|
61 | - * @throws \PHPUnit\Framework\Exception |
|
62 | - */ |
|
63 | - public function __construct($type) |
|
64 | - { |
|
65 | - parent::__construct(); |
|
66 | - |
|
67 | - if (!isset($this->types[$type])) { |
|
68 | - throw new \PHPUnit\Framework\Exception( |
|
69 | - \sprintf( |
|
70 | - 'Type specified for PHPUnit\Framework\Constraint\IsType <%s> ' . |
|
71 | - 'is not a valid type.', |
|
72 | - $type |
|
73 | - ) |
|
74 | - ); |
|
75 | - } |
|
76 | - |
|
77 | - $this->type = $type; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
82 | - * constraint is met, false otherwise. |
|
83 | - * |
|
84 | - * @param mixed $other Value or object to evaluate. |
|
85 | - * |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - protected function matches($other) |
|
89 | - { |
|
90 | - switch ($this->type) { |
|
91 | - case 'numeric': |
|
92 | - return \is_numeric($other); |
|
93 | - |
|
94 | - case 'integer': |
|
95 | - case 'int': |
|
96 | - return \is_int($other); |
|
97 | - |
|
98 | - case 'double': |
|
99 | - case 'float': |
|
100 | - case 'real': |
|
101 | - return \is_float($other); |
|
102 | - |
|
103 | - case 'string': |
|
104 | - return \is_string($other); |
|
105 | - |
|
106 | - case 'boolean': |
|
107 | - case 'bool': |
|
108 | - return \is_bool($other); |
|
109 | - |
|
110 | - case 'null': |
|
111 | - return null === $other; |
|
112 | - |
|
113 | - case 'array': |
|
114 | - return \is_array($other); |
|
115 | - |
|
116 | - case 'object': |
|
117 | - return \is_object($other); |
|
118 | - |
|
119 | - case 'resource': |
|
120 | - return \is_resource($other) || \is_string(@\get_resource_type($other)); |
|
121 | - |
|
122 | - case 'scalar': |
|
123 | - return \is_scalar($other); |
|
124 | - |
|
125 | - case 'callable': |
|
126 | - return \is_callable($other); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Returns a string representation of the constraint. |
|
132 | - * |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function toString() |
|
136 | - { |
|
137 | - return \sprintf( |
|
138 | - 'is of type "%s"', |
|
139 | - $this->type |
|
140 | - ); |
|
141 | - } |
|
20 | + const TYPE_ARRAY = 'array'; |
|
21 | + const TYPE_BOOL = 'bool'; |
|
22 | + const TYPE_FLOAT = 'float'; |
|
23 | + const TYPE_INT = 'int'; |
|
24 | + const TYPE_NULL = 'null'; |
|
25 | + const TYPE_NUMERIC = 'numeric'; |
|
26 | + const TYPE_OBJECT = 'object'; |
|
27 | + const TYPE_RESOURCE = 'resource'; |
|
28 | + const TYPE_STRING = 'string'; |
|
29 | + const TYPE_SCALAR = 'scalar'; |
|
30 | + const TYPE_CALLABLE = 'callable'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $types = [ |
|
36 | + 'array' => true, |
|
37 | + 'boolean' => true, |
|
38 | + 'bool' => true, |
|
39 | + 'double' => true, |
|
40 | + 'float' => true, |
|
41 | + 'integer' => true, |
|
42 | + 'int' => true, |
|
43 | + 'null' => true, |
|
44 | + 'numeric' => true, |
|
45 | + 'object' => true, |
|
46 | + 'real' => true, |
|
47 | + 'resource' => true, |
|
48 | + 'string' => true, |
|
49 | + 'scalar' => true, |
|
50 | + 'callable' => true |
|
51 | + ]; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $type; |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $type |
|
60 | + * |
|
61 | + * @throws \PHPUnit\Framework\Exception |
|
62 | + */ |
|
63 | + public function __construct($type) |
|
64 | + { |
|
65 | + parent::__construct(); |
|
66 | + |
|
67 | + if (!isset($this->types[$type])) { |
|
68 | + throw new \PHPUnit\Framework\Exception( |
|
69 | + \sprintf( |
|
70 | + 'Type specified for PHPUnit\Framework\Constraint\IsType <%s> ' . |
|
71 | + 'is not a valid type.', |
|
72 | + $type |
|
73 | + ) |
|
74 | + ); |
|
75 | + } |
|
76 | + |
|
77 | + $this->type = $type; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
82 | + * constraint is met, false otherwise. |
|
83 | + * |
|
84 | + * @param mixed $other Value or object to evaluate. |
|
85 | + * |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + protected function matches($other) |
|
89 | + { |
|
90 | + switch ($this->type) { |
|
91 | + case 'numeric': |
|
92 | + return \is_numeric($other); |
|
93 | + |
|
94 | + case 'integer': |
|
95 | + case 'int': |
|
96 | + return \is_int($other); |
|
97 | + |
|
98 | + case 'double': |
|
99 | + case 'float': |
|
100 | + case 'real': |
|
101 | + return \is_float($other); |
|
102 | + |
|
103 | + case 'string': |
|
104 | + return \is_string($other); |
|
105 | + |
|
106 | + case 'boolean': |
|
107 | + case 'bool': |
|
108 | + return \is_bool($other); |
|
109 | + |
|
110 | + case 'null': |
|
111 | + return null === $other; |
|
112 | + |
|
113 | + case 'array': |
|
114 | + return \is_array($other); |
|
115 | + |
|
116 | + case 'object': |
|
117 | + return \is_object($other); |
|
118 | + |
|
119 | + case 'resource': |
|
120 | + return \is_resource($other) || \is_string(@\get_resource_type($other)); |
|
121 | + |
|
122 | + case 'scalar': |
|
123 | + return \is_scalar($other); |
|
124 | + |
|
125 | + case 'callable': |
|
126 | + return \is_callable($other); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Returns a string representation of the constraint. |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function toString() |
|
136 | + { |
|
137 | + return \sprintf( |
|
138 | + 'is of type "%s"', |
|
139 | + $this->type |
|
140 | + ); |
|
141 | + } |
|
142 | 142 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | if (!isset($this->types[$type])) { |
68 | 68 | throw new \PHPUnit\Framework\Exception( |
69 | 69 | \sprintf( |
70 | - 'Type specified for PHPUnit\Framework\Constraint\IsType <%s> ' . |
|
70 | + 'Type specified for PHPUnit\Framework\Constraint\IsType <%s> '. |
|
71 | 71 | 'is not a valid type.', |
72 | 72 | $type |
73 | 73 | ) |
@@ -21,63 +21,63 @@ |
||
21 | 21 | */ |
22 | 22 | class ArrayHasKey extends Constraint |
23 | 23 | { |
24 | - /** |
|
25 | - * @var int|string |
|
26 | - */ |
|
27 | - protected $key; |
|
24 | + /** |
|
25 | + * @var int|string |
|
26 | + */ |
|
27 | + protected $key; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param int|string $key |
|
31 | - */ |
|
32 | - public function __construct($key) |
|
33 | - { |
|
34 | - parent::__construct(); |
|
35 | - $this->key = $key; |
|
36 | - } |
|
29 | + /** |
|
30 | + * @param int|string $key |
|
31 | + */ |
|
32 | + public function __construct($key) |
|
33 | + { |
|
34 | + parent::__construct(); |
|
35 | + $this->key = $key; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
40 | - * constraint is met, false otherwise. |
|
41 | - * |
|
42 | - * @param mixed $other Value or object to evaluate. |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - protected function matches($other) |
|
47 | - { |
|
48 | - if (\is_array($other)) { |
|
49 | - return \array_key_exists($this->key, $other); |
|
50 | - } |
|
38 | + /** |
|
39 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
40 | + * constraint is met, false otherwise. |
|
41 | + * |
|
42 | + * @param mixed $other Value or object to evaluate. |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + protected function matches($other) |
|
47 | + { |
|
48 | + if (\is_array($other)) { |
|
49 | + return \array_key_exists($this->key, $other); |
|
50 | + } |
|
51 | 51 | |
52 | - if ($other instanceof ArrayAccess) { |
|
53 | - return $other->offsetExists($this->key); |
|
54 | - } |
|
52 | + if ($other instanceof ArrayAccess) { |
|
53 | + return $other->offsetExists($this->key); |
|
54 | + } |
|
55 | 55 | |
56 | - return false; |
|
57 | - } |
|
56 | + return false; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Returns a string representation of the constraint. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function toString() |
|
65 | - { |
|
66 | - return 'has the key ' . $this->exporter->export($this->key); |
|
67 | - } |
|
59 | + /** |
|
60 | + * Returns a string representation of the constraint. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function toString() |
|
65 | + { |
|
66 | + return 'has the key ' . $this->exporter->export($this->key); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns the description of the failure |
|
71 | - * |
|
72 | - * The beginning of failure messages is "Failed asserting that" in most |
|
73 | - * cases. This method should return the second part of that sentence. |
|
74 | - * |
|
75 | - * @param mixed $other Evaluated value or object. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - protected function failureDescription($other) |
|
80 | - { |
|
81 | - return 'an array ' . $this->toString(); |
|
82 | - } |
|
69 | + /** |
|
70 | + * Returns the description of the failure |
|
71 | + * |
|
72 | + * The beginning of failure messages is "Failed asserting that" in most |
|
73 | + * cases. This method should return the second part of that sentence. |
|
74 | + * |
|
75 | + * @param mixed $other Evaluated value or object. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + protected function failureDescription($other) |
|
80 | + { |
|
81 | + return 'an array ' . $this->toString(); |
|
82 | + } |
|
83 | 83 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function toString() |
65 | 65 | { |
66 | - return 'has the key ' . $this->exporter->export($this->key); |
|
66 | + return 'has the key '.$this->exporter->export($this->key); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,6 +78,6 @@ discard block |
||
78 | 78 | */ |
79 | 79 | protected function failureDescription($other) |
80 | 80 | { |
81 | - return 'an array ' . $this->toString(); |
|
81 | + return 'an array '.$this->toString(); |
|
82 | 82 | } |
83 | 83 | } |
@@ -13,65 +13,65 @@ |
||
13 | 13 | |
14 | 14 | class ExceptionMessageRegularExpression extends Constraint |
15 | 15 | { |
16 | - /** |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $expectedMessageRegExp; |
|
16 | + /** |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $expectedMessageRegExp; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $expected |
|
23 | - */ |
|
24 | - public function __construct($expected) |
|
25 | - { |
|
26 | - parent::__construct(); |
|
27 | - $this->expectedMessageRegExp = $expected; |
|
28 | - } |
|
21 | + /** |
|
22 | + * @param string $expected |
|
23 | + */ |
|
24 | + public function __construct($expected) |
|
25 | + { |
|
26 | + parent::__construct(); |
|
27 | + $this->expectedMessageRegExp = $expected; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Evaluates the constraint for parameter $other. Returns true if the |
|
32 | - * constraint is met, false otherwise. |
|
33 | - * |
|
34 | - * @param \PHPUnit\Framework\Exception $other |
|
35 | - * |
|
36 | - * @return bool |
|
37 | - */ |
|
38 | - protected function matches($other) |
|
39 | - { |
|
40 | - $match = RegularExpressionUtil::safeMatch($this->expectedMessageRegExp, $other->getMessage()); |
|
30 | + /** |
|
31 | + * Evaluates the constraint for parameter $other. Returns true if the |
|
32 | + * constraint is met, false otherwise. |
|
33 | + * |
|
34 | + * @param \PHPUnit\Framework\Exception $other |
|
35 | + * |
|
36 | + * @return bool |
|
37 | + */ |
|
38 | + protected function matches($other) |
|
39 | + { |
|
40 | + $match = RegularExpressionUtil::safeMatch($this->expectedMessageRegExp, $other->getMessage()); |
|
41 | 41 | |
42 | - if (false === $match) { |
|
43 | - throw new \PHPUnit\Framework\Exception( |
|
44 | - "Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'" |
|
45 | - ); |
|
46 | - } |
|
42 | + if (false === $match) { |
|
43 | + throw new \PHPUnit\Framework\Exception( |
|
44 | + "Invalid expected exception message regex given: '{$this->expectedMessageRegExp}'" |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - return 1 === $match; |
|
49 | - } |
|
48 | + return 1 === $match; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the description of the failure |
|
53 | - * |
|
54 | - * The beginning of failure messages is "Failed asserting that" in most |
|
55 | - * cases. This method should return the second part of that sentence. |
|
56 | - * |
|
57 | - * @param mixed $other Evaluated value or object. |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - protected function failureDescription($other) |
|
62 | - { |
|
63 | - return \sprintf( |
|
64 | - "exception message '%s' matches '%s'", |
|
65 | - $other->getMessage(), |
|
66 | - $this->expectedMessageRegExp |
|
67 | - ); |
|
68 | - } |
|
51 | + /** |
|
52 | + * Returns the description of the failure |
|
53 | + * |
|
54 | + * The beginning of failure messages is "Failed asserting that" in most |
|
55 | + * cases. This method should return the second part of that sentence. |
|
56 | + * |
|
57 | + * @param mixed $other Evaluated value or object. |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + protected function failureDescription($other) |
|
62 | + { |
|
63 | + return \sprintf( |
|
64 | + "exception message '%s' matches '%s'", |
|
65 | + $other->getMessage(), |
|
66 | + $this->expectedMessageRegExp |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function toString() |
|
74 | - { |
|
75 | - return 'exception message matches '; |
|
76 | - } |
|
70 | + /** |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function toString() |
|
74 | + { |
|
75 | + return 'exception message matches '; |
|
76 | + } |
|
77 | 77 | } |
@@ -17,85 +17,85 @@ |
||
17 | 17 | */ |
18 | 18 | class StringMatchesFormatDescription extends RegularExpression |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $string; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $string; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $string |
|
27 | - */ |
|
28 | - public function __construct($string) |
|
29 | - { |
|
30 | - parent::__construct($string); |
|
25 | + /** |
|
26 | + * @param string $string |
|
27 | + */ |
|
28 | + public function __construct($string) |
|
29 | + { |
|
30 | + parent::__construct($string); |
|
31 | 31 | |
32 | - $this->pattern = $this->createPatternFromFormat( |
|
33 | - \preg_replace('/\r\n/', "\n", $string) |
|
34 | - ); |
|
32 | + $this->pattern = $this->createPatternFromFormat( |
|
33 | + \preg_replace('/\r\n/', "\n", $string) |
|
34 | + ); |
|
35 | 35 | |
36 | - $this->string = $string; |
|
37 | - } |
|
36 | + $this->string = $string; |
|
37 | + } |
|
38 | 38 | |
39 | - protected function failureDescription($other) |
|
40 | - { |
|
41 | - return 'string matches format description'; |
|
42 | - } |
|
39 | + protected function failureDescription($other) |
|
40 | + { |
|
41 | + return 'string matches format description'; |
|
42 | + } |
|
43 | 43 | |
44 | - protected function additionalFailureDescription($other) |
|
45 | - { |
|
46 | - $from = \preg_split('(\r\n|\r|\n)', $this->string); |
|
47 | - $to = \preg_split('(\r\n|\r|\n)', $other); |
|
44 | + protected function additionalFailureDescription($other) |
|
45 | + { |
|
46 | + $from = \preg_split('(\r\n|\r|\n)', $this->string); |
|
47 | + $to = \preg_split('(\r\n|\r|\n)', $other); |
|
48 | 48 | |
49 | - foreach ($from as $index => $line) { |
|
50 | - if (isset($to[$index]) && $line !== $to[$index]) { |
|
51 | - $line = $this->createPatternFromFormat($line); |
|
49 | + foreach ($from as $index => $line) { |
|
50 | + if (isset($to[$index]) && $line !== $to[$index]) { |
|
51 | + $line = $this->createPatternFromFormat($line); |
|
52 | 52 | |
53 | - if (\preg_match($line, $to[$index]) > 0) { |
|
54 | - $from[$index] = $to[$index]; |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
53 | + if (\preg_match($line, $to[$index]) > 0) { |
|
54 | + $from[$index] = $to[$index]; |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - $this->string = \implode("\n", $from); |
|
60 | - $other = \implode("\n", $to); |
|
59 | + $this->string = \implode("\n", $from); |
|
60 | + $other = \implode("\n", $to); |
|
61 | 61 | |
62 | - $differ = new Differ("--- Expected\n+++ Actual\n"); |
|
62 | + $differ = new Differ("--- Expected\n+++ Actual\n"); |
|
63 | 63 | |
64 | - return $differ->diff($this->string, $other); |
|
65 | - } |
|
64 | + return $differ->diff($this->string, $other); |
|
65 | + } |
|
66 | 66 | |
67 | - protected function createPatternFromFormat($string) |
|
68 | - { |
|
69 | - $string = \str_replace( |
|
70 | - [ |
|
71 | - '%e', |
|
72 | - '%s', |
|
73 | - '%S', |
|
74 | - '%a', |
|
75 | - '%A', |
|
76 | - '%w', |
|
77 | - '%i', |
|
78 | - '%d', |
|
79 | - '%x', |
|
80 | - '%f', |
|
81 | - '%c' |
|
82 | - ], |
|
83 | - [ |
|
84 | - '\\' . DIRECTORY_SEPARATOR, |
|
85 | - '[^\r\n]+', |
|
86 | - '[^\r\n]*', |
|
87 | - '.+', |
|
88 | - '.*', |
|
89 | - '\s*', |
|
90 | - '[+-]?\d+', |
|
91 | - '\d+', |
|
92 | - '[0-9a-fA-F]+', |
|
93 | - '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', |
|
94 | - '.' |
|
95 | - ], |
|
96 | - \preg_quote($string, '/') |
|
97 | - ); |
|
67 | + protected function createPatternFromFormat($string) |
|
68 | + { |
|
69 | + $string = \str_replace( |
|
70 | + [ |
|
71 | + '%e', |
|
72 | + '%s', |
|
73 | + '%S', |
|
74 | + '%a', |
|
75 | + '%A', |
|
76 | + '%w', |
|
77 | + '%i', |
|
78 | + '%d', |
|
79 | + '%x', |
|
80 | + '%f', |
|
81 | + '%c' |
|
82 | + ], |
|
83 | + [ |
|
84 | + '\\' . DIRECTORY_SEPARATOR, |
|
85 | + '[^\r\n]+', |
|
86 | + '[^\r\n]*', |
|
87 | + '.+', |
|
88 | + '.*', |
|
89 | + '\s*', |
|
90 | + '[+-]?\d+', |
|
91 | + '\d+', |
|
92 | + '[0-9a-fA-F]+', |
|
93 | + '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', |
|
94 | + '.' |
|
95 | + ], |
|
96 | + \preg_quote($string, '/') |
|
97 | + ); |
|
98 | 98 | |
99 | - return '/^' . $string . '$/s'; |
|
100 | - } |
|
99 | + return '/^' . $string . '$/s'; |
|
100 | + } |
|
101 | 101 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | '%c' |
82 | 82 | ], |
83 | 83 | [ |
84 | - '\\' . DIRECTORY_SEPARATOR, |
|
84 | + '\\'.DIRECTORY_SEPARATOR, |
|
85 | 85 | '[^\r\n]+', |
86 | 86 | '[^\r\n]*', |
87 | 87 | '.+', |
@@ -96,6 +96,6 @@ discard block |
||
96 | 96 | \preg_quote($string, '/') |
97 | 97 | ); |
98 | 98 | |
99 | - return '/^' . $string . '$/s'; |
|
99 | + return '/^'.$string.'$/s'; |
|
100 | 100 | } |
101 | 101 | } |
@@ -20,25 +20,25 @@ |
||
20 | 20 | */ |
21 | 21 | class ExpectationFailedException extends AssertionFailedError |
22 | 22 | { |
23 | - protected $comparisonFailure; |
|
23 | + protected $comparisonFailure; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $message |
|
27 | - * @param ComparisonFailure|null $comparisonFailure |
|
28 | - * @param \Exception|null $previous |
|
29 | - */ |
|
30 | - public function __construct($message, ComparisonFailure $comparisonFailure = null, \Exception $previous = null) |
|
31 | - { |
|
32 | - $this->comparisonFailure = $comparisonFailure; |
|
25 | + /** |
|
26 | + * @param string $message |
|
27 | + * @param ComparisonFailure|null $comparisonFailure |
|
28 | + * @param \Exception|null $previous |
|
29 | + */ |
|
30 | + public function __construct($message, ComparisonFailure $comparisonFailure = null, \Exception $previous = null) |
|
31 | + { |
|
32 | + $this->comparisonFailure = $comparisonFailure; |
|
33 | 33 | |
34 | - parent::__construct($message, 0, $previous); |
|
35 | - } |
|
34 | + parent::__construct($message, 0, $previous); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return null|ComparisonFailure |
|
39 | - */ |
|
40 | - public function getComparisonFailure() |
|
41 | - { |
|
42 | - return $this->comparisonFailure; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @return null|ComparisonFailure |
|
39 | + */ |
|
40 | + public function getComparisonFailure() |
|
41 | + { |
|
42 | + return $this->comparisonFailure; |
|
43 | + } |
|
44 | 44 | } |
@@ -14,63 +14,63 @@ |
||
14 | 14 | */ |
15 | 15 | class WarningTestCase extends TestCase |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $message = ''; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $message = ''; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $backupGlobals = false; |
|
22 | + /** |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $backupGlobals = false; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var bool |
|
29 | - */ |
|
30 | - protected $backupStaticAttributes = false; |
|
27 | + /** |
|
28 | + * @var bool |
|
29 | + */ |
|
30 | + protected $backupStaticAttributes = false; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - protected $runTestInSeparateProcess = false; |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + protected $runTestInSeparateProcess = false; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var bool |
|
39 | - */ |
|
40 | - protected $useErrorHandler = false; |
|
37 | + /** |
|
38 | + * @var bool |
|
39 | + */ |
|
40 | + protected $useErrorHandler = false; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param string $message |
|
44 | - */ |
|
45 | - public function __construct($message = '') |
|
46 | - { |
|
47 | - $this->message = $message; |
|
48 | - parent::__construct('Warning'); |
|
49 | - } |
|
42 | + /** |
|
43 | + * @param string $message |
|
44 | + */ |
|
45 | + public function __construct($message = '') |
|
46 | + { |
|
47 | + $this->message = $message; |
|
48 | + parent::__construct('Warning'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - protected function runTest() |
|
55 | - { |
|
56 | - throw new Warning($this->message); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + protected function runTest() |
|
55 | + { |
|
56 | + throw new Warning($this->message); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function getMessage() |
|
63 | - { |
|
64 | - return $this->message; |
|
65 | - } |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function getMessage() |
|
63 | + { |
|
64 | + return $this->message; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns a string representation of the test case. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function toString() |
|
73 | - { |
|
74 | - return 'Warning'; |
|
75 | - } |
|
67 | + /** |
|
68 | + * Returns a string representation of the test case. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function toString() |
|
73 | + { |
|
74 | + return 'Warning'; |
|
75 | + } |
|
76 | 76 | } |