ShellTest.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  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. Plugin::unload();
  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. Plugin::unload();
  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. }