DbConfigTaskTest.php 4.1 KB

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