1 | <?php |
||
13 | class ExceptionMatcher extends AbstractMatcher |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $arguments = []; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $expectedMessage = ""; |
||
24 | |||
25 | /** |
||
26 | * A captured exception message |
||
27 | * |
||
28 | * @var string $message |
||
29 | */ |
||
30 | protected $message; |
||
31 | |||
32 | /** |
||
33 | * @var TemplateInterface |
||
34 | */ |
||
35 | protected $messageTemplate; |
||
36 | |||
37 | /** |
||
38 | * @param callable $expected |
||
|
|||
39 | */ |
||
40 | public function __construct($exceptionType) |
||
44 | |||
45 | /** |
||
46 | * Set arguments to be passed to the callable. |
||
47 | * |
||
48 | * @param array $arguments |
||
49 | * @return $this |
||
50 | */ |
||
51 | public function setArguments(array $arguments) |
||
56 | |||
57 | /** |
||
58 | * Set the expected message of the exception. |
||
59 | * |
||
60 | * @param string $message |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function setExpectedMessage($message) |
||
68 | |||
69 | /** |
||
70 | * Set the message thrown from an exception resulting from the |
||
71 | * callable being invoked. |
||
72 | * |
||
73 | * @param string $message |
||
74 | */ |
||
75 | public function setMessage($message) |
||
79 | |||
80 | /** |
||
81 | * Returns the arguments passed to the callable. |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | public function getArguments() |
||
89 | |||
90 | /** |
||
91 | * Return the expected exception message. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getExpectedMessage() |
||
99 | |||
100 | /** |
||
101 | * Return the message thrown by an exception resulting from the callable |
||
102 | * being invoked. |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getMessage() |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | * |
||
114 | * If the expected message has been set, the message template will be used. |
||
115 | * |
||
116 | * @return TemplateInterface |
||
117 | */ |
||
118 | public function getTemplate() |
||
125 | |||
126 | /** |
||
127 | * Set the template to be used when an expected exception message is provided. |
||
128 | * |
||
129 | * @param TemplateInterface $template |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function setMessageTemplate(TemplateInterface $template) |
||
137 | |||
138 | /** |
||
139 | * Return a template for rendering exception message templates. |
||
140 | * |
||
141 | * return TemplateInterface |
||
142 | */ |
||
143 | public function getMessageTemplate() |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | * |
||
154 | * @return TemplateInterface |
||
155 | */ |
||
156 | public function getDefaultTemplate() |
||
165 | |||
166 | /** |
||
167 | * Return a default template for exception message assertions. |
||
168 | * |
||
169 | * @return ArrayTemplate |
||
170 | */ |
||
171 | public function getDefaultMessageTemplate() |
||
178 | |||
179 | /** |
||
180 | * Executes the callable and matches the exception type and exception message. |
||
181 | * |
||
182 | * @param $actual |
||
183 | * @return Match |
||
184 | */ |
||
185 | public function match($actual) |
||
212 | |||
213 | /** |
||
214 | * Executes the callable and matches the exception type and exception message. |
||
215 | * |
||
216 | * @param $actual |
||
217 | * @return bool |
||
218 | */ |
||
219 | protected function doMatch($actual) |
||
223 | |||
224 | /** |
||
225 | * Validate that expected is indeed a valid callable. |
||
226 | * |
||
227 | * @throws \BadFunctionCallException |
||
228 | */ |
||
229 | protected function validateCallable($callable) |
||
236 | } |
||
237 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.