PluginListCommandTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. * PluginListCommandTest class.
  21. */
  22. class PluginListCommandTest extends TestCase
  23. {
  24. use ConsoleIntegrationTestTrait;
  25. protected string $pluginsListPath;
  26. protected string $pluginsConfigPath;
  27. /**
  28. * setUp method
  29. */
  30. public function setUp(): void
  31. {
  32. parent::setUp();
  33. $this->setAppNamespace();
  34. $this->pluginsListPath = ROOT . DS . 'cakephp-plugins.php';
  35. if (file_exists($this->pluginsListPath)) {
  36. unlink($this->pluginsListPath);
  37. }
  38. $this->pluginsConfigPath = CONFIG . DS . 'plugins.php';
  39. if (file_exists($this->pluginsConfigPath)) {
  40. unlink($this->pluginsConfigPath);
  41. }
  42. }
  43. protected function tearDown(): void
  44. {
  45. parent::tearDown();
  46. if (file_exists($this->pluginsListPath)) {
  47. unlink($this->pluginsListPath);
  48. }
  49. if (file_exists($this->pluginsConfigPath)) {
  50. unlink($this->pluginsConfigPath);
  51. }
  52. }
  53. /**
  54. * Test generating help succeeds
  55. */
  56. public function testHelp(): void
  57. {
  58. $this->exec('plugin list --help');
  59. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  60. $this->assertOutputContains('plugin list');
  61. }
  62. /**
  63. * Test plugin names are being displayed correctly
  64. */
  65. public function testList(): void
  66. {
  67. $file = <<<PHP
  68. <?php
  69. declare(strict_types=1);
  70. return [
  71. 'plugins' => [
  72. 'TestPlugin' => '/config/path',
  73. 'OtherPlugin' => '/config/path'
  74. ]
  75. ];
  76. PHP;
  77. file_put_contents($this->pluginsListPath, $file);
  78. $this->exec('plugin list');
  79. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  80. $this->assertOutputContains('TestPlugin');
  81. $this->assertOutputContains('OtherPlugin');
  82. }
  83. /**
  84. * Test empty plugins array
  85. */
  86. public function testListEmpty(): void
  87. {
  88. $file = <<<PHP
  89. <?php
  90. declare(strict_types=1);
  91. return [];
  92. PHP;
  93. file_put_contents($this->pluginsListPath, $file);
  94. $this->exec('plugin list');
  95. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  96. $this->assertErrorContains('No plugins have been found.');
  97. }
  98. /**
  99. * Test enabled plugins are being flagged as enabled
  100. */
  101. public function testListEnabled(): void
  102. {
  103. $file = <<<PHP
  104. <?php
  105. declare(strict_types=1);
  106. return [
  107. 'plugins' => [
  108. 'TestPlugin' => '/config/path',
  109. 'OtherPlugin' => '/config/path'
  110. ]
  111. ];
  112. PHP;
  113. file_put_contents($this->pluginsListPath, $file);
  114. $config = <<<PHP
  115. <?php
  116. declare(strict_types=1);
  117. return [
  118. 'TestPlugin',
  119. 'OtherPlugin' => ['onlyDebug' => true, 'onlyCli' => true, 'optional' => true]
  120. ];
  121. PHP;
  122. file_put_contents($this->pluginsConfigPath, $config);
  123. $this->exec('plugin list');
  124. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  125. $this->assertOutputContains('TestPlugin');
  126. $this->assertOutputContains('OtherPlugin');
  127. }
  128. }