PluginLoadCommandTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP Project
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Command;
  16. use Cake\Console\CommandInterface;
  17. use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * PluginLoadCommandTest class.
  21. */
  22. class PluginLoadCommandTest extends TestCase
  23. {
  24. use ConsoleIntegrationTestTrait;
  25. /**
  26. * @var string
  27. */
  28. protected $configFile;
  29. /**
  30. * @var string
  31. */
  32. protected $originalContent;
  33. /**
  34. * setUp method
  35. */
  36. public function setUp(): void
  37. {
  38. parent::setUp();
  39. $this->configFile = CONFIG . 'plugins.php';
  40. $this->originalContent = file_get_contents($this->configFile);
  41. $this->setAppNamespace();
  42. }
  43. /**
  44. * tearDown method
  45. */
  46. public function tearDown(): void
  47. {
  48. parent::tearDown();
  49. file_put_contents($this->configFile, $this->originalContent);
  50. }
  51. /**
  52. * Test generating help succeeds
  53. */
  54. public function testHelp(): void
  55. {
  56. $this->exec('plugin load --help');
  57. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  58. $this->assertOutputContains('plugin load');
  59. }
  60. /**
  61. * Test loading a plugin modifies the config file
  62. */
  63. public function testLoad(): void
  64. {
  65. $this->exec('plugin load TestPlugin');
  66. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  67. $this->exec('plugin load TestPluginTwo --no-bootstrap --no-console --no-middleware --no-routes --no-services');
  68. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  69. $this->exec('plugin load Company/TestPluginThree --only-debug --only-cli');
  70. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  71. $config = include $this->configFile;
  72. $this->assertTrue(isset($config['TestPlugin']));
  73. $this->assertTrue(isset($config['TestPluginTwo']));
  74. $this->assertTrue(isset($config['Company/TestPluginThree']));
  75. $this->assertSame(['onlyDebug' => true, 'onlyCli' => true], $config['Company/TestPluginThree']);
  76. $this->assertSame(
  77. ['bootstrap' => false, 'console' => false, 'middleware' => false, 'routes' => false, 'services' => false],
  78. $config['TestPluginTwo']
  79. );
  80. }
  81. /**
  82. * Test loading an unknown plugin
  83. */
  84. public function testLoadUnknownPlugin(): void
  85. {
  86. $this->exec('plugin load NopeNotThere');
  87. $this->assertExitCode(CommandInterface::CODE_ERROR);
  88. $this->assertErrorContains('Plugin NopeNotThere could not be found');
  89. $config = include $this->configFile;
  90. $this->assertFalse(isset($config['NopeNotThere']));
  91. }
  92. /**
  93. * Test loading optional plugin
  94. */
  95. public function testLoadOptionalPlugin(): void
  96. {
  97. $this->exec('plugin load NopeNotThere --optional');
  98. $config = include $this->configFile;
  99. $this->assertTrue(isset($config['NopeNotThere']));
  100. $this->assertSame(['optional' => true], $config['NopeNotThere']);
  101. }
  102. }