PluginUnloadCommandTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\Core\Plugin;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * PluginUnloadCommandTest class
  22. */
  23. class PluginUnloadCommandTest extends TestCase
  24. {
  25. use ConsoleIntegrationTestTrait;
  26. /**
  27. * @var string
  28. */
  29. protected $configFile;
  30. /**
  31. * @var string
  32. */
  33. protected $originalContent;
  34. /**
  35. * setUp method
  36. */
  37. public function setUp(): void
  38. {
  39. parent::setUp();
  40. Plugin::getCollection()->clear();
  41. $this->configFile = CONFIG . 'plugins.php';
  42. $this->originalContent = file_get_contents($this->configFile);
  43. $contents = <<<CONTENTS
  44. <?php
  45. return [
  46. 'TestPlugin' => ['routes' => false],
  47. 'TestPluginTwo',
  48. 'Company/TestPluginThree'
  49. ];
  50. CONTENTS;
  51. file_put_contents($this->configFile, $contents);
  52. $this->setAppNamespace();
  53. }
  54. /**
  55. * tearDown method
  56. */
  57. public function tearDown(): void
  58. {
  59. parent::tearDown();
  60. file_put_contents($this->configFile, $this->originalContent);
  61. }
  62. /**
  63. * testUnload
  64. *
  65. * @dataProvider pluginNameProvider
  66. */
  67. public function testUnload($plugin): void
  68. {
  69. $this->exec('plugin unload ' . $plugin);
  70. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  71. $contents = file_get_contents($this->configFile);
  72. $this->assertStringNotContainsString("'" . $plugin . "'", $contents);
  73. $this->assertStringContainsString("'Company/TestPluginThree'", $contents);
  74. }
  75. public static function pluginNameProvider()
  76. {
  77. return [
  78. ['TestPlugin'],
  79. ['TestPluginTwo'],
  80. ];
  81. }
  82. public function testUnloadNoConfigFile(): void
  83. {
  84. unlink($this->configFile);
  85. $this->exec('plugin unload TestPlugin');
  86. $this->assertExitCode(CommandInterface::CODE_ERROR);
  87. $this->assertErrorContains('`CONFIG/plugins.php` not found or does not return an array');
  88. }
  89. public function testUnloadUnknownPlugin(): void
  90. {
  91. $this->exec('plugin unload NopeNotThere');
  92. $this->assertExitCode(CommandInterface::CODE_ERROR);
  93. $this->assertErrorContains('Plugin `NopeNotThere` could not be found');
  94. }
  95. }