PluginListCommandTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 $configPath;
  26. /**
  27. * setUp method
  28. */
  29. public function setUp(): void
  30. {
  31. parent::setUp();
  32. $this->setAppNamespace();
  33. $this->configPath = ROOT . DS . 'cakephp-plugins.php';
  34. if (file_exists($this->configPath)) {
  35. unlink($this->configPath);
  36. }
  37. }
  38. protected function tearDown(): void
  39. {
  40. parent::tearDown();
  41. if (file_exists($this->configPath)) {
  42. unlink($this->configPath);
  43. }
  44. }
  45. /**
  46. * Test generating help succeeds
  47. */
  48. public function testHelp(): void
  49. {
  50. $this->exec('plugin list --help');
  51. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  52. $this->assertOutputContains('plugin list');
  53. }
  54. /**
  55. * Test plugin names are being displayed correctly
  56. */
  57. public function testList(): void
  58. {
  59. $file = <<<PHP
  60. <?php
  61. declare(strict_types=1);
  62. return [
  63. 'plugins' => [
  64. 'TestPlugin' => '/config/path',
  65. 'OtherPlugin' => '/config/path'
  66. ]
  67. ];
  68. PHP;
  69. file_put_contents($this->configPath, $file);
  70. $this->exec('plugin list');
  71. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  72. $this->assertOutputContains('TestPlugin');
  73. $this->assertOutputContains('OtherPlugin');
  74. }
  75. /**
  76. * Test empty plugins array
  77. */
  78. public function testListEmpty(): void
  79. {
  80. $file = <<<PHP
  81. <?php
  82. declare(strict_types=1);
  83. return [];
  84. PHP;
  85. file_put_contents($this->configPath, $file);
  86. $this->exec('plugin list');
  87. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  88. $this->assertErrorContains('No plugins have been found.');
  89. }
  90. }