Skip to content

Commit

Permalink
Updating DbConfigTask to PHPUnit.
Browse files Browse the repository at this point in the history
Making protected methods and properties protected for easier mocking.
  • Loading branch information
markstory committed Jun 9, 2010
1 parent ebfbbfe commit dad4b5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
11 changes: 6 additions & 5 deletions cake/console/libs/tasks/db_config.php
Expand Up @@ -40,7 +40,7 @@ class DbConfigTask extends Shell {
* @var array
* @access private
*/
private $__defaultConfig = array(
protected $_defaultConfig = array(
'name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
Expand Down Expand Up @@ -174,9 +174,10 @@ protected function _interactive() {

$config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');

while ($this->__verify($config) == false) {
while ($this->_verify($config) == false) {
$this->_interactive();
}

$dbConfigs[] = $config;
$doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');

Expand All @@ -195,8 +196,8 @@ protected function _interactive() {
*
* @return boolean True if user says it looks good, false otherwise
*/
private function __verify($config) {
$config = array_merge($this->__defaultConfig, $config);
protected function _verify($config) {
$config = array_merge($this->_defaultConfig, $config);
extract($config);
$this->out();
$this->hr();
Expand Down Expand Up @@ -257,7 +258,7 @@ public function bake($configs) {
$temp = get_class_vars(get_class($db));

foreach ($temp as $configName => $info) {
$info = array_merge($this->__defaultConfig, $info);
$info = array_merge($this->_defaultConfig, $info);

if (!isset($info['schema'])) {
$info['schema'] = null;
Expand Down
25 changes: 13 additions & 12 deletions cake/tests/cases/console/libs/tasks/db_config.test.php
Expand Up @@ -123,20 +123,21 @@ public function testInitialize() {
*/
public function testExecuteIntoInteractive() {
$this->Task->initialize();
$this->Task = $this->getMock('DbConfigTask', array('in', '_stop', 'createFile'), array(&$this->Dispatcher));

$this->Task->expects($this->once())->method('_stop');
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('default'));
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('mysql'));
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('localhost'));
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(8))->method('in')->will($this->returnValue('root'));
$this->Task->expects($this->at(9))->method('in')->will($this->returnValue('password'));
$this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test'));
$this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n'));
$this->Task->expects($this->at(13))->method('_verify')->will($this->returnValue(true));
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('mysql')); //db type
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); //persistant
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('localhost')); //server
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); //port
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('root')); //user
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('password')); //password
$this->Task->expects($this->at(10))->method('in')->will($this->returnValue('cake_test')); //db
$this->Task->expects($this->at(11))->method('in')->will($this->returnValue('n')); //prefix
$this->Task->expects($this->at(12))->method('in')->will($this->returnValue('n')); //encoding
$this->Task->expects($this->at(13))->method('in')->will($this->returnValue('y')); //looks good
$this->Task->expects($this->at(14))->method('in')->will($this->returnValue('n')); //another

$result = $this->Task->execute();
}
Expand Down

0 comments on commit dad4b5a

Please sign in to comment.