2009-05-21 03:15:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DBConfigTask Test Case
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-21 03:15:31 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-03-08 05:23:06 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('Shell', 'Console');
|
|
|
|
App::uses('DbConfigTask', 'Console/Command/Task');
|
2009-05-21 03:15:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DbConfigTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-21 03:15:31 +00:00
|
|
|
*/
|
|
|
|
class DbConfigTaskTest extends CakeTestCase {
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setup method
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2010-10-06 04:15:51 +00:00
|
|
|
|
2010-06-08 04:54:42 +00:00
|
|
|
$this->Task = $this->getMock('DbConfigTask',
|
|
|
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-08 04:54:42 +00:00
|
|
|
);
|
2009-05-21 03:15:31 +00:00
|
|
|
|
2011-05-13 08:06:45 +00:00
|
|
|
$this->Task->path = APP . 'Config' . DS;
|
2009-05-21 03:15:31 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* endTest method
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2009-05-21 03:15:31 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
|
|
|
* Test the getConfig method.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetConfig() {
|
2011-10-03 16:43:11 +00:00
|
|
|
$this->Task->expects($this->any())
|
2011-10-03 02:49:48 +00:00
|
|
|
->method('in')
|
|
|
|
->will($this->returnValue('test'));
|
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
$result = $this->Task->getConfig();
|
2011-10-03 02:49:48 +00:00
|
|
|
$this->assertEquals('test', $result);
|
2009-05-21 03:15:31 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
|
|
|
* test that initialize sets the path up.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testInitialize() {
|
2009-05-21 03:15:31 +00:00
|
|
|
$this->Task->initialize();
|
|
|
|
$this->assertFalse(empty($this->Task->path));
|
2011-05-13 08:06:45 +00:00
|
|
|
$this->assertEquals(APP . 'Config' . DS, $this->Task->path);
|
2009-05-21 03:15:31 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-21 03:15:31 +00:00
|
|
|
/**
|
2010-04-24 02:03:11 +00:00
|
|
|
* test execute and by extension _interactive
|
2009-05-21 03:15:31 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteIntoInteractive() {
|
2009-05-21 03:15:31 +00:00
|
|
|
$this->Task->initialize();
|
2010-10-06 04:15:51 +00:00
|
|
|
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
2010-10-24 19:27:04 +00:00
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2010-10-06 04:15:51 +00:00
|
|
|
$this->Task = $this->getMock(
|
|
|
|
'DbConfigTask',
|
2010-10-24 19:27:04 +00:00
|
|
|
array('in', '_stop', 'createFile', 'bake'), array($out, $out, $in)
|
2010-10-06 04:15:51 +00:00
|
|
|
);
|
2009-05-21 03:15:31 +00:00
|
|
|
|
2010-06-08 04:54:42 +00:00
|
|
|
$this->Task->expects($this->once())->method('_stop');
|
2010-06-09 02:14:48 +00:00
|
|
|
$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
|
2010-10-18 02:48:24 +00:00
|
|
|
$this->Task->expects($this->at(15))->method('bake')
|
|
|
|
->with(array(
|
|
|
|
array(
|
|
|
|
'name' => 'default',
|
|
|
|
'driver' => 'mysql',
|
|
|
|
'persistent' => 'false',
|
|
|
|
'host' => 'localhost',
|
|
|
|
'login' => 'root',
|
|
|
|
'password' => 'password',
|
|
|
|
'database' => 'cake_test',
|
|
|
|
'prefix' => null,
|
|
|
|
'encoding' => null,
|
|
|
|
'port' => '',
|
|
|
|
'schema' => null
|
|
|
|
)
|
|
|
|
));
|
2009-05-21 03:15:31 +00:00
|
|
|
|
|
|
|
$result = $this->Task->execute();
|
|
|
|
}
|
|
|
|
}
|