ShellTest.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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.Tags',
  45. 'core.ArticlesTags',
  46. 'core.Attachments',
  47. 'core.Comments',
  48. 'core.Posts',
  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->once())
  145. ->method('askChoice')
  146. ->with('Just a test?', ['y', 'n'], 'n')
  147. ->will($this->returnValue('n'));
  148. $this->io->expects($this->once())
  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->once())
  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->assertFileDoesNotExist($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. ->onlyMethods(['startup'])
  611. ->addMethods(['main'])
  612. ->setConstructorArgs([$io])
  613. ->getMock();
  614. $shell->expects($this->once())->method('startup');
  615. $shell->expects($this->once())->method('main')
  616. ->with('cakes')
  617. ->will($this->returnValue(true));
  618. $result = $shell->runCommand(['cakes', '--verbose']);
  619. $this->assertTrue($result);
  620. $this->assertSame('main', $shell->command);
  621. }
  622. /**
  623. * test run command calling a real method with no subcommands defined.
  624. *
  625. * @return void
  626. */
  627. public function testRunCommandWithMethod()
  628. {
  629. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  630. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  631. $shell = $this->getMockBuilder('Cake\Console\Shell')
  632. ->onlyMethods(['startup'])
  633. ->addMethods(['hitMe'])
  634. ->setConstructorArgs([$io])
  635. ->getMock();
  636. $shell->expects($this->once())->method('startup');
  637. $shell->expects($this->once())->method('hitMe')
  638. ->with('cakes')
  639. ->will($this->returnValue(true));
  640. $result = $shell->runCommand(['hit_me', 'cakes', '--verbose'], true);
  641. $this->assertTrue($result);
  642. $this->assertSame('hit_me', $shell->command);
  643. }
  644. /**
  645. * test that a command called with an extra parameter passed merges the extra parameters
  646. * to the shell's one
  647. * Also tests that if an extra `requested` parameter prevents the welcome message from
  648. * being displayed
  649. *
  650. * @return void
  651. */
  652. public function testRunCommandWithExtra()
  653. {
  654. $Parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  655. ->onlyMethods(['help'])
  656. ->setConstructorArgs(['knife'])
  657. ->getMock();
  658. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  659. $Shell = $this->getMockBuilder('Cake\Console\Shell')
  660. ->onlyMethods(['getOptionParser', '_welcome', 'param'])
  661. ->addMethods(['slice'])
  662. ->setConstructorArgs([$io])
  663. ->getMock();
  664. $Parser->addSubCommand('slice');
  665. $Shell->expects($this->once())
  666. ->method('getOptionParser')
  667. ->will($this->returnValue($Parser));
  668. $Shell->expects($this->once())
  669. ->method('slice')
  670. ->with('cakes');
  671. $Shell->expects($this->never())->method('_welcome');
  672. $Shell->expects($this->once())->method('param')
  673. ->with('requested')
  674. ->will($this->returnValue(true));
  675. $Shell->runCommand(['slice', 'cakes'], false, ['requested' => true]);
  676. }
  677. /**
  678. * Test the dispatchShell() arguments parser
  679. *
  680. * @return void
  681. */
  682. public function testDispatchShellArgsParser()
  683. {
  684. $Shell = new Shell();
  685. $expected = [['schema', 'create', 'DbAcl'], []];
  686. // Shell::dispatchShell('schema create DbAcl');
  687. $result = $Shell->parseDispatchArguments(['schema create DbAcl']);
  688. $this->assertEquals($expected, $result);
  689. // Shell::dispatchShell('schema', 'create', 'DbAcl');
  690. $result = $Shell->parseDispatchArguments(['schema', 'create', 'DbAcl']);
  691. $this->assertEquals($expected, $result);
  692. // Shell::dispatchShell(['command' => 'schema create DbAcl']);
  693. $result = $Shell->parseDispatchArguments([[
  694. 'command' => 'schema create DbAcl',
  695. ]]);
  696. $this->assertEquals($expected, $result);
  697. // Shell::dispatchShell(['command' => ['schema', 'create', 'DbAcl']]);
  698. $result = $Shell->parseDispatchArguments([[
  699. 'command' => ['schema', 'create', 'DbAcl'],
  700. ]]);
  701. $this->assertEquals($expected, $result);
  702. $expected[1] = ['param' => 'value'];
  703. // Shell::dispatchShell(['command' => 'schema create DbAcl', 'extra' => ['param' => 'value']]);
  704. $result = $Shell->parseDispatchArguments([[
  705. 'command' => 'schema create DbAcl',
  706. 'extra' => ['param' => 'value'],
  707. ]]);
  708. $this->assertEquals($expected, $result);
  709. // Shell::dispatchShell(['command' => ['schema', 'create', 'DbAcl'], 'extra' => ['param' => 'value']]);
  710. $result = $Shell->parseDispatchArguments([[
  711. 'command' => ['schema', 'create', 'DbAcl'],
  712. 'extra' => ['param' => 'value'],
  713. ]]);
  714. $this->assertEquals($expected, $result);
  715. }
  716. /**
  717. * test calling a shell that dispatch another one
  718. *
  719. * @return void
  720. */
  721. public function testDispatchShell()
  722. {
  723. $Shell = new TestingDispatchShell();
  724. ob_start();
  725. $Shell->runCommand(['test_task'], true);
  726. $result = ob_get_clean();
  727. $expected = <<<TEXT
  728. <info>Welcome to CakePHP Console</info>
  729. I am a test task, I dispatch another Shell
  730. I am a dispatched Shell
  731. TEXT;
  732. $this->assertSame($expected, $result);
  733. ob_start();
  734. $Shell->runCommand(['test_task_dispatch_array'], true);
  735. $result = ob_get_clean();
  736. $this->assertSame($expected, $result);
  737. ob_start();
  738. $Shell->runCommand(['test_task_dispatch_command_string'], true);
  739. $result = ob_get_clean();
  740. $this->assertSame($expected, $result);
  741. ob_start();
  742. $Shell->runCommand(['test_task_dispatch_command_array'], true);
  743. $result = ob_get_clean();
  744. $this->assertSame($expected, $result);
  745. $expected = <<<TEXT
  746. <info>Welcome to CakePHP Console</info>
  747. I am a test task, I dispatch another Shell
  748. I am a dispatched Shell. My param `foo` has the value `bar`
  749. TEXT;
  750. ob_start();
  751. $Shell->runCommand(['test_task_dispatch_with_param'], true);
  752. $result = ob_get_clean();
  753. $this->assertSame($expected, $result);
  754. $expected = <<<TEXT
  755. <info>Welcome to CakePHP Console</info>
  756. I am a test task, I dispatch another Shell
  757. I am a dispatched Shell. My param `foo` has the value `bar`
  758. My param `fooz` has the value `baz`
  759. TEXT;
  760. ob_start();
  761. $Shell->runCommand(['test_task_dispatch_with_multiple_params'], true);
  762. $result = ob_get_clean();
  763. $this->assertSame($expected, $result);
  764. $expected = <<<TEXT
  765. <info>Welcome to CakePHP Console</info>
  766. I am a test task, I dispatch another Shell
  767. <info>Welcome to CakePHP Console</info>
  768. I am a dispatched Shell
  769. TEXT;
  770. ob_start();
  771. $Shell->runCommand(['test_task_dispatch_with_requested_off'], true);
  772. $result = ob_get_clean();
  773. $this->assertSame($expected, $result);
  774. }
  775. /**
  776. * Test that runCommand() doesn't call public methods when the second arg is false.
  777. *
  778. * @return void
  779. */
  780. public function testRunCommandAutoMethodOff()
  781. {
  782. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  783. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  784. $shell = $this->getMockBuilder('Cake\Console\Shell')
  785. ->onlyMethods(['startup'])
  786. ->addMethods(['hit_me'])
  787. ->setConstructorArgs([$io])
  788. ->getMock();
  789. $shell->expects($this->never())->method('startup');
  790. $shell->expects($this->never())->method('hit_me');
  791. $result = $shell->runCommand(['hit_me', 'baseball'], false);
  792. $this->assertFalse($result);
  793. $result = $shell->runCommand(['hit_me', 'baseball']);
  794. $this->assertFalse($result, 'Default value of runCommand() should be false');
  795. }
  796. /**
  797. * test run command calling a real method with mismatching subcommands defined.
  798. *
  799. * @return void
  800. */
  801. public function testRunCommandWithMethodNotInSubcommands()
  802. {
  803. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  804. ->onlyMethods(['help'])
  805. ->setConstructorArgs(['knife'])
  806. ->getMock();
  807. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  808. $shell = $this->getMockBuilder('Cake\Console\Shell')
  809. ->onlyMethods(['getOptionParser', 'startup'])
  810. ->addMethods(['roll'])
  811. ->setConstructorArgs([$io])
  812. ->getMock();
  813. $parser->addSubCommand('slice');
  814. $shell->expects($this->any())
  815. ->method('getOptionParser')
  816. ->will($this->returnValue($parser));
  817. $parser->expects($this->once())
  818. ->method('help');
  819. $shell->expects($this->never())->method('startup');
  820. $shell->expects($this->never())->method('roll');
  821. $result = $shell->runCommand(['roll', 'cakes', '--verbose']);
  822. $this->assertFalse($result);
  823. }
  824. /**
  825. * test run command calling a real method with subcommands defined.
  826. *
  827. * @return void
  828. */
  829. public function testRunCommandWithMethodInSubcommands()
  830. {
  831. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  832. ->onlyMethods(['help'])
  833. ->setConstructorArgs(['knife'])
  834. ->getMock();
  835. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  836. $shell = $this->getMockBuilder('Cake\Console\Shell')
  837. ->onlyMethods(['getOptionParser', 'startup'])
  838. ->addMethods(['slice'])
  839. ->setConstructorArgs([$io])
  840. ->getMock();
  841. $parser->addSubCommand('slice');
  842. $shell->expects($this->any())
  843. ->method('getOptionParser')
  844. ->will($this->returnValue($parser));
  845. $shell->expects($this->once())->method('startup');
  846. $shell->expects($this->once())
  847. ->method('slice')
  848. ->with('cakes');
  849. $shell->runCommand(['slice', 'cakes', '--verbose']);
  850. }
  851. /**
  852. * test run command calling a missing method with subcommands defined.
  853. *
  854. * @return void
  855. */
  856. public function testRunCommandWithMissingMethodInSubcommands()
  857. {
  858. /** @var \Cake\Console\ConsoleOptionParser|\PHPUnit\Framework\MockObject\MockObject $parser */
  859. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  860. ->onlyMethods(['help'])
  861. ->setConstructorArgs(['knife'])
  862. ->getMock();
  863. $parser->addSubCommand('slice');
  864. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  865. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  866. $shell = $this->getMockBuilder('Cake\Console\Shell')
  867. ->onlyMethods(['getOptionParser', 'startup'])
  868. ->setConstructorArgs([$io])
  869. ->getMock();
  870. $shell->expects($this->any())
  871. ->method('getOptionParser')
  872. ->will($this->returnValue($parser));
  873. $shell->expects($this->never())
  874. ->method('startup');
  875. $parser->expects($this->once())
  876. ->method('help');
  877. $shell->runCommand(['slice', 'cakes', '--verbose']);
  878. }
  879. /**
  880. * test run command causing exception on Shell method.
  881. *
  882. * @return void
  883. */
  884. public function testRunCommandBaseClassMethod()
  885. {
  886. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  887. $shell = $this->getMockBuilder('Cake\Console\Shell')
  888. ->onlyMethods(['startup', 'getOptionParser', 'hr'])
  889. ->disableOriginalConstructor()
  890. ->getMock();
  891. $shell->setIo(
  892. $this->getMockBuilder('Cake\Console\ConsoleIo')
  893. ->onlyMethods(['err'])
  894. ->getMock()
  895. );
  896. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  897. ->disableOriginalConstructor()
  898. ->getMock();
  899. $parser->expects($this->once())->method('help');
  900. $parser->method('parse')
  901. ->will($this->returnValue([[], []]));
  902. $shell->expects($this->once())->method('getOptionParser')
  903. ->will($this->returnValue($parser));
  904. $shell->expects($this->never())->method('hr');
  905. $shell->_io->expects($this->exactly(2))->method('err');
  906. $shell->runCommand(['hr']);
  907. }
  908. /**
  909. * test run command causing exception on Shell method.
  910. *
  911. * @return void
  912. */
  913. public function testRunCommandMissingMethod()
  914. {
  915. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  916. $shell = $this->getMockBuilder('Cake\Console\Shell')
  917. ->onlyMethods(['startup', 'getOptionParser', 'hr'])
  918. ->disableOriginalConstructor()
  919. ->getMock();
  920. $shell->setIo(
  921. $this->getMockBuilder('Cake\Console\ConsoleIo')
  922. ->onlyMethods(['err'])
  923. ->getMock()
  924. );
  925. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  926. ->disableOriginalConstructor()
  927. ->getMock();
  928. $parser->expects($this->once())->method('help');
  929. $parser->method('parse')
  930. ->will($this->returnValue([[], []]));
  931. $shell->expects($this->once())->method('getOptionParser')
  932. ->will($this->returnValue($parser));
  933. $shell->_io->expects($this->exactly(2))->method('err');
  934. $result = $shell->runCommand(['idontexist']);
  935. $this->assertFalse($result);
  936. }
  937. /**
  938. * test that a --help causes help to show.
  939. *
  940. * @return void
  941. */
  942. public function testRunCommandTriggeringHelp()
  943. {
  944. $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
  945. ->disableOriginalConstructor()
  946. ->getMock();
  947. $parser->expects($this->once())->method('parse')
  948. ->with(['--help'])
  949. ->will($this->returnValue([['help' => true], []]));
  950. $parser->expects($this->once())->method('help');
  951. $shell = $this->getMockBuilder('Cake\Console\Shell')
  952. ->onlyMethods(['getOptionParser', 'out', 'startup', '_welcome'])
  953. ->disableOriginalConstructor()
  954. ->getMock();
  955. $shell->setIo($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
  956. $shell->expects($this->once())->method('getOptionParser')
  957. ->will($this->returnValue($parser));
  958. $shell->expects($this->once())->method('out');
  959. $shell->runCommand(['--help']);
  960. }
  961. /**
  962. * test that runCommand will not call runCommand on tasks that are not subcommands.
  963. *
  964. * @return void
  965. */
  966. public function testRunCommandNotCallUnexposedTask()
  967. {
  968. /** @var \Cake\Console\Shell|\PHPUnit\Framework\MockObject\MockObject $shell */
  969. $shell = $this->getMockBuilder('Cake\Console\Shell')
  970. ->onlyMethods(['startup', 'hasTask'])
  971. ->disableOriginalConstructor()
  972. ->getMock();
  973. $shell->setIo(
  974. $this->getMockBuilder('Cake\Console\ConsoleIo')
  975. ->onlyMethods(['err'])
  976. ->getMock()
  977. );
  978. $task = $this->getMockBuilder('Cake\Console\Shell')
  979. ->onlyMethods(['runCommand'])
  980. ->disableOriginalConstructor()
  981. ->getMock();
  982. $task->expects($this->never())
  983. ->method('runCommand');
  984. $shell->expects($this->any())
  985. ->method('hasTask')
  986. ->will($this->returnValue(true));
  987. $shell->expects($this->never())->method('startup');
  988. $shell->_io->expects($this->exactly(2))->method('err');
  989. $shell->RunCommand = $task;
  990. $result = $shell->runCommand(['run_command', 'one']);
  991. $this->assertFalse($result);
  992. }
  993. /**
  994. * test that runCommand will call runCommand on the task.
  995. *
  996. * @return void
  997. */
  998. public function testRunCommandHittingTaskInSubcommand()
  999. {
  1000. $parser = new ConsoleOptionParser('knife');
  1001. $parser->addSubcommand('slice');
  1002. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  1003. $shell = $this->getMockBuilder('Cake\Console\Shell')
  1004. ->onlyMethods(['hasTask', 'startup', 'getOptionParser'])
  1005. ->disableOriginalConstructor()
  1006. ->getMock();
  1007. $shell->setIo($io);
  1008. $task = $this->getMockBuilder('Cake\Console\Shell')
  1009. ->onlyMethods(['runCommand'])
  1010. ->addMethods(['main'])
  1011. ->disableOriginalConstructor()
  1012. ->getMock();
  1013. $task->setIo($io);
  1014. $task->expects($this->once())
  1015. ->method('runCommand')
  1016. ->with(['one'], false, ['requested' => true]);
  1017. $shell->expects($this->once())->method('getOptionParser')
  1018. ->will($this->returnValue($parser));
  1019. $shell->expects($this->once())->method('startup');
  1020. $shell->expects($this->any())
  1021. ->method('hasTask')
  1022. ->will($this->returnValue(true));
  1023. $shell->Slice = $task;
  1024. $shell->runCommand(['slice', 'one']);
  1025. }
  1026. /**
  1027. * test that runCommand will invoke a task
  1028. *
  1029. * @return void
  1030. */
  1031. public function testRunCommandInvokeTask()
  1032. {
  1033. $parser = new ConsoleOptionParser('knife');
  1034. $parser->addSubcommand('slice');
  1035. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  1036. $shell = $this->getMockBuilder('Cake\Console\Shell')
  1037. ->onlyMethods(['hasTask', 'getOptionParser'])
  1038. ->setConstructorArgs([$io])
  1039. ->getMock();
  1040. $task = $this->getMockBuilder('Cake\Console\Shell')
  1041. ->onlyMethods(['_welcome'])
  1042. ->addMethods(['main'])
  1043. ->setConstructorArgs([$io])
  1044. ->getMock();
  1045. $shell->expects($this->once())
  1046. ->method('getOptionParser')
  1047. ->will($this->returnValue($parser));
  1048. $shell->expects($this->any())
  1049. ->method('hasTask')
  1050. ->will($this->returnValue(true));
  1051. $task->expects($this->never())
  1052. ->method('_welcome');
  1053. $shell->Slice = $task;
  1054. $shell->runCommand(['slice', 'one']);
  1055. $this->assertTrue($task->params['requested'], 'Task is requested, no welcome.');
  1056. }
  1057. /**
  1058. * test run command missing parameters
  1059. *
  1060. * @return void
  1061. */
  1062. public function testRunCommandMainMissingArgument()
  1063. {
  1064. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
  1065. $shell = $this->getMockBuilder('Cake\Console\Shell')
  1066. ->onlyMethods(['startup', 'getOptionParser'])
  1067. ->addMethods(['main'])
  1068. ->setConstructorArgs([$io])
  1069. ->getMock();
  1070. $parser = new ConsoleOptionParser('test');
  1071. $parser->addArgument('filename', [
  1072. 'required' => true,
  1073. 'help' => 'a file',
  1074. ]);
  1075. $shell->expects($this->once())
  1076. ->method('getOptionParser')
  1077. ->will($this->returnValue($parser));
  1078. $shell->expects($this->never())->method('main');
  1079. $io->expects($this->once())
  1080. ->method('error')
  1081. ->with('Error: Missing required argument. The `filename` argument is required.');
  1082. $result = $shell->runCommand([]);
  1083. $this->assertFalse($result, 'Shell should fail');
  1084. }
  1085. /**
  1086. * test wrapBlock wrapping text.
  1087. *
  1088. * @return void
  1089. */
  1090. public function testWrapText()
  1091. {
  1092. $text = 'This is the song that never ends. This is the song that never ends. This is the song that never ends.';
  1093. $result = $this->Shell->wrapText($text, ['width' => 33]);
  1094. $expected = <<<TEXT
  1095. This is the song that never ends.
  1096. This is the song that never ends.
  1097. This is the song that never ends.
  1098. TEXT;
  1099. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  1100. $result = $this->Shell->wrapText($text, ['indent' => ' ', 'width' => 33]);
  1101. $expected = <<<TEXT
  1102. This is the song that never ends.
  1103. This is the song that never ends.
  1104. This is the song that never ends.
  1105. TEXT;
  1106. $this->assertTextEquals($expected, $result, 'Text not wrapped.');
  1107. }
  1108. /**
  1109. * Testing camel cased naming of tasks
  1110. *
  1111. * @return void
  1112. */
  1113. public function testShellNaming()
  1114. {
  1115. $this->Shell->tasks = ['TestApple'];
  1116. $this->Shell->loadTasks();
  1117. $expected = 'TestApple';
  1118. $this->assertSame($expected, $this->Shell->TestApple->name);
  1119. }
  1120. /**
  1121. * Test reading params
  1122. *
  1123. * @dataProvider paramReadingDataProvider
  1124. * @param mixed $expected
  1125. */
  1126. public function testParamReading(string $toRead, $expected)
  1127. {
  1128. $this->Shell->params = [
  1129. 'key' => 'value',
  1130. 'help' => false,
  1131. 'emptykey' => '',
  1132. 'truthy' => true,
  1133. ];
  1134. $this->assertSame($expected, $this->Shell->param($toRead));
  1135. }
  1136. /**
  1137. * Data provider for testing reading values with Shell::param()
  1138. *
  1139. * @return array
  1140. */
  1141. public function paramReadingDataProvider()
  1142. {
  1143. return [
  1144. [
  1145. 'key',
  1146. 'value',
  1147. ],
  1148. [
  1149. 'help',
  1150. false,
  1151. ],
  1152. [
  1153. 'emptykey',
  1154. '',
  1155. ],
  1156. [
  1157. 'truthy',
  1158. true,
  1159. ],
  1160. [
  1161. 'does_not_exist',
  1162. null,
  1163. ],
  1164. ];
  1165. }
  1166. /**
  1167. * Test that option parsers are created with the correct name/command.
  1168. *
  1169. * @return void
  1170. */
  1171. public function testGetOptionParser()
  1172. {
  1173. $this->Shell->name = 'test';
  1174. $this->Shell->plugin = 'plugin';
  1175. $parser = $this->Shell->getOptionParser();
  1176. $this->assertSame('plugin.test', $parser->getCommand());
  1177. }
  1178. /**
  1179. * Test file and console and logging quiet output
  1180. *
  1181. * @return void
  1182. */
  1183. public function testQuietLog()
  1184. {
  1185. $io = $this->getMockBuilder('Cake\Console\ConsoleIo')
  1186. ->disableOriginalConstructor()
  1187. ->getMock();
  1188. $io->expects($this->once())
  1189. ->method('level')
  1190. ->with(Shell::QUIET);
  1191. $io->expects($this->exactly(2))
  1192. ->method('setLoggers')
  1193. ->withConsecutive([true], [ConsoleIo::QUIET]);
  1194. $this->Shell = $this->getMockBuilder(ShellTestShell::class)
  1195. ->addMethods(['welcome'])
  1196. ->setConstructorArgs([$io])
  1197. ->getMock();
  1198. $this->Shell->runCommand(['foo', '--quiet']);
  1199. }
  1200. /**
  1201. * Test getIo() and setIo() methods
  1202. *
  1203. * @return void
  1204. */
  1205. public function testGetSetIo()
  1206. {
  1207. $this->Shell->setIo($this->io);
  1208. $this->assertSame($this->Shell->getIo(), $this->io);
  1209. }
  1210. /**
  1211. * Test setRootName filters into the option parser help text.
  1212. *
  1213. * @return void
  1214. */
  1215. public function testSetRootNamePropagatesToHelpText()
  1216. {
  1217. $this->assertSame($this->Shell, $this->Shell->setRootName('tool'), 'is chainable');
  1218. $this->assertStringContainsString('tool shell_test_shell [-h]', $this->Shell->getOptionParser()->help());
  1219. }
  1220. /**
  1221. * Tests __debugInfo
  1222. *
  1223. * @return void
  1224. */
  1225. public function testDebugInfo()
  1226. {
  1227. $expected = [
  1228. 'name' => 'ShellTestShell',
  1229. 'plugin' => null,
  1230. 'command' => null,
  1231. 'tasks' => [],
  1232. 'params' => [],
  1233. 'args' => [],
  1234. 'interactive' => true,
  1235. ];
  1236. $result = $this->Shell->__debugInfo();
  1237. $this->assertEquals($expected, $result);
  1238. }
  1239. }