File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,52 @@ public function assertFailed()
145
145
return $ this ;
146
146
}
147
147
148
+ /**
149
+ * Assert that the job was manually failed with a specific exception.
150
+ *
151
+ * @param \Throwable|string $exception
152
+ * @return $this
153
+ */
154
+ public function assertFailedWith ($ exception )
155
+ {
156
+ $ this ->assertFailed ();
157
+
158
+ if (is_string ($ exception ) && class_exists ($ exception )) {
159
+ PHPUnit::assertInstanceOf (
160
+ $ exception ,
161
+ $ this ->job ->failedWith ,
162
+ 'Expected job to be manually failed with [ ' .$ exception .'] but job failed with [ ' .get_class ($ this ->job ->failedWith ).']. '
163
+ );
164
+
165
+ return $ this ;
166
+ }
167
+
168
+ if (is_string ($ exception )) {
169
+ $ exception = new ManuallyFailedException ($ exception );
170
+ }
171
+
172
+ if ($ exception instanceof Throwable) {
173
+ PHPUnit::assertInstanceOf (
174
+ get_class ($ exception ),
175
+ $ this ->job ->failedWith ,
176
+ 'Expected job to be manually failed with [ ' .get_class ($ exception ).'] but job failed with [ ' .get_class ($ this ->job ->failedWith ).']. '
177
+ );
178
+
179
+ PHPUnit::assertEquals (
180
+ $ exception ->getCode (),
181
+ $ this ->job ->failedWith ->getCode (),
182
+ 'Expected exception code [ ' .$ exception ->getCode ().'] but job failed with exception code [ ' .$ this ->job ->failedWith ->getCode ().']. '
183
+ );
184
+
185
+ PHPUnit::assertEquals (
186
+ $ exception ->getMessage (),
187
+ $ this ->job ->failedWith ->getMessage (),
188
+ 'Expected exceptoin message [ ' .$ exception ->getMessage ().'] but job failed with exception message [ ' .$ this ->job ->failedWith ->getMessage ().']. ' );
189
+ }
190
+
191
+ return $ this ;
192
+ }
193
+
148
194
/**
149
195
* Assert that the job was not manually failed.
150
196
*
You can’t perform that action at this time.
0 commit comments