mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing more console tests to use new internals.
Making TaskCollection pass the stdout, stdin, stderr to Tasks they create. This allows for more flexible dependency injection and makes testing easier.
This commit is contained in:
parent
a3023430c8
commit
73ad3043a2
5 changed files with 37 additions and 29 deletions
|
@ -60,7 +60,9 @@ class TaskCollection extends ObjectCollection {
|
|||
}
|
||||
}
|
||||
|
||||
$this->_loaded[$name] = new $taskClass($this->_Shell);
|
||||
$this->_loaded[$name] = new $taskClass(
|
||||
$this->_Shell, $this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin
|
||||
);
|
||||
if ($enable === true) {
|
||||
$this->_enabled[] = $name;
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ class FixtureTask extends BakeTask {
|
|||
* Override initialize
|
||||
*
|
||||
*/
|
||||
public function __construct(&$dispatch) {
|
||||
parent::__construct($dispatch);
|
||||
public function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) {
|
||||
parent::__construct($dispatch, $stdout, $stderr, $stdin);
|
||||
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,12 +67,12 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
|
||||
));
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
|
||||
$out = $this->getMock('ConsoleOutput');
|
||||
$in = $this->getMock('ConsoleInput');
|
||||
$this->Task = $this->getMock('ControllerTask',
|
||||
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
||||
array(&$this->Dispatcher)
|
||||
array(&$this->Dispatcher, $out, $out, $in)
|
||||
);
|
||||
$this->Task->name = 'ControllerTask';
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
|
@ -81,13 +81,13 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
|
||||
$this->Task->Model = $this->getMock('ModelTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
||||
array(&$this->Dispatcher)
|
||||
array(&$this->Dispatcher, $out, $out, $in)
|
||||
);
|
||||
$this->Task->Project = $this->getMock('ProjectTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
|
||||
array(&$this->Dispatcher)
|
||||
array(&$this->Dispatcher, $out, $out, $in)
|
||||
);
|
||||
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher));
|
||||
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher, $out, $out, $in));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,12 +60,13 @@ class DbConfigTaskTest extends CakeTestCase {
|
|||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
|
||||
));
|
||||
$out = $this->getMock('ConsoleOutput');
|
||||
$in = $this->getMock('ConsoleInput');
|
||||
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
|
||||
$this->Task = $this->getMock('DbConfigTask',
|
||||
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
|
||||
array(&$this->Dispatcher)
|
||||
array(&$this->Dispatcher, $out, $out, $in)
|
||||
);
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
|
||||
|
@ -114,7 +115,12 @@ class DbConfigTaskTest extends CakeTestCase {
|
|||
*/
|
||||
public function testExecuteIntoInteractive() {
|
||||
$this->Task->initialize();
|
||||
$this->Task = $this->getMock('DbConfigTask', array('in', '_stop', 'createFile'), array(&$this->Dispatcher));
|
||||
|
||||
$out = $this->getMock('ConsoleOutput');
|
||||
$this->Task = $this->getMock(
|
||||
'DbConfigTask',
|
||||
array('in', '_stop', 'createFile'), array(&$this->Dispatcher, $out, $out)
|
||||
);
|
||||
|
||||
$this->Task->expects($this->once())->method('_stop');
|
||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
*/
|
||||
App::import('Shell', 'Shell', false);
|
||||
|
||||
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
||||
define('DISABLE_AUTO_DISPATCH', true);
|
||||
}
|
||||
|
||||
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||
|
@ -50,18 +46,19 @@ class FixtureTaskTest extends CakeTestCase {
|
|||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
|
||||
));
|
||||
$out = $this->getMock('ConsoleOutput');
|
||||
$in = $this->getMock('ConsoleInput');
|
||||
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
|
||||
$this->Task = $this->getMock('FixtureTask',
|
||||
array('in', 'err', 'createFile', '_stop'),
|
||||
array(&$this->Dispatcher)
|
||||
array('in', 'err', 'createFile', '_stop', 'clear'),
|
||||
array(&$this->Dispatcher, $out, $out, $in)
|
||||
);
|
||||
$this->Task->Model = $this->getMock('Shell',
|
||||
array('in', 'out', 'erro', 'createFile', 'getName', 'getTable', 'listAll'),
|
||||
array(&$this->Dispatcher)
|
||||
array('in', 'out', 'error', 'createFile', 'getName', 'getTable', 'listAll'),
|
||||
array(&$this->Dispatcher, $out, $out, $in)
|
||||
);
|
||||
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
||||
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
$this->Task->Template->initialize();
|
||||
}
|
||||
|
@ -82,8 +79,11 @@ class FixtureTaskTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testConstruct() {
|
||||
$out = $this->getMock('ConsoleOutput');
|
||||
$in = $this->getMock('ConsoleInput');
|
||||
|
||||
$this->Dispatcher->params['working'] = DS . 'my' . DS . 'path';
|
||||
$Task = new FixtureTask($this->Dispatcher);
|
||||
$Task = new FixtureTask($this->Dispatcher, $out, $out, $in);
|
||||
|
||||
$expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS;
|
||||
$this->assertEqual($Task->path, $expected);
|
||||
|
@ -137,7 +137,7 @@ class FixtureTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testImportRecordsFromDatabaseWithConditions() {
|
||||
public function testImportRecordsFromDatabaseWithConditionsPoo() {
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->expects($this->at(0))->method('in')
|
||||
->will($this->returnValue('WHERE 1=1 LIMIT 10'));
|
||||
|
|
Loading…
Add table
Reference in a new issue