I think app/lib/lib/Cake/Console/Command/TestShellTest.php can be a reference.
1、create file in app/Test/Case/Console/Command/yourfile.php, state your classes using App::uses('your class', 'relative path').
for example:
App::uses('yourShellClass', 'Console/Command');
App::uses('ShellDispatcher', 'Console');
App::uses('Shell', 'Console');
2、write a mock class B from your shell class A, whose function use data returns in class A.
for example:
class TestYourShellClass extends YourShellClass {
public function F1 ($parms){
//if you need use database here, you can
//$this->yourModel = ClassRegistry::init('yourModel');
return $this->_F1($parms);
}
}
3、write test class of class A, you need to init it in startup.
for example:
class YourShellClassTest extends CakeTestCase {
public function setUp()
{
parent::setUp();
$out = $this->getMock('ConsoleOutput', [], [], '', false);
$in = $this->getMock('ConsoleInput', [], [], '', false);
$this->Shell = $this->getMock(
// this is your class B, which mocks class A.
'TestYourShellClass',
['in', 'out', 'hr', 'help', 'error', 'err', '_stop', 'initialize', '_run', 'clear'],
[$out, $out, $in]
);
$this->Shell->OptionParser = $this->getMock('ConsoleOptionParser', [], [null, false]);
}
/**
* tear down method.
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
unset($this->Dispatch, $this->Shell);
}
}
4、 the test function can be like this.
/**
* test _F1.
*
* @return void
*/
public function testF1()
{
$this->Shell->startup();
$return = $this->Shell->F1();
$expectedSellerCount = 14;
$this->assertSame($expectedSellerCount, $return);
}
and then you can view result in http://yourdomain/test.php