ShellTest.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP Project
  13. * @since 1.2.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Console;
  17. use Cake\Console\ConsoleIo;
  18. use Cake\Console\ConsoleOptionParser;
  19. use Cake\Console\Exception\StopException;
  20. use Cake\Console\Shell;
  21. use Cake\Filesystem\Filesystem;
  22. use Cake\TestSuite\TestCase;
  23. use RuntimeException;
  24. use TestApp\Shell\MergeShell;
  25. use TestApp\Shell\ShellTestShell;
  26. use TestApp\Shell\Task\TestAppleTask;
  27. use TestApp\Shell\Task\TestBananaTask;
  28. use TestApp\Shell\TestingDispatchShell;
  29. use TestPlugin\Model\Table\TestPluginCommentsTable;
  30. class_alias(TestAppleTask::class, 'Cake\Shell\Task\TestAppleTask');
  31. class_alias(TestBananaTask::class, 'Cake\Shell\Task\TestBananaTask');
  32. /**
  33. * ShellTest class
  34. */
  35. class ShellTest extends TestCase
  36. {
  37. /**
  38. * Fixtures used in this test case
  39. *
  40. * @var array
  41. */
  42. protected $fixtures = [
  43. 'core.Articles',
  44. 'core.ArticlesTags',
  45. 'core.Attachments',
  46. 'core.Comments',
  47. 'core.Posts',
  48. 'core.Tags',
  49. 'core.Users',
  50. ];
  51. /**
  52. * @var \Cake\Console\Shell
  53. */
  54. protected $Shell;
  55. /**
  56. * @var \Cake\Console\ConsoleIo|\PHPUnit\Framework\MockObject\MockObject
  57. */
  58. protected $io;
  59. /**
  60. * @var \Cake\Filesystem\Filesystem
  61. */
  62. protected $fs;
  63. /**
  64. * setUp method
  65. *
  66. * @return void
  67. */
  68. public function setUp(): void
  69. {
  70. parent::setUp();
  71. $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')
  72. ->disableOriginalConstructor()
  73. ->getMock();
  74. $this->Shell = new ShellTestShell($this->io, $this->getTableLocator());
  75. $this->fs = new Filesystem();
  76. if (is_dir(TMP . 'shell_test')) {
  77. $this->fs->deleteDir(TMP . 'shell_test');
  78. }
  79. }
  80. /**
  81. * testConstruct method
  82. *
  83. * @return void
  84. */
  85. public function testConstruct()
  86. {
  87. $this->assertSame('ShellTestShell', $this->Shell->name);
  88. $this->assertInstanceOf(ConsoleIo::class, $this->Shell->getIo());
  89. }
  90. /**
  91. * testInitialize method
  92. *
  93. * @return void
  94. */
  95. public function testInitialize()
  96. {
  97. static::setAppNamespace();
  98. $this->loadPlugins(['TestPlugin']);
  99. $this->Shell->tasks = ['Sample' => ['one', 'two']];
  100. $this->Shell->plugin = 'TestPlugin';
  101. $this->Shell->initialize();
  102. // TestApp\Shell\ShellTestShell has $modelClass property set to 'TestPlugin.TestPluginComments'
  103. $this->Shell->loadModel();
  104. $this->assertTrue(isset($this->Shell->TestPluginComments));
  105. $this->assertInstanceOf(
  106. TestPluginCommentsTable::class,
  107. $this->Shell->TestPluginComments
  108. );
  109. $this->clearPlugins();
  110. }
  111. /**
  112. * test LoadModel method
  113. *
  114. * @return void
  115. */
  116. public function testLoadModel()
  117. {
  118. static::setAppNamespace();
  119. $Shell = new MergeShell();
  120. $this->assertInstanceOf(
  121. 'TestApp\Model\Table\ArticlesTable',
  122. $Shell->Articles
  123. );
  124. $this->assertSame('Articles', $Shell->modelClass);
  125. $this->loadPlugins(['TestPlugin']);
  126. $result = $this->Shell->loadModel('TestPlugin.TestPluginComments');
  127. $this->assertInstanceOf(
  128. TestPluginCommentsTable::class,
  129. $result
  130. );
  131. $this->assertInstanceOf(
  132. TestPluginCommentsTable::class,
  133. $this->Shell->TestPluginComments
  134. );
  135. $this->clearPlugins();
  136. }
  137. /**
  138. * testIn method
  139. *
  140. * @return void
  141. */
  142. public function testIn()
  143. {
  144. $this->io->expects($this->at(0))
  145. ->method('askChoice')
  146. ->with('Just a test?', ['y', 'n'], 'n')
  147. ->will($this->returnValue('n'));
  148. $this->io->expects($this->at(1))
  149. ->method('ask')
  150. ->with('Just a test?', 'n')
  151. ->will($this->returnValue('n'));
  152. $result = $this->Shell->in('Just a test?', ['y', 'n'], 'n');
  153. $this->assertSame('n', $result);
  154. $result = $this->Shell->in('Just a test?', null, 'n');
  155. $this->assertSame('n', $result);
  156. }
  157. /**
  158. * Test in() when not interactive.
  159. *
  160. * @return void
  161. */
  162. public function testInNonInteractive()
  163. {
  164. $this->io->expects($this->never())
  165. ->method('askChoice');
  166. $this->io->expects($this->never())
  167. ->method('ask');
  168. $this->Shell->interactive = false;
  169. $result = $this->Shell->in('Just a test?', 'y/n', 'n');
  170. $this->assertSame('n', $result);
  171. }
  172. /**
  173. * testVerbose method
  174. *
  175. * @return void
  176. */
  177. public function testVerbose()
  178. {
  179. $this->io->expects($this->once())
  180. ->method('verbose')
  181. ->with('Just a test', 1);
  182. $this->Shell->verbose('Just a test');
  183. }
  184. /**
  185. * testQuiet method
  186. *
  187. * @return void
  188. */
  189. public function testQuiet()
  190. {
  191. $this->io->expects($this->once())
  192. ->method('quiet')
  193. ->with('Just a test', 1);
  194. $this->Shell->quiet('Just a test');
  195. }
  196. /**
  197. * testOut method
  198. *
  199. * @return void
  200. */
  201. public function testOut()
  202. {
  203. $this->io->expects($this->once())
  204. ->method('out')
  205. ->with('Just a test', 1);
  206. $this->Shell->out('Just a test');
  207. }
  208. /**
  209. * testErr method
  210. *
  211. * @return void
  212. */
  213. public function testErr()
  214. {
  215. $this->io->expects($this->once())
  216. ->method('error')
  217. ->with('Just a test', 1);
  218. $this->Shell->err('Just a test');
  219. }
  220. /**
  221. * testErr method with array
  222. *
  223. * @return void
  224. */
  225. public function testErrArray()
  226. {
  227. $this->io->expects($this->once())
  228. ->method('error')
  229. ->with(['Just', 'a', 'test'], 1);
  230. $this->Shell->err(['Just', 'a', 'test']);
  231. }
  232. /**
  233. * testInfo method
  234. *
  235. * @return void
  236. */
  237. public function testInfo()
  238. {
  239. $this->io->expects($this->once())
  240. ->method('info')
  241. ->with('Just a test', 1);
  242. $this->Shell->info('Just a test');
  243. }
  244. /**
  245. * testInfo method with array
  246. *
  247. * @return void
  248. */
  249. public function testInfoArray()
  250. {
  251. $this->io->expects($this->once())
  252. ->method('info')
  253. ->with(['Just', 'a', 'test'], 1);
  254. $this->Shell->info(['Just', 'a', 'test']);
  255. }
  256. /**
  257. * testWarn method
  258. *
  259. * @return void
  260. */
  261. public function testWarn()
  262. {
  263. $this->io->expects($this->once())
  264. ->method('warning')
  265. ->with('Just a test', 1);
  266. $this->Shell->warn('Just a test');
  267. }
  268. /**
  269. * testWarn method with array
  270. *
  271. * @return void
  272. */
  273. public function testWarnArray()
  274. {
  275. $this->io->expects($this->once())
  276. ->method('warning')
  277. ->with(['Just', 'a', 'test'], 1);
  278. $this->Shell->warn(['Just', 'a', 'test']);
  279. }
  280. /**
  281. * testSuccess method
  282. *
  283. * @return void
  284. */
  285. public function testSuccess()
  286. {
  287. $this->io->expects($this->once())
  288. ->method('success')
  289. ->with('Just a test', 1);
  290. $this->Shell->success('Just a test');
  291. }
  292. /**
  293. * testSuccess method with array
  294. *
  295. * @return void
  296. */
  297. public function testSuccessArray()
  298. {
  299. $this->io->expects($this->once())
  300. ->method('success')
  301. ->with(['Just', 'a', 'test'], 1);
  302. $this->Shell->success(['Just', 'a', 'test']);
  303. }
  304. /**
  305. * testNl
  306. *
  307. * @return void
  308. */
  309. public function testNl()
  310. {
  311. $this->io->expects($this->once())
  312. ->method('nl')
  313. ->with(2);
  314. $this->Shell->nl(2);
  315. }
  316. /**
  317. * testHr
  318. *
  319. * @return void
  320. */
  321. public function testHr()
  322. {
  323. $this->io->expects($this->once())
  324. ->method('hr')
  325. ->with(2);
  326. $this->Shell->hr(2);
  327. }
  328. /**
  329. * testAbort
  330. *
  331. * @return void
  332. */
  333. public function testAbort()
  334. {
  335. $this->expectException(StopException::class);
  336. $this->expectExceptionMessage('Foo Not Found');
  337. $this->expectExceptionCode(1);
  338. $this->io->expects($this->at(0))
  339. ->method('err')
  340. ->with('<error>Foo Not Found</error>');
  341. $this->Shell->abort('Foo Not Found');
  342. }
  343. /**
  344. * testLoadTasks method
  345. *
  346. * @return void
  347. */
  348. public function testLoadTasks()
  349. {
  350. $this->assertTrue($this->Shell->loadTasks());
  351. $this->Shell->tasks = null;
  352. $this->assertTrue($this->Shell->loadTasks());
  353. $this->Shell->tasks = false;
  354. $this->assertTrue($this->Shell->loadTasks());
  355. $this->Shell->tasks = true;
  356. $this->assertTrue($this->Shell->loadTasks());
  357. $this->Shell->tasks = [];
  358. $this->assertTrue($this->Shell->loadTasks());
  359. $this->Shell->tasks = ['TestApple'];
  360. $this->assertTrue($this->Shell->loadTasks());
  361. $this->assertInstanceOf('Cake\Shell\Task\TestAppleTask', $this->Shell->TestApple);
  362. $this->Shell->tasks = 'TestBanana';
  363. $this->assertTrue($this->Shell->loadTasks());
  364. $this->assertInstanceOf('Cake\Shell\Task\TestAppleTask', $this->Shell->TestApple);
  365. $this->assertInstanceOf('Cake\Shell\Task\TestBananaTask', $this->Shell->TestBanana);
  366. unset($this->Shell->ShellTestApple, $this->Shell->TestBanana);
  367. $this->Shell->tasks = ['TestApple', 'TestBanana'];
  368. $this->assertTrue($this->Shell->loadTasks());
  369. $this->assertInstanceOf('Cake\Shell\Task\TestAppleTask', $this->Shell->TestApple);
  370. $this->assertInstanceOf('Cake\Shell\Task\TestBananaTask', $this->Shell->TestBanana);
  371. }
  372. /**
  373. * test that __get() makes args and params references
  374. *
  375. * @return void
  376. */
  377. public function testMagicGetArgAndParamReferences()
  378. {
  379. $this->Shell->tasks = ['TestApple'];
  380. $this->Shell->args = ['one'];
  381. $this->Shell->params = ['help' => false];
  382. $this->Shell->loadTasks();
  383. $result = $this->Shell->TestApple;
  384. $this->Shell->args = ['one', 'two'];
  385. $this->assertSame($this->Shell->args, $result->args);
  386. $this->assertSame($this->Shell->params, $result->params);
  387. }
  388. /**
  389. * testShortPath method
  390. *
  391. * @return void
  392. */
  393. public function testShortPath()
  394. {
  395. $path = $expected = DS . 'tmp/ab/cd';
  396. $this->assertPathEquals($expected, $this->Shell->shortPath($path));
  397. $path = $expected = DS . 'tmp/ab/cd/';
  398. $this->assertPathEquals($expected, $this->Shell->shortPath($path));
  399. $path = $expected = DS . 'tmp/ab/index.php';
  400. $this->assertPathEquals($expected, $this->Shell->shortPath($path));
  401. $path = DS . 'tmp/ab/' . DS . 'cd';
  402. $expected = DS . 'tmp/ab/cd';
  403. $this->assertPathEquals($expected, $this->Shell->shortPath($path));
  404. $path = 'tmp/ab';
  405. $expected = 'tmp/ab';
  406. $this->assertPathEquals($expected, $this->Shell->shortPath($path));
  407. $path = 'tmp/ab';
  408. $expected = 'tmp/ab';
  409. $this->assertPathEquals($expected, $this->Shell->shortPath($path));
  410. $path = APP;
  411. $result = $this->Shell->shortPath($path);
  412. $this->assertStringNotContainsString(ROOT, $result, 'Short paths should not contain ROOT');
  413. }
  414. /**
  415. * testCreateFile method
  416. *
  417. * @return void
  418. */
  419. public function testCreateFileNonInteractive()
  420. {
  421. $eol = PHP_EOL;
  422. $path = TMP . 'shell_test';
  423. $file = $path . DS . 'file1.php';
  424. $this->fs->mkdir($path);
  425. $contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
  426. $this->Shell->interactive = false;
  427. $result = $this->Shell->createFile($file, $contents);
  428. $this->assertTrue($result);
  429. $this->assertFileExists($file);
  430. $this->assertStringEqualsFile($file, $contents);
  431. }
  432. /**
  433. * Test that while in non interactive mode it will not overwrite files by default.
  434. *
  435. * @return void
  436. */
  437. public function testCreateFileNonInteractiveFileExists()
  438. {
  439. $eol = PHP_EOL;
  440. $path = TMP . 'shell_test';
  441. $file = $path . DS . 'file1.php';
  442. if (!is_dir($path)) {
  443. mkdir($path, 0770, true);
  444. }
  445. touch($file);
  446. $this->assertFileExists($file);
  447. $this->fs->mkdir($path);
  448. $contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}";
  449. $this->Shell->interactive = false;
  450. $result = $this->Shell->createFile($file, $contents);
  451. $this->assertFalse($result);
  452. }
  453. /**
  454. * Test that files are not changed with a 'n' reply.
  455. *
  456. * @return void
  457. */
  458. public function testCreateFileNoReply()
  459. {
  460. $path = TMP . 'shell_test';
  461. $file = $path . DS . 'file1.php';
  462. $this->fs->mkdir($path);
  463. $this->io->expects($this->once())
  464. ->method('askChoice')
  465. ->will($this->returnValue('n'));
  466. touch($file);
  467. $this->assertFileExists($file);
  468. $contents = 'My content';
  469. $result = $this->Shell->createFile($file, $contents);
  470. $this->assertFileExists($file);
  471. $this->assertTextEquals('', file_get_contents($file));
  472. $this->assertFalse($result, 'Did not create file.');
  473. }
  474. /**
  475. * Test that files are changed with a 'y' reply.
  476. *
  477. * @return void
  478. */
  479. public function testCreateFileOverwrite()
  480. {
  481. $path = TMP . 'shell_test';
  482. $file = $path . DS . 'file1.php';
  483. $this->fs->mkdir($path);
  484. $this->io->expects($this->once())
  485. ->method('askChoice')
  486. ->will($this->returnValue('y'));
  487. touch($file);
  488. $this->assertFileExists($file);
  489. $contents = 'My content';
  490. $result = $this->Shell->createFile($file, $contents);
  491. $this->assertFileExists($file);
  492. $this->assertTextEquals($contents, file_get_contents($file));
  493. $this->assertTrue($result, 'Did create file.');
  494. }
  495. /**
  496. * Test that there is no user prompt in non-interactive mode while file already exists
  497. * and if force mode is explicitly enabled.
  498. *
  499. * @return void
  500. */
  501. public function testCreateFileOverwriteNonInteractive()
  502. {
  503. $path = TMP . 'shell_test';
  504. $file = $path . DS . 'file1.php';
  505. $this->fs->mkdir($path);
  506. touch($file);
  507. $this->assertFileExists($file);
  508. $this->io->expects($this->never())->method('askChoice');
  509. $this->Shell->params['force'] = true;
  510. $this->Shell->interactive = false;
  511. $result = $this->Shell->createFile($file, 'My content');
  512. $this->assertTrue($result);
  513. $this->assertStringEqualsFile($file, 'My content');
  514. }
  515. /**
  516. * Test that all files are changed with a 'a' reply.
  517. *
  518. * @return void
  519. */
  520. public function testCreateFileOverwriteAll()
  521. {
  522. $path = TMP . 'shell_test';
  523. $files = [
  524. $path . DS . 'file1.php' => 'My first content',
  525. $path . DS . 'file2.php' => 'My second content',
  526. $path . DS . 'file3.php' => 'My third content',
  527. ];
  528. $this->fs->mkdir($path);
  529. $this->io->expects($this->once())
  530. ->method('askChoice')
  531. ->will($this->returnValue('a'));
  532. foreach ($files as $file => $contents) {
  533. touch($file);
  534. $this->assertFileExists($file);
  535. $result = $this->Shell->createFile($file, $contents);
  536. $this->assertFileExists($file);
  537. $this->assertTextEquals($contents, file_get_contents($file));
  538. $this->assertTrue($result, 'Did create file.');
  539. }
  540. }
  541. /**
  542. * Test that you can't create files that aren't writable.
  543. *
  544. * @return void
  545. */
  546. public function testCreateFileNoPermissions()
  547. {
  548. $this->skipIf(DS === '\\', 'Cant perform operations using permissions on windows.');
  549. $path = TMP . 'shell_test';
  550. $file = $path . DS . 'no_perms';
  551. if (!is_dir($path)) {
  552. mkdir($path);
  553. }
  554. chmod($path, 0444);
  555. $this->Shell->createFile($file, 'testing');
  556. $this->assertFileNotExists($file);
  557. chmod($path, 0744);
  558. rmdir($path);
  559. }
  560. /**
  561. * test hasTask method
  562. *
  563. * @return void
  564. */
  565. public function testHasTask()
  566. {
  567. $this->setAppNamespace();
  568. $this->Shell->tasks = ['Sample', 'TestApple'];
  569. $this->Shell->loadTasks();
  570. $this->assertTrue($this->Shell->hasTask('sample'));
  571. $this->assertTrue($this->Shell->hasTask('Sample'));
  572. $this->assertFalse($this->Shell->hasTask('random'));
  573. $this->assertTrue($this->Shell->hasTask('testApple'));
  574. $this->assertTrue($this->Shell->hasTask('TestApple'));
  575. }
  576. /**
  577. * test task loading exception
  578. *
  579. * @return void
  580. */
  581. public function testMissingTaskException()
  582. {
  583. $this->expectException(RuntimeException::class);
  584. $this->expectExceptionMessage('Task `DoesNotExist` not found. Maybe you made a typo or a plugin is missing or not loaded?');
  585. $this->Shell->tasks = ['DoesNotExist'];
  586. $this->Shell->loadTasks();
  587. }
  588. /**
  589. * test the hasMethod
  590. *
  591. * @return void
  592. */
  593. public function testHasMethod()
  594. {
  595. $this->assertTrue($this->Shell->hasMethod('doSomething'));
  596. $this->assertFalse($this->Shell->hasMethod('hr'), 'hr is callable');
  597. $this->assertFalse($this->Shell->hasMethod('_secret'), '_secret is callable');
  598. $this->assertFalse($this->Shell->hasMethod('no_access'), 'no_access is callable');
  599. }
  600. /**
  601. * test run command calling main.
  602. *
  603. * @return void
  604. */
  605. public function testRunCommandMain()
  606. {
  607. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  608. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  609. $shell = $this->getMockBuilder('Cake\Console\Shell')
  610. ->setMethods(['main', 'startup'])
  611. ->setConstructorArgs([$io])
  612. ->getMock();
  613. $shell->expects($this->once())->method('startup');
  614. $shell->expects($this->once())->method('main')
  615. ->with('cakes')
  616. ->will($this->returnValue(true));
  617. $result = $shell->runCommand(['cakes', '--verbose']);
  618. $this->assertTrue($result);
  619. $this->assertSame('main', $shell->command);
  620. }
  621. /**
  622. * test run command calling a real method with no subcommands defined.
  623. *
  624. * @return void
  625. */
  626. public function testRunCommandWithMethod()
  627. {
  628. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  629. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  630. $shell = $this->getMockBuilder('Cake\Console\Shell')
  631. ->setMethods(['hitMe', 'startup'])
  632. ->setConstructorArgs([$io])
  633. ->getMock();
  634. $shell->expects($this->once())->method('startup');
  635. $shell->expects($this->once())->method('hitMe')
  636. ->with('cakes')
  637. ->will($this->returnValue(true));
  638. $result = $shell->runCommand(['hit_me', 'cakes', '--verbose'], true);
  639. $this->assertTrue($result);
  640. $this->assertSame('hit_me', $shell->command);
  641. }
  642. /**
  643. * test that a command called with an extra parameter passed merges the extra parameters
  644. * to the shell's one
  645. * Also tests that if an extra `requested` parameter prevents the welcome message from
  646. * being displayed
  647. *
  648. * @return void
  649. */
  650. public function testRunCommandWithExtra()
  651. {
  652. $Parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  653. ->setMethods(['help'])
  654. ->setConstructorArgs(['knife'])
  655. ->getMock();
  656. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  657. $Shell = $this->getMockBuilder('Cake\Console\Shell')
  658. ->setMethods(['getOptionParser', 'slice', '_welcome', 'param'])
  659. ->setConstructorArgs([$io])
  660. ->getMock();
  661. $Parser->addSubCommand('slice');
  662. $Shell->expects($this->once())
  663. ->method('getOptionParser')
  664. ->will($this->returnValue($Parser));
  665. $Shell->expects($this->once())
  666. ->method('slice')
  667. ->with('cakes');
  668. $Shell->expects($this->never())->method('_welcome');
  669. $Shell->expects($this->once())->method('param')
  670. ->with('requested')
  671. ->will($this->returnValue(true));
  672. $Shell->runCommand(['slice', 'cakes'], false, ['requested' => true]);
  673. }
  674. /**
  675. * Test the dispatchShell() arguments parser
  676. *
  677. * @return void
  678. */
  679. public function testDispatchShellArgsParser()
  680. {
  681. $Shell = new Shell();
  682. $expected = [['schema', 'create', 'DbAcl'], []];
  683. // Shell::dispatchShell('schema create DbAcl');
  684. $result = $Shell->parseDispatchArguments(['schema create DbAcl']);
  685. $this->assertEquals($expected, $result);
  686. // Shell::dispatchShell('schema', 'create', 'DbAcl');
  687. $result = $Shell->parseDispatchArguments(['schema', 'create', 'DbAcl']);
  688. $this->assertEquals($expected, $result);
  689. // Shell::dispatchShell(['command' => 'schema create DbAcl']);
  690. $result = $Shell->parseDispatchArguments([[
  691. 'command' => 'schema create DbAcl',
  692. ]]);
  693. $this->assertEquals($expected, $result);
  694. // Shell::dispatchShell(['command' => ['schema', 'create', 'DbAcl']]);
  695. $result = $Shell->parseDispatchArguments([[
  696. 'command' => ['schema', 'create', 'DbAcl'],
  697. ]]);
  698. $this->assertEquals($expected, $result);
  699. $expected[1] = ['param' => 'value'];
  700. // Shell::dispatchShell(['command' => 'schema create DbAcl', 'extra' => ['param' => 'value']]);
  701. $result = $Shell->parseDispatchArguments([[
  702. 'command' => 'schema create DbAcl',
  703. 'extra' => ['param' => 'value'],
  704. ]]);
  705. $this->assertEquals($expected, $result);
  706. // Shell::dispatchShell(['command' => ['schema', 'create', 'DbAcl'], 'extra' => ['param' => 'value']]);
  707. $result = $Shell->parseDispatchArguments([[
  708. 'command' => ['schema', 'create', 'DbAcl'],
  709. 'extra' => ['param' => 'value'],
  710. ]]);
  711. $this->assertEquals($expected, $result);
  712. }
  713. /**
  714. * test calling a shell that dispatch another one
  715. *
  716. * @return void
  717. */
  718. public function testDispatchShell()
  719. {
  720. $Shell = new TestingDispatchShell();
  721. ob_start();
  722. $Shell->runCommand(['test_task'], true);
  723. $result = ob_get_clean();
  724. $expected = <<<TEXT
  725. <info>Welcome to CakePHP Console</info>
  726. I am a test task, I dispatch another Shell
  727. I am a dispatched Shell
  728. TEXT;
  729. $this->assertEquals($expected, $result);
  730. ob_start();
  731. $Shell->runCommand(['test_task_dispatch_array'], true);
  732. $result = ob_get_clean();
  733. $this->assertEquals($expected, $result);
  734. ob_start();
  735. $Shell->runCommand(['test_task_dispatch_command_string'], true);
  736. $result = ob_get_clean();
  737. $this->assertEquals($expected, $result);
  738. ob_start();
  739. $Shell->runCommand(['test_task_dispatch_command_array'], true);
  740. $result = ob_get_clean();
  741. $this->assertEquals($expected, $result);
  742. $expected = <<<TEXT
  743. <info>Welcome to CakePHP Console</info>
  744. I am a test task, I dispatch another Shell
  745. I am a dispatched Shell. My param `foo` has the value `bar`
  746. TEXT;
  747. ob_start();
  748. $Shell->runCommand(['test_task_dispatch_with_param'], true);
  749. $result = ob_get_clean();
  750. $this->assertEquals($expected, $result);
  751. $expected = <<<TEXT
  752. <info>Welcome to CakePHP Console</info>
  753. I am a test task, I dispatch another Shell
  754. I am a dispatched Shell. My param `foo` has the value `bar`
  755. My param `fooz` has the value `baz`
  756. TEXT;
  757. ob_start();
  758. $Shell->runCommand(['test_task_dispatch_with_multiple_params'], true);
  759. $result = ob_get_clean();
  760. $this->assertEquals($expected, $result);
  761. $expected = <<<TEXT
  762. <info>Welcome to CakePHP Console</info>
  763. I am a test task, I dispatch another Shell
  764. <info>Welcome to CakePHP Console</info>
  765. I am a dispatched Shell
  766. TEXT;
  767. ob_start();
  768. $Shell->runCommand(['test_task_dispatch_with_requested_off'], true);
  769. $result = ob_get_clean();
  770. $this->assertEquals($expected, $result);
  771. }
  772. /**
  773. * Test that runCommand() doesn't call public methods when the second arg is false.
  774. *
  775. * @return void
  776. */
  777. public function testRunCommandAutoMethodOff()
  778. {
  779. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  780. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  781. $shell = $this->getMockBuilder('Cake\Console\Shell')
  782. ->setMethods(['hit_me', 'startup'])
  783. ->setConstructorArgs([$io])
  784. ->getMock();
  785. $shell->expects($this->never())->method('startup');
  786. $shell->expects($this->never())->method('hit_me');
  787. $result = $shell->runCommand(['hit_me', 'baseball'], false);
  788. $this->assertFalse($result);
  789. $result = $shell->runCommand(['hit_me', 'baseball']);
  790. $this->assertFalse($result, 'Default value of runCommand() should be false');
  791. }
  792. /**
  793. * test run command calling a real method with mismatching subcommands defined.
  794. *
  795. * @return void
  796. */
  797. public function testRunCommandWithMethodNotInSubcommands()
  798. {
  799. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  800. ->setMethods(['help'])
  801. ->setConstructorArgs(['knife'])
  802. ->getMock();
  803. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  804. $shell = $this->getMockBuilder('Cake\Console\Shell')
  805. ->setMethods(['getOptionParser', 'roll', 'startup'])
  806. ->setConstructorArgs([$io])
  807. ->getMock();
  808. $parser->addSubCommand('slice');
  809. $shell->expects($this->any())
  810. ->method('getOptionParser')
  811. ->will($this->returnValue($parser));
  812. $parser->expects($this->once())
  813. ->method('help');
  814. $shell->expects($this->never())->method('startup');
  815. $shell->expects($this->never())->method('roll');
  816. $result = $shell->runCommand(['roll', 'cakes', '--verbose']);
  817. $this->assertFalse($result);
  818. }
  819. /**
  820. * test run command calling a real method with subcommands defined.
  821. *
  822. * @return void
  823. */
  824. public function testRunCommandWithMethodInSubcommands()
  825. {
  826. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  827. ->setMethods(['help'])
  828. ->setConstructorArgs(['knife'])
  829. ->getMock();
  830. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  831. $shell = $this->getMockBuilder('Cake\Console\Shell')
  832. ->setMethods(['getOptionParser', 'slice', 'startup'])
  833. ->setConstructorArgs([$io])
  834. ->getMock();
  835. $parser->addSubCommand('slice');
  836. $shell->expects($this->any())
  837. ->method('getOptionParser')
  838. ->will($this->returnValue($parser));
  839. $shell->expects($this->once())->method('startup');
  840. $shell->expects($this->once())
  841. ->method('slice')
  842. ->with('cakes');
  843. $shell->runCommand(['slice', 'cakes', '--verbose']);
  844. }
  845. /**
  846. * test run command calling a missing method with subcommands defined.
  847. *
  848. * @return void
  849. */
  850. public function testRunCommandWithMissingMethodInSubcommands()
  851. {
  852. /** @var \Cake\Console\ConsoleOptionParser|\PHPUnit\Framework\MockObject\MockObject $parser */
  853. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  854. ->setMethods(['help'])
  855. ->setConstructorArgs(['knife'])
  856. ->getMock();
  857. $parser->addSubCommand('slice');
  858. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  859. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  860. $shell = $this->getMockBuilder('Cake\Console\Shell')
  861. ->setMethods(['getOptionParser', 'startup'])
  862. ->setConstructorArgs([$io])
  863. ->getMock();
  864. $shell->expects($this->any())
  865. ->method('getOptionParser')
  866. ->will($this->returnValue($parser));
  867. $shell->expects($this->never())
  868. ->method('startup');
  869. $parser->expects($this->once())
  870. ->method('help');
  871. $shell->runCommand(['slice', 'cakes', '--verbose']);
  872. }
  873. /**
  874. * test run command causing exception on Shell method.
  875. *
  876. * @return void
  877. */
  878. public function testRunCommandBaseClassMethod()
  879. {
  880. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  881. $shell = $this->getMockBuilder('Cake\Console\Shell')
  882. ->setMethods(['startup', 'getOptionParser', 'hr'])
  883. ->disableOriginalConstructor()
  884. ->getMock();
  885. $shell->setIo(
  886. $this->getMockBuilder('Cake\Console\ConsoleIo')
  887. ->setMethods(['err'])
  888. ->getMock()
  889. );
  890. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  891. ->disableOriginalConstructor()
  892. ->getMock();
  893. $parser->expects($this->once())->method('help');
  894. $parser->method('parse')
  895. ->will($this->returnValue([[], []]));
  896. $shell->expects($this->once())->method('getOptionParser')
  897. ->will($this->returnValue($parser));
  898. $shell->expects($this->never())->method('hr');
  899. $shell->_io->expects($this->exactly(2))->method('err');
  900. $shell->runCommand(['hr']);
  901. }
  902. /**
  903. * test run command causing exception on Shell method.
  904. *
  905. * @return void
  906. */
  907. public function testRunCommandMissingMethod()
  908. {
  909. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  910. $shell = $this->getMockBuilder('Cake\Console\Shell')
  911. ->setMethods(['startup', 'getOptionParser', 'hr'])
  912. ->disableOriginalConstructor()
  913. ->getMock();
  914. $shell->setIo(
  915. $this->getMockBuilder('Cake\Console\ConsoleIo')
  916. ->setMethods(['err'])
  917. ->getMock()
  918. );
  919. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  920. ->disableOriginalConstructor()
  921. ->getMock();
  922. $parser->expects($this->once())->method('help');
  923. $parser->method('parse')
  924. ->will($this->returnValue([[], []]));
  925. $shell->expects($this->once())->method('getOptionParser')
  926. ->will($this->returnValue($parser));
  927. $shell->_io->expects($this->exactly(2))->method('err');
  928. $result = $shell->runCommand(['idontexist']);
  929. $this->assertFalse($result);
  930. }
  931. /**
  932. * test that a --help causes help to show.
  933. *
  934. * @return void
  935. */
  936. public function testRunCommandTriggeringHelp()
  937. {
  938. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  939. ->disableOriginalConstructor()
  940. ->getMock();
  941. $parser->expects($this->once())->method('parse')
  942. ->with(['--help'])
  943. ->will($this->returnValue([['help' => true], []]));
  944. $parser->expects($this->once())->method('help');
  945. $shell = $this->getMockBuilder('Cake\Console\Shell')
  946. ->setMethods(['getOptionParser', 'out', 'startup', '_welcome'])
  947. ->disableOriginalConstructor()
  948. ->getMock();
  949. $shell->setIo($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
  950. $shell->expects($this->once())->method('getOptionParser')
  951. ->will($this->returnValue($parser));
  952. $shell->expects($this->once())->method('out');
  953. $shell->runCommand(['--help']);
  954. }
  955. /**
  956. * test that runCommand will not call runCommand on tasks that are not subcommands.
  957. *
  958. * @return void
  959. */
  960. public function testRunCommandNotCallUnexposedTask()
  961. {
  962. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  963. $shell = $this->getMockBuilder('Cake\Console\Shell')
  964. ->setMethods(['startup', 'hasTask'])
  965. ->disableOriginalConstructor()
  966. ->getMock();
  967. $shell->setIo(
  968. $this->getMockBuilder('Cake\Console\ConsoleIo')
  969. ->setMethods(['err'])
  970. ->getMock()
  971. );
  972. $task = $this->getMockBuilder('Cake\Console\Shell')
  973. ->setMethods(['runCommand'])
  974. ->disableOriginalConstructor()
  975. ->getMock();
  976. $task->expects($this->never())
  977. ->method('runCommand');
  978. $shell->expects($this->any())
  979. ->method('hasTask')
  980. ->will($this->returnValue(true));
  981. $shell->expects($this->never())->method('startup');
  982. $shell->_io->expects($this->exactly(2))->method('err');
  983. $shell->RunCommand = $task;
  984. $result = $shell->runCommand(['run_command', 'one']);
  985. $this->assertFalse($result);
  986. }
  987. /**
  988. * test that runCommand will call runCommand on the task.
  989. *
  990. * @return void
  991. */
  992. public function testRunCommandHittingTaskInSubcommand()
  993. {
  994. $parser = new ConsoleOptionParser('knife');
  995. $parser->addSubcommand('slice');
  996. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  997. $shell = $this->getMockBuilder('Cake\Console\Shell')
  998. ->setMethods(['hasTask', 'startup', 'getOptionParser'])
  999. ->disableOriginalConstructor()
  1000. ->getMock();
  1001. $shell->setIo($io);
  1002. $task = $this->getMockBuilder('Cake\Console\Shell')
  1003. ->setMethods(['main', 'runCommand'])
  1004. ->disableOriginalConstructor()
  1005. ->getMock();
  1006. $task->setIo($io);
  1007. $task->expects($this->once())
  1008. ->method('runCommand')
  1009. ->with(['one'], false, ['requested' => true]);
  1010. $shell->expects($this->once())->method('getOptionParser')
  1011. ->will($this->returnValue($parser));
  1012. $shell->expects($this->once())->method('startup');
  1013. $shell->expects($this->any())
  1014. ->method('hasTask')
  1015. ->will($this->returnValue(true));
  1016. $shell->Slice = $task;
  1017. $shell->runCommand(['slice', 'one']);
  1018. }
  1019. /**
  1020. * test that runCommand will invoke a task
  1021. *
  1022. * @return void
  1023. */
  1024. public function testRunCommandInvokeTask()
  1025. {
  1026. $parser = new ConsoleOptionParser('knife');
  1027. $parser->addSubcommand('slice');
  1028. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  1029. $shell = $this->getMockBuilder('Cake\Console\Shell')
  1030. ->setMethods(['hasTask', 'getOptionParser'])
  1031. ->setConstructorArgs([$io])
  1032. ->getMock();
  1033. $task = $this->getMockBuilder('Cake\Console\Shell')
  1034. ->setMethods(['main', '_welcome'])
  1035. ->setConstructorArgs([$io])
  1036. ->getMock();
  1037. $shell->expects($this->once())
  1038. ->method('getOptionParser')
  1039. ->will($this->returnValue($parser));
  1040. $shell->expects($this->any())
  1041. ->method('hasTask')
  1042. ->will($this->returnValue(true));
  1043. $task->expects($this->never())
  1044. ->method('_welcome');
  1045. $shell->Slice = $task;
  1046. $shell->runCommand(['slice', 'one']);
  1047. $this->assertTrue($task->params['requested'], 'Task is requested, no welcome.');
  1048. }
  1049. /**
  1050. * test run command missing parameters
  1051. *
  1052. * @return void
  1053. */
  1054. public function testRunCommandMainMissingArgument()
  1055. {
  1056. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  1057. $shell = $this->getMockBuilder('Cake\Console\Shell')
  1058. ->setMethods(['main', 'startup', 'getOptionParser'])
  1059. ->setConstructorArgs([$io])
  1060. ->getMock();
  1061. $parser = new ConsoleOptionParser('test');
  1062. $parser->addArgument('filename', [
  1063. 'required' => true,
  1064. 'help' => 'a file',
  1065. ]);
  1066. $shell->expects($this->once())
  1067. ->method('getOptionParser')
  1068. ->will($this->returnValue($parser));
  1069. $shell->expects($this->never())->method('main');
  1070. $io->expects($this->once())
  1071. ->method('error')
  1072. ->with('Error: Missing required arguments. The `filename` argument is required.');
  1073. $result = $shell->runCommand([]);
  1074. $this->assertFalse($result, 'Shell should fail');
  1075. }
  1076. /**
  1077. * test wrapBlock wrapping text.
  1078. *
  1079. * @return void
  1080. */
  1081. public function testWrapText()
  1082. {
  1083. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  1084. $result = $this->Shell->wrapText($text, ['width' => 33]);
  1085. $expected = <<<TEXT
  1086. This is the song that never ends.
  1087. This is the song that never ends.
  1088. This is the song that never ends.
  1089. TEXT;
  1090. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  1091. $result = $this->Shell->wrapText($text, ['indent' => ' ', 'width' => 33]);
  1092. $expected = <<<TEXT
  1093. This is the song that never ends.
  1094. This is the song that never ends.
  1095. This is the song that never ends.
  1096. TEXT;
  1097. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  1098. }
  1099. /**
  1100. * Testing camel cased naming of tasks
  1101. *
  1102. * @return void
  1103. */
  1104. public function testShellNaming()
  1105. {
  1106. $this->Shell->tasks = ['TestApple'];
  1107. $this->Shell->loadTasks();
  1108. $expected = 'TestApple';
  1109. $this->assertEquals($expected, $this->Shell->TestApple->name);
  1110. }
  1111. /**
  1112. * Test reading params
  1113. *
  1114. * @dataProvider paramReadingDataProvider
  1115. */
  1116. public function testParamReading($toRead, $expected)
  1117. {
  1118. $this->Shell->params = [
  1119. 'key' => 'value',
  1120. 'help' => false,
  1121. 'emptykey' => '',
  1122. 'truthy' => true,
  1123. ];
  1124. $this->assertSame($expected, $this->Shell->param($toRead));
  1125. }
  1126. /**
  1127. * Data provider for testing reading values with Shell::param()
  1128. *
  1129. * @return array
  1130. */
  1131. public function paramReadingDataProvider()
  1132. {
  1133. return [
  1134. [
  1135. 'key',
  1136. 'value',
  1137. ],
  1138. [
  1139. 'help',
  1140. false,
  1141. ],
  1142. [
  1143. 'emptykey',
  1144. '',
  1145. ],
  1146. [
  1147. 'truthy',
  1148. true,
  1149. ],
  1150. [
  1151. 'does_not_exist',
  1152. null,
  1153. ],
  1154. ];
  1155. }
  1156. /**
  1157. * Test that option parsers are created with the correct name/command.
  1158. *
  1159. * @return void
  1160. */
  1161. public function testGetOptionParser()
  1162. {
  1163. $this->Shell->name = 'test';
  1164. $this->Shell->plugin = 'plugin';
  1165. $parser = $this->Shell->getOptionParser();
  1166. $this->assertSame('plugin.test', $parser->getCommand());
  1167. }
  1168. /**
  1169. * Test file and console and logging quiet output
  1170. *
  1171. * @return void
  1172. */
  1173. public function testQuietLog()
  1174. {
  1175. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')
  1176. ->disableOriginalConstructor()
  1177. ->getMock();
  1178. $io->expects($this->once())
  1179. ->method('level')
  1180. ->with(Shell::QUIET);
  1181. $io->expects($this->at(0))
  1182. ->method('setLoggers')
  1183. ->with(true);
  1184. $io->expects($this->at(2))
  1185. ->method('setLoggers')
  1186. ->with(ConsoleIo::QUIET);
  1187. $this->Shell = $this->getMockBuilder(ShellTestShell::class)
  1188. ->setMethods(['welcome'])
  1189. ->setConstructorArgs([$io])
  1190. ->getMock();
  1191. $this->Shell->runCommand(['foo', '--quiet']);
  1192. }
  1193. /**
  1194. * Test getIo() and setIo() methods
  1195. *
  1196. * @return void
  1197. */
  1198. public function testGetSetIo()
  1199. {
  1200. $this->Shell->setIo($this->io);
  1201. $this->assertSame($this->Shell->getIo(), $this->io);
  1202. }
  1203. /**
  1204. * Test setRootName filters into the option parser help text.
  1205. *
  1206. * @return void
  1207. */
  1208. public function testSetRootNamePropagatesToHelpText()
  1209. {
  1210. $this->assertSame($this->Shell, $this->Shell->setRootName('tool'), 'is chainable');
  1211. $this->assertStringContainsString('tool shell_test_shell [-h]', $this->Shell->getOptionParser()->help());
  1212. }
  1213. /**
  1214. * Tests __debugInfo
  1215. *
  1216. * @return void
  1217. */
  1218. public function testDebugInfo()
  1219. {
  1220. $expected = [
  1221. 'name' => 'ShellTestShell',
  1222. 'plugin' => null,
  1223. 'command' => null,
  1224. 'tasks' => [],
  1225. 'params' => [],
  1226. 'args' => [],
  1227. 'interactive' => true,
  1228. ];
  1229. $result = $this->Shell->__debugInfo();
  1230. $this->assertEquals($expected, $result);
  1231. }
  1232. }