PluginUnloadCommandTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * PluginUnloadCommandTest class
  21. */
  22. class PluginUnloadCommandTest 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. $contents = <<<CONTENTS
  42. <?php
  43. return [
  44. 'TestPlugin' => ['routes' => false],
  45. 'TestPluginTwo',
  46. 'Company/TestPluginThree'
  47. ];
  48. CONTENTS;
  49. file_put_contents($this->configFile, $contents);
  50. $this->setAppNamespace();
  51. }
  52. /**
  53. * tearDown method
  54. */
  55. public function tearDown(): void
  56. {
  57. parent::tearDown();
  58. file_put_contents($this->configFile, $this->originalContent);
  59. }
  60. /**
  61. * testUnload
  62. *
  63. * @dataProvider pluginNameProvider
  64. */
  65. public function testUnload($plugin): void
  66. {
  67. $this->exec('plugin unload ' . $plugin);
  68. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  69. $contents = file_get_contents($this->configFile);
  70. $this->assertStringNotContainsString("'" . $plugin . "'", $contents);
  71. $this->assertStringContainsString("'Company/TestPluginThree'", $contents);
  72. }
  73. public static function pluginNameProvider()
  74. {
  75. return [
  76. ['TestPlugin'],
  77. ['TestPluginTwo'],
  78. ];
  79. }
  80. public function testUnloadNoConfigFile(): void
  81. {
  82. unlink($this->configFile);
  83. $this->exec('plugin unload TestPlugin');
  84. $this->assertExitCode(CommandInterface::CODE_ERROR);
  85. $this->assertErrorContains('`CONFIG/plugins.php` not found or does not return an array');
  86. }
  87. public function testUnloadUnknownPlugin(): void
  88. {
  89. $this->exec('plugin unload NopeNotThere');
  90. $this->assertExitCode(CommandInterface::CODE_ERROR);
  91. $this->assertErrorContains('Plugin `NopeNotThere` could not be found');
  92. }
  93. }