PluginLoadCommandTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\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 $app;
  29. /**
  30. * @var string
  31. */
  32. protected $originalAppContent;
  33. /**
  34. * setUp method
  35. */
  36. public function setUp(): void
  37. {
  38. parent::setUp();
  39. $this->app = APP . DS . 'Application.php';
  40. $this->originalAppContent = file_get_contents($this->app);
  41. $this->setAppNamespace();
  42. }
  43. /**
  44. * tearDown method
  45. */
  46. public function tearDown(): void
  47. {
  48. parent::tearDown();
  49. file_put_contents($this->app, $this->originalAppContent);
  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 app
  62. */
  63. public function testLoadModifiesApplication(): void
  64. {
  65. $this->exec('plugin load TestPlugin');
  66. $this->assertExitCode(CommandInterface::CODE_SUCCESS);
  67. $contents = file_get_contents($this->app);
  68. $this->assertMatchesRegularExpression('/Check plugins added here\n {8}\$this->addPlugin\(\'TestPlugin\'\);\n {4}\}\n/u', $contents);
  69. }
  70. /**
  71. * Test loading an unknown plugin
  72. */
  73. public function testLoadUnknownPlugin(): void
  74. {
  75. $this->exec('plugin load NopeNotThere');
  76. $this->assertExitCode(CommandInterface::CODE_ERROR);
  77. $this->assertErrorContains('Plugin NopeNotThere could not be found');
  78. $contents = file_get_contents($this->app);
  79. $this->assertStringNotContainsString("\$this->addPlugin('NopeNotThere');", $contents);
  80. }
  81. }