ShellTest.php 41 KB

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