cakephp2-php8/lib/Cake/Test/Case/Console/Command/Task/DbConfigTaskTest.php

133 lines
4.1 KiB
PHP
Raw Normal View History

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