DbConfigTaskTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * DBConfigTask Test Case
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.tests.cases.console.libs.tasks
  16. * @since CakePHP(tm) v 1.3
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('ShellDispatcher', 'Console');
  20. App::uses('ConsoleOutput', 'Console');
  21. App::uses('ConsoleInput', 'Console');
  22. App::uses('Shell', 'Console');
  23. App::uses('DbConfigTask', 'Console/Command/Task');
  24. class TEST_DATABASE_CONFIG {
  25. public $default = array(
  26. 'driver' => 'mysql',
  27. 'persistent' => false,
  28. 'host' => 'localhost',
  29. 'login' => 'user',
  30. 'password' => 'password',
  31. 'database' => 'database_name',
  32. 'prefix' => '',
  33. );
  34. public $otherOne = array(
  35. 'driver' => 'mysql',
  36. 'persistent' => false,
  37. 'host' => 'localhost',
  38. 'login' => 'user',
  39. 'password' => 'password',
  40. 'database' => 'other_one',
  41. 'prefix' => '',
  42. );
  43. }
  44. /**
  45. * DbConfigTest class
  46. *
  47. * @package cake.tests.cases.console.libs.tasks
  48. */
  49. class DbConfigTaskTest extends CakeTestCase {
  50. /**
  51. * setup method
  52. *
  53. * @return void
  54. */
  55. public function setUp() {
  56. parent::setUp();
  57. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  58. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  59. $this->Task = $this->getMock('DbConfigTask',
  60. array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
  61. array($out, $out, $in)
  62. );
  63. $this->Task->path = APP . 'config' . DS;
  64. $this->Task->databaseClassName = 'TEST_DATABASE_CONFIG';
  65. }
  66. /**
  67. * endTest method
  68. *
  69. * @return void
  70. */
  71. public function tearDown() {
  72. parent::tearDown();
  73. unset($this->Task);
  74. }
  75. /**
  76. * Test the getConfig method.
  77. *
  78. * @return void
  79. */
  80. public function testGetConfig() {
  81. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('otherOne'));
  82. $result = $this->Task->getConfig();
  83. $this->assertEquals('otherOne', $result);
  84. }
  85. /**
  86. * test that initialize sets the path up.
  87. *
  88. * @return void
  89. */
  90. public function testInitialize() {
  91. $this->Task->initialize();
  92. $this->assertFalse(empty($this->Task->path));
  93. $this->assertEquals(APP . 'config' . DS, $this->Task->path);
  94. }
  95. /**
  96. * test execute and by extension _interactive
  97. *
  98. * @return void
  99. */
  100. public function testExecuteIntoInteractive() {
  101. $this->Task->initialize();
  102. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  103. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  104. $this->Task = $this->getMock(
  105. 'DbConfigTask',
  106. array('in', '_stop', 'createFile', 'bake'), array($out, $out, $in)
  107. );
  108. $this->Task->expects($this->once())->method('_stop');
  109. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
  110. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
  111. $this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistant
  112. $this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
  113. $this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
  114. $this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
  115. $this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
  116. $this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
  117. $this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
  118. $this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
  119. $this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
  120. $this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another
  121. $this->Task->expects($this->at(15))->method('bake')
  122. ->with(array(
  123. array(
  124. 'name' => 'default',
  125. 'driver' => 'mysql',
  126. 'persistent' => 'false',
  127. 'host' => 'localhost',
  128. 'login' => 'root',
  129. 'password' => 'password',
  130. 'database' => 'cake_test',
  131. 'prefix' => null,
  132. 'encoding' => null,
  133. 'port' => '',
  134. 'schema' => null
  135. )
  136. ));
  137. $result = $this->Task->execute();
  138. }
  139. }