1 | <?php |
||
16 | class ExceptionMatcher implements MatcherInterface |
||
17 | { |
||
18 | use MatcherTrait; |
||
19 | |||
20 | /** |
||
21 | * @param string $exceptionType |
||
22 | */ |
||
23 | public function __construct($exceptionType) |
||
27 | |||
28 | /** |
||
29 | * Set arguments to be passed to the callable. |
||
30 | * |
||
31 | * @param array $arguments |
||
32 | * @return $this |
||
33 | */ |
||
34 | public function setArguments(array $arguments) |
||
40 | |||
41 | /** |
||
42 | * Set the expected message of the exception. |
||
43 | * |
||
44 | * @param string $message |
||
45 | * @return $this |
||
46 | */ |
||
47 | public function setExpectedMessage($message) |
||
53 | |||
54 | /** |
||
55 | * Set the message thrown from an exception resulting from the |
||
56 | * callable being invoked. |
||
57 | * |
||
58 | * @param string $message |
||
59 | */ |
||
60 | public function setMessage($message) |
||
64 | |||
65 | /** |
||
66 | * Returns the arguments passed to the callable. |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | public function getArguments() |
||
74 | |||
75 | /** |
||
76 | * Return the expected exception message. |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getExpectedMessage() |
||
84 | |||
85 | /** |
||
86 | * Return the message thrown by an exception resulting from the callable |
||
87 | * being invoked. |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getMessage() |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | * |
||
99 | * If the expected message has been set, the message template will be used. |
||
100 | * |
||
101 | * @return TemplateInterface |
||
102 | */ |
||
103 | public function getTemplate() |
||
115 | |||
116 | /** |
||
117 | * Set the template to be used when an expected exception message is provided. |
||
118 | * |
||
119 | * @param TemplateInterface $template |
||
120 | * @return $this |
||
121 | */ |
||
122 | public function setMessageTemplate(TemplateInterface $template) |
||
128 | |||
129 | /** |
||
130 | * Return a template for rendering exception message templates. |
||
131 | * |
||
132 | * return TemplateInterface |
||
133 | */ |
||
134 | public function getMessageTemplate() |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | * |
||
146 | * @return TemplateInterface |
||
147 | */ |
||
148 | public function getDefaultTemplate() |
||
155 | |||
156 | /** |
||
157 | * Return a default template for exception message assertions. |
||
158 | * |
||
159 | * @return ArrayTemplate |
||
160 | */ |
||
161 | public function getDefaultMessageTemplate() |
||
168 | |||
169 | /** |
||
170 | * Executes the callable and matches the exception type and exception message. |
||
171 | * |
||
172 | * @param $actual |
||
173 | * @return Match |
||
174 | */ |
||
175 | public function match($actual) |
||
184 | |||
185 | /** |
||
186 | * Validate that expected is indeed a valid callable. |
||
187 | * |
||
188 | * @throws \BadFunctionCallException |
||
189 | */ |
||
190 | protected function validateCallable($callable) |
||
197 | |||
198 | private function callableException($callable) |
||
215 | |||
216 | private function matchMessage($actual, $exception, $message) |
||
226 | |||
227 | private function matchType($actual, $exception) |
||
234 | |||
235 | /** |
||
236 | * @var mixed |
||
237 | */ |
||
238 | protected $expected; |
||
239 | |||
240 | /** |
||
241 | * @var array |
||
242 | */ |
||
243 | protected $arguments = []; |
||
244 | |||
245 | /** |
||
246 | * @var string |
||
247 | */ |
||
248 | protected $expectedMessage = ''; |
||
249 | |||
250 | /** |
||
251 | * A captured exception message. |
||
252 | * |
||
253 | * @var string |
||
254 | */ |
||
255 | protected $message; |
||
256 | |||
257 | /** |
||
258 | * @var TemplateInterface |
||
259 | */ |
||
260 | protected $messageTemplate; |
||
261 | } |
||
262 |