File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 15
15
namespace Cake \Console ;
16
16
17
17
use Cake \Console \Exception \ConsoleException ;
18
+ use Cake \Console \Exception \StopException ;
18
19
use Cake \Datasource \ModelAwareTrait ;
19
20
use Cake \Log \LogTrait ;
20
21
use Cake \ORM \Locator \LocatorAwareTrait ;
@@ -233,4 +234,15 @@ public function execute(Arguments $args, ConsoleIo $io)
233
234
{
234
235
return null ;
235
236
}
237
+
238
+ /**
239
+ * Halt the the current process with a StopException.
240
+ *
241
+ * @param int $code The exit code to use.
242
+ * @throws \Cake\Console\Exception\ConsoleException
243
+ */
244
+ public function abort ($ code = self ::CODE_ERROR )
245
+ {
246
+ throw new StopException ('Command aborted ' , $ code );
247
+ }
236
248
}
Original file line number Diff line number Diff line change @@ -235,6 +235,32 @@ public function testRunOptionParserFailure()
235
235
$ this ->assertContains ('Error: Missing required arguments. name is required ' , $ messages );
236
236
}
237
237
238
+ /**
239
+ * Test abort()
240
+ *
241
+ * @expectedException \Cake\Console\Exception\StopException
242
+ * @expectedExceptionCode 1
243
+ * @return void
244
+ */
245
+ public function testAbort ()
246
+ {
247
+ $ command = new Command ();
248
+ $ command ->abort ();
249
+ }
250
+
251
+ /**
252
+ * Test abort()
253
+ *
254
+ * @expectedException \Cake\Console\Exception\StopException
255
+ * @expectedExceptionCode 99
256
+ * @return void
257
+ */
258
+ public function testAbortCustomCode ()
259
+ {
260
+ $ command = new Command ();
261
+ $ command ->abort (99 );
262
+ }
263
+
238
264
protected function getMockIo ($ output )
239
265
{
240
266
$ io = $ this ->getMockBuilder (ConsoleIo::class)
You can’t perform that action at this time.
0 commit comments