PluginLoadCommandTest.php 2.2 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\Command;
  17. use Cake\Filesystem\File;
  18. use Cake\TestSuite\ConsoleIntegrationTestTrait;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * PluginLoadCommandTest class.
  22. */
  23. class PluginLoadCommandTest extends TestCase
  24. {
  25. use ConsoleIntegrationTestTrait;
  26. /**
  27. * @var string
  28. */
  29. protected $app;
  30. /**
  31. * @var string
  32. */
  33. protected $originalAppContent;
  34. /**
  35. * setUp method
  36. *
  37. * @return void
  38. */
  39. public function setUp(): void
  40. {
  41. parent::setUp();
  42. $this->app = APP . DS . 'Application.php';
  43. $app = new File($this->app, false);
  44. $this->originalAppContent = $app->read();
  45. $this->useCommandRunner();
  46. $this->setAppNamespace();
  47. }
  48. /**
  49. * tearDown method
  50. *
  51. * @return void
  52. */
  53. public function tearDown(): void
  54. {
  55. parent::tearDown();
  56. $app = new File($this->app, false);
  57. $app->write($this->originalAppContent);
  58. }
  59. /**
  60. * Test generating help succeeds
  61. *
  62. * @return void
  63. */
  64. public function testHelp()
  65. {
  66. $this->exec('plugin load --help');
  67. $this->assertExitCode(Command::CODE_SUCCESS);
  68. $this->assertOutputContains('plugin load');
  69. }
  70. /**
  71. * Test loading the app
  72. *
  73. * @return void
  74. */
  75. public function testLoadApp()
  76. {
  77. $this->exec('plugin load TestPlugin');
  78. $this->assertExitCode(Command::CODE_SUCCESS);
  79. $contents = file_get_contents($this->app);
  80. $this->assertStringContainsString("\$this->addPlugin('TestPlugin');", $contents);
  81. }
  82. }