CommandTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 3.6.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Console;
  16. use Cake\Console\Command;
  17. use Cake\Console\ConsoleOptionParser;
  18. use Cake\ORM\Locator\TableLocator;
  19. use Cake\ORM\Table;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * Test case for Console\Command
  23. */
  24. class CommandTest extends TestCase
  25. {
  26. /**
  27. * test orm locator is setup
  28. *
  29. * @return void
  30. */
  31. public function testConstructorSetsLocator()
  32. {
  33. $command = new Command();
  34. $result = $command->getTableLocator();
  35. $this->assertInstanceOf(TableLocator::class, $result);
  36. }
  37. /**
  38. * test loadModel is configured properly
  39. *
  40. * @return void
  41. */
  42. public function testConstructorLoadModel()
  43. {
  44. $command = new Command();
  45. $command->loadModel('Comments');
  46. $this->assertInstanceOf(Table::class, $command->Comments);
  47. }
  48. /**
  49. * Test name
  50. *
  51. * @return void
  52. */
  53. public function testSetName()
  54. {
  55. $command = new Command();
  56. $this->assertSame($command, $command->setName('routes show'));
  57. $this->assertSame('routes show', $command->getName());
  58. }
  59. /**
  60. * Test option parser fetching
  61. *
  62. * @return void
  63. */
  64. public function testGetOptionParser()
  65. {
  66. $command = new Command();
  67. $command->setName('cake routes show');
  68. $parser = $command->getOptionParser();
  69. $this->assertInstanceOf(ConsoleOptionParser::class, $parser);
  70. $this->assertSame('cake routes show', $parser->getCommand());
  71. }
  72. /**
  73. * Test option parser fetching
  74. *
  75. * @expectedException RuntimeException
  76. * @return void
  77. */
  78. public function testGetOptionParserInvalid()
  79. {
  80. $command = $this->getMockBuilder(Command::class)
  81. ->setMethods(['buildOptionParser'])
  82. ->getMock();
  83. $command->expects($this->once())
  84. ->method('buildOptionParser')
  85. ->will($this->returnValue(null));
  86. $command->getOptionParser();
  87. }
  88. }