LoadTaskTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP Project
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Shell\Task;
  15. use Cake\Console\Shell;
  16. use Cake\Core\Plugin;
  17. use Cake\Filesystem\File;
  18. use Cake\TestSuite\ConsoleIntegrationTestCase;
  19. /**
  20. * LoadTaskTest class.
  21. */
  22. class LoadTaskTest extends ConsoleIntegrationTestCase
  23. {
  24. /**
  25. * @var \Cake\Shell\Task\LoadTask|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $Task;
  28. /**
  29. * setUp method
  30. *
  31. * @return void
  32. */
  33. public function setUp()
  34. {
  35. parent::setUp();
  36. $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')
  37. ->disableOriginalConstructor()
  38. ->getMock();
  39. $this->Task = $this->getMockBuilder('Cake\Shell\Task\LoadTask')
  40. ->setMethods(['in', 'out', 'err', '_stop'])
  41. ->setConstructorArgs([$this->io])
  42. ->getMock();
  43. $this->app = APP . DS . 'Application.php';
  44. $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
  45. $this->bootstrapCli = ROOT . DS . 'config' . DS . 'bootstrap_cli.php';
  46. copy($this->bootstrap, $this->bootstrapCli);
  47. $bootstrap = new File($this->bootstrap, false);
  48. $this->originalBootstrapContent = $bootstrap->read();
  49. $app = new File($this->app, false);
  50. $this->originalAppContent = $app->read();
  51. }
  52. /**
  53. * tearDown method
  54. *
  55. * @return void
  56. */
  57. public function tearDown()
  58. {
  59. parent::tearDown();
  60. unset($this->shell);
  61. Plugin::unload();
  62. $bootstrap = new File($this->bootstrap, false);
  63. $bootstrap->write($this->originalBootstrapContent);
  64. unlink($this->bootstrapCli);
  65. $app = new File($this->app, false);
  66. $app->write($this->originalAppContent);
  67. }
  68. /**
  69. * testLoad
  70. *
  71. * @return void
  72. */
  73. public function testLoad()
  74. {
  75. $this->exec('plugin load --no_app --autoload TestPlugin');
  76. $this->assertExitCode(Shell::CODE_SUCCESS);
  77. $contents = file_get_contents($this->bootstrap);
  78. $this->assertContains(
  79. "Plugin::load('TestPlugin', ['autoload' => true]);",
  80. $contents
  81. );
  82. }
  83. /**
  84. * testLoadWithBootstrap
  85. *
  86. * @return void
  87. */
  88. public function testLoadWithBootstrap()
  89. {
  90. $this->exec('plugin load --no_app --bootstrap --autoload TestPlugin');
  91. $this->assertExitCode(Shell::CODE_SUCCESS);
  92. $contents = file_get_contents($this->bootstrap);
  93. $this->assertContains(
  94. "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true]);",
  95. $contents
  96. );
  97. }
  98. /**
  99. * Tests that loading with bootstrap_cli works.
  100. *
  101. * @return void
  102. */
  103. public function testLoadBootstrapCli()
  104. {
  105. $this->exec('plugin load --no_app --cli TestPlugin');
  106. $this->assertExitCode(Shell::CODE_SUCCESS);
  107. $contents = file_get_contents($this->bootstrapCli);
  108. $this->assertContains(
  109. "Plugin::load('TestPlugin');",
  110. $contents
  111. );
  112. }
  113. /**
  114. * testLoadWithRoutes
  115. *
  116. * @return void
  117. */
  118. public function testLoadWithRoutes()
  119. {
  120. $this->exec('plugin load --no_app --routes --autoload TestPlugin');
  121. $this->assertExitCode(Shell::CODE_SUCCESS);
  122. $contents = file_get_contents($this->bootstrap);
  123. $this->assertContains(
  124. "Plugin::load('TestPlugin', ['autoload' => true, 'routes' => true]);",
  125. $contents
  126. );
  127. }
  128. /**
  129. * test load no autoload
  130. *
  131. * @return void
  132. */
  133. public function testLoadNoAutoload()
  134. {
  135. $this->exec('plugin load --no_app --routes TestPlugin');
  136. $this->assertExitCode(Shell::CODE_SUCCESS);
  137. $contents = file_get_contents($this->bootstrap);
  138. $this->assertContains("Plugin::load('TestPlugin', ['routes' => true]);", $contents);
  139. }
  140. /**
  141. * testLoad
  142. *
  143. * @return void
  144. */
  145. public function testLoadNothing()
  146. {
  147. $this->exec('plugin load --no_app TestPlugin');
  148. $this->assertExitCode(Shell::CODE_SUCCESS);
  149. $contents = file_get_contents($this->bootstrap);
  150. $this->assertContains("Plugin::load('TestPlugin');", $contents);
  151. }
  152. }