PluginLoadCommandTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\Command\Command;
  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. * @return void
  37. */
  38. public function setUp(): void
  39. {
  40. parent::setUp();
  41. $this->app = APP . DS . 'Application.php';
  42. $this->originalAppContent = file_get_contents($this->app);
  43. $this->useCommandRunner();
  44. $this->setAppNamespace();
  45. }
  46. /**
  47. * tearDown method
  48. *
  49. * @return void
  50. */
  51. public function tearDown(): void
  52. {
  53. parent::tearDown();
  54. file_put_contents($this->app, $this->originalAppContent);
  55. }
  56. /**
  57. * Test generating help succeeds
  58. *
  59. * @return void
  60. */
  61. public function testHelp()
  62. {
  63. $this->exec('plugin load --help');
  64. $this->assertExitCode(Command::CODE_SUCCESS);
  65. $this->assertOutputContains('plugin load');
  66. }
  67. /**
  68. * Test loading a plugin modifies the app
  69. *
  70. * @return void
  71. */
  72. public function testLoadModifiesApplication()
  73. {
  74. $this->exec('plugin load TestPlugin');
  75. $this->assertExitCode(Command::CODE_SUCCESS);
  76. $contents = file_get_contents($this->app);
  77. $this->assertStringContainsString("\$this->addPlugin('TestPlugin');", $contents);
  78. }
  79. /**
  80. * Test loading an unknown plugin
  81. *
  82. * @return void
  83. */
  84. public function testLoadUnknownPlugin()
  85. {
  86. $this->exec('plugin load NopeNotThere');
  87. $this->assertExitCode(Command::CODE_ERROR);
  88. $this->assertErrorContains('Plugin NopeNotThere could not be found');
  89. $contents = file_get_contents($this->app);
  90. $this->assertStringNotContainsString("\$this->addPlugin('NopeNotThere');", $contents);
  91. }
  92. }