PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/Test/Case/Console/Command/Task/DbConfigTaskTest.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 133 lines | 73 code | 13 blank | 47 comment | 0 complexity | 97df4554483b82427468b86d2f9f1901 MD5 | raw file
  1. <?php
  2. /**
  3. * DBConfigTask Test Case
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, 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-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Test.Case.Console.Command.Task
  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. /**
  25. * DbConfigTest class
  26. *
  27. * @package Cake.Test.Case.Console.Command.Task
  28. */
  29. class DbConfigTaskTest extends CakeTestCase {
  30. /**
  31. * setUp method
  32. *
  33. * @return void
  34. */
  35. public function setUp() {
  36. parent::setUp();
  37. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  38. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  39. $this->Task = $this->getMock('DbConfigTask',
  40. array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
  41. array($out, $out, $in)
  42. );
  43. $this->Task->path = APP . 'Config' . DS;
  44. }
  45. /**
  46. * endTest method
  47. *
  48. * @return void
  49. */
  50. public function tearDown() {
  51. parent::tearDown();
  52. unset($this->Task);
  53. }
  54. /**
  55. * Test the getConfig method.
  56. *
  57. * @return void
  58. */
  59. public function testGetConfig() {
  60. $this->Task->expects($this->any())
  61. ->method('in')
  62. ->will($this->returnValue('test'));
  63. $result = $this->Task->getConfig();
  64. $this->assertEquals('test', $result);
  65. }
  66. /**
  67. * test that initialize sets the path up.
  68. *
  69. * @return void
  70. */
  71. public function testInitialize() {
  72. $this->Task->initialize();
  73. $this->assertFalse(empty($this->Task->path));
  74. $this->assertEquals(APP . 'Config' . DS, $this->Task->path);
  75. }
  76. /**
  77. * test execute and by extension _interactive
  78. *
  79. * @return void
  80. */
  81. public function testExecuteIntoInteractive() {
  82. $this->Task->initialize();
  83. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  84. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  85. $this->Task = $this->getMock(
  86. 'DbConfigTask',
  87. array('in', '_stop', 'createFile', 'bake'), array($out, $out, $in)
  88. );
  89. $this->Task->expects($this->once())->method('_stop');
  90. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
  91. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
  92. $this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistant
  93. $this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
  94. $this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
  95. $this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
  96. $this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
  97. $this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
  98. $this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
  99. $this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
  100. $this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
  101. $this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another
  102. $this->Task->expects($this->at(15))->method('bake')
  103. ->with(array(
  104. array(
  105. 'name' => 'default',
  106. 'datasource' => 'mysql',
  107. 'persistent' => 'false',
  108. 'host' => 'localhost',
  109. 'login' => 'root',
  110. 'password' => 'password',
  111. 'database' => 'cake_test',
  112. 'prefix' => null,
  113. 'encoding' => null,
  114. 'port' => '',
  115. 'schema' => null
  116. )
  117. ));
  118. $result = $this->Task->execute();
  119. }
  120. }