DbConfigTaskTest.php 4.1 KB

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