1 | <?php |
||
15 | class ExceptionMatcher extends AbstractMatcher |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $arguments = []; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $expectedMessage = ""; |
||
26 | |||
27 | /** |
||
28 | * A captured exception message |
||
29 | * |
||
30 | * @var string $message |
||
31 | */ |
||
32 | protected $message; |
||
33 | |||
34 | /** |
||
35 | * @var TemplateInterface |
||
36 | */ |
||
37 | protected $messageTemplate; |
||
38 | |||
39 | /** |
||
40 | * @param callable $expected |
||
|
|||
41 | */ |
||
42 | public function __construct($exceptionType) |
||
46 | |||
47 | /** |
||
48 | * Set arguments to be passed to the callable. |
||
49 | * |
||
50 | * @param array $arguments |
||
51 | * @return $this |
||
52 | */ |
||
53 | public function setArguments(array $arguments) |
||
58 | |||
59 | /** |
||
60 | * Set the expected message of the exception. |
||
61 | * |
||
62 | * @param string $message |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function setExpectedMessage($message) |
||
70 | |||
71 | /** |
||
72 | * Set the message thrown from an exception resulting from the |
||
73 | * callable being invoked. |
||
74 | * |
||
75 | * @param string $message |
||
76 | */ |
||
77 | public function setMessage($message) |
||
81 | |||
82 | /** |
||
83 | * Returns the arguments passed to the callable. |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function getArguments() |
||
91 | |||
92 | /** |
||
93 | * Return the expected exception message. |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getExpectedMessage() |
||
101 | |||
102 | /** |
||
103 | * Return the message thrown by an exception resulting from the callable |
||
104 | * being invoked. |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function getMessage() |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | * |
||
116 | * If the expected message has been set, the message template will be used. |
||
117 | * |
||
118 | * @return TemplateInterface |
||
119 | */ |
||
120 | public function getTemplate() |
||
127 | |||
128 | /** |
||
129 | * Set the template to be used when an expected exception message is provided. |
||
130 | * |
||
131 | * @param TemplateInterface $template |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function setMessageTemplate(TemplateInterface $template) |
||
139 | |||
140 | /** |
||
141 | * Return a template for rendering exception message templates. |
||
142 | * |
||
143 | * return TemplateInterface |
||
144 | */ |
||
145 | public function getMessageTemplate() |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | * |
||
156 | * @return TemplateInterface |
||
157 | */ |
||
158 | public function getDefaultTemplate() |
||
167 | |||
168 | /** |
||
169 | * Return a default template for exception message assertions. |
||
170 | * |
||
171 | * @return ArrayTemplate |
||
172 | */ |
||
173 | public function getDefaultMessageTemplate() |
||
180 | |||
181 | /** |
||
182 | * Executes the callable and matches the exception type and exception message. |
||
183 | * |
||
184 | * @param $actual |
||
185 | * @return Match |
||
186 | */ |
||
187 | public function match($actual) |
||
225 | |||
226 | /** |
||
227 | * Executes the callable and matches the exception type and exception message. |
||
228 | * |
||
229 | * @param $actual |
||
230 | * @return bool |
||
231 | */ |
||
232 | protected function doMatch($actual) |
||
236 | |||
237 | /** |
||
238 | * Validate that expected is indeed a valid callable. |
||
239 | * |
||
240 | * @throws \BadFunctionCallException |
||
241 | */ |
||
242 | protected function validateCallable($callable) |
||
249 | } |
||
250 |
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.