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