2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ShellDispatcherTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-14 04:47:14 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-14 04:47:14 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc.
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-03-08 22:02:22 +00:00
|
|
|
|
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestShellDispatcher class
|
2008-06-26 03:50:11 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestShellDispatcher extends ShellDispatcher {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* params property
|
2008-06-26 03:50:11 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $params = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* stopped property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $stopped = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* TestShell
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $TestShell;
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* _initEnvironment method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _initEnvironment() {
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-26 01:27:02 +00:00
|
|
|
/**
|
|
|
|
* clear method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function clear() {
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-07-26 01:27:02 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* _stop method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _stop($status = 0) {
|
2008-11-13 00:33:53 +00:00
|
|
|
$this->stopped = 'Stopped with status: ' . $status;
|
2009-04-30 17:25:58 +00:00
|
|
|
return $status;
|
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* getShell
|
|
|
|
*
|
2010-10-18 01:04:14 +00:00
|
|
|
* @param mixed $shell
|
2009-04-30 17:25:58 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2010-10-18 01:04:14 +00:00
|
|
|
public function getShell($shell) {
|
|
|
|
return $this->_getShell($shell);
|
2009-04-30 17:25:58 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* _getShell
|
|
|
|
*
|
|
|
|
* @param mixed $plugin
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2010-10-18 01:04:14 +00:00
|
|
|
protected function _getShell($shell) {
|
2009-04-30 17:25:58 +00:00
|
|
|
if (isset($this->TestShell)) {
|
|
|
|
return $this->TestShell;
|
|
|
|
}
|
2010-10-18 01:04:14 +00:00
|
|
|
return parent::_getShell($shell);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ShellDispatcherTest
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-04-30 17:25:58 +00:00
|
|
|
class ShellDispatcherTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function setUp() {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
|
2009-06-11 16:13:16 +00:00
|
|
|
),
|
2011-03-08 22:02:22 +00:00
|
|
|
'Console/Command' => array(
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
|
2009-06-11 16:13:16 +00:00
|
|
|
)
|
|
|
|
), true);
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::loadAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
CakePlugin::unload();
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testParseParams method
|
2008-06-26 03:50:11 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testParseParams() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'/cake/1.2.x.x/cake/console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-working',
|
|
|
|
'/var/www/htdocs'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => '/var/www/htdocs/new',
|
|
|
|
'root' => '/var/www/htdocs'
|
|
|
|
);
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array('cake.php');
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
2011-04-15 01:58:46 +00:00
|
|
|
'working' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'app'),
|
|
|
|
'root' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH)),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-04-15 01:58:46 +00:00
|
|
|
'working' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake/console'
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-04-15 01:58:46 +00:00
|
|
|
'working' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
|
|
|
'webroot' => 'webroot',
|
2011-04-15 01:58:46 +00:00
|
|
|
'working' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./console/cake.php',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'new',
|
|
|
|
'-dry',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'new',
|
2011-04-15 01:58:46 +00:00
|
|
|
'working' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'new'),
|
|
|
|
'root' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH)),
|
2010-05-22 17:10:01 +00:00
|
|
|
'webroot' => 'webroot'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
2010-05-22 17:10:01 +00:00
|
|
|
$this->assertEquals($expected, $Dispatcher->params);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'./console/cake.php',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/cake',
|
|
|
|
'schema',
|
|
|
|
'run',
|
|
|
|
'create',
|
|
|
|
'-dry',
|
|
|
|
'-f',
|
|
|
|
'-name',
|
|
|
|
'DbAcl'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
2011-04-15 01:58:46 +00:00
|
|
|
'working' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH) . DS . 'app'),
|
|
|
|
'root' => str_replace('\\', '/', dirname(CAKE_CORE_INCLUDE_PATH)),
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
2010-10-10 03:09:19 +00:00
|
|
|
$expected = array(
|
|
|
|
'./console/cake.php', 'schema', 'run', 'create', '-dry', '-f', '-name', 'DbAcl'
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($expected, $Dispatcher->args);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'/cake/1.2.x.x/cake/console/cake.php',
|
|
|
|
'-working',
|
|
|
|
'/cake/1.2.x.x/app',
|
|
|
|
'schema',
|
|
|
|
'run',
|
|
|
|
'create',
|
|
|
|
'-dry',
|
|
|
|
'-name',
|
|
|
|
'DbAcl'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => '/cake/1.2.x.x/app',
|
|
|
|
'root' => '/cake/1.2.x.x',
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'C:/wamp/www/cake/app',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'C:/wamp/www/apps/cake/app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => 'C:\wamp\www\apps\cake\app',
|
|
|
|
'root' => 'C:\wamp\www\apps\cake'
|
|
|
|
);
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'C:\wamp\www\cake\app',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'C:\wamp\www\apps\cake\app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => 'C:\wamp\www\apps\cake\app',
|
|
|
|
'root' => 'C:\wamp\www\apps\cake'
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
2008-06-26 03:50:11 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'C:\wamp\www\apps',
|
|
|
|
'bake',
|
|
|
|
'-app',
|
|
|
|
'cake\app',
|
|
|
|
'-url',
|
|
|
|
'http://example.com/some/url/with/a/path'
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => 'C:\wamp\www\apps\cake\app',
|
|
|
|
'root' => 'C:\wamp\www\apps\cake',
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
|
|
|
|
2008-06-26 03:50:11 +00:00
|
|
|
$params = array(
|
|
|
|
'/home/amelo/dev/cake-common/cake/console/cake.php',
|
|
|
|
'-root',
|
|
|
|
'/home/amelo/dev/lsbu-vacancy',
|
|
|
|
'-working',
|
|
|
|
'/home/amelo/dev/lsbu-vacancy',
|
|
|
|
'-app',
|
|
|
|
'app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'app' => 'app',
|
|
|
|
'webroot' => 'webroot',
|
|
|
|
'working' => '/home/amelo/dev/lsbu-vacancy/app',
|
|
|
|
'root' => '/home/amelo/dev/lsbu-vacancy',
|
|
|
|
);
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
2009-07-27 16:57:58 +00:00
|
|
|
|
|
|
|
$params = array(
|
|
|
|
'cake.php',
|
|
|
|
'-working',
|
|
|
|
'D:\www',
|
|
|
|
'bake',
|
|
|
|
'my_app',
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'working' => 'D:\www',
|
|
|
|
'app' => 'www',
|
|
|
|
'root' => 'D:',
|
|
|
|
'webroot' => 'webroot'
|
|
|
|
);
|
|
|
|
|
|
|
|
$Dispatcher->params = $Dispatcher->args = array();
|
2008-06-26 03:50:11 +00:00
|
|
|
$Dispatcher->parseParams($params);
|
|
|
|
$this->assertEqual($expected, $Dispatcher->params);
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-13 00:33:53 +00:00
|
|
|
/**
|
2009-04-30 17:25:58 +00:00
|
|
|
* Verify loading of (plugin-) shells
|
2008-11-13 00:33:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetShell() {
|
2009-04-30 17:25:58 +00:00
|
|
|
$this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
|
|
|
|
$this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
|
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-10-18 01:04:14 +00:00
|
|
|
$result = $Dispatcher->getShell('sample');
|
|
|
|
$this->assertInstanceOf('SampleShell', $result);
|
2008-11-13 00:33:53 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2011-05-12 04:58:39 +00:00
|
|
|
$result = $Dispatcher->getShell('TestPlugin.example');
|
2010-10-18 01:04:14 +00:00
|
|
|
$this->assertInstanceOf('ExampleShell', $result);
|
2009-04-30 17:25:58 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of Shell subclasses with a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchShellWithMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2010-10-10 04:21:16 +00:00
|
|
|
$Mock = $this->getMock('Shell', array(), array(&$Dispatcher), 'MockWithMainShell');
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Mock->expects($this->once())->method('initialize');
|
|
|
|
$Mock->expects($this->once())->method('loadTasks');
|
2010-10-10 04:21:16 +00:00
|
|
|
$Mock->expects($this->once())->method('runCommand')
|
|
|
|
->with(null, array())
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher->TestShell = $Mock;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_with_main');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
2009-05-01 10:08:56 +00:00
|
|
|
$this->assertEqual($Dispatcher->args, array());
|
2009-04-30 17:25:58 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of Shell subclasses without a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchShellWithoutMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2010-10-10 04:21:16 +00:00
|
|
|
$Shell = $this->getMock('Shell', array(), array(&$Dispatcher), 'MockWithoutMainShell');
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-07-08 01:35:03 +00:00
|
|
|
$Shell = new MockWithoutMainShell($Dispatcher);
|
2010-05-22 17:10:01 +00:00
|
|
|
$this->mockObjects[] = $Shell;
|
2010-10-10 04:21:16 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->once())->method('initialize');
|
|
|
|
$Shell->expects($this->once())->method('loadTasks');
|
2010-10-10 04:21:16 +00:00
|
|
|
$Shell->expects($this->once())->method('runCommand')
|
|
|
|
->with('initdb', array('initdb'))
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_without_main', 'initdb');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of custom classes with a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchNotAShellWithMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
|
|
|
$methods = get_class_methods('Object');
|
|
|
|
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
|
2010-10-04 03:00:48 +00:00
|
|
|
$Shell = $this->getMock('Object', $methods, array(), 'MockWithMainNotAShell');
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->never())->method('initialize');
|
|
|
|
$Shell->expects($this->never())->method('loadTasks');
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_with_main_not_a');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
2009-05-01 10:08:56 +00:00
|
|
|
$this->assertEqual($Dispatcher->args, array());
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell = new MockWithMainNotAShell($Dispatcher);
|
|
|
|
$this->mockObjects[] = $Shell;
|
|
|
|
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_with_main_not_a', 'initdb');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-04-30 17:25:58 +00:00
|
|
|
/**
|
|
|
|
* Verify correct dispatch of custom classes without a main method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDispatchNotAShellWithoutMain() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
|
|
|
$methods = get_class_methods('Object');
|
|
|
|
array_push($methods, 'main', 'initdb', 'initialize', 'loadTasks', 'startup', '_secret');
|
|
|
|
$Shell = $this->getMock('Object', $methods, array(&$Dispatcher), 'MockWithoutMainNotAShell');
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell->expects($this->never())->method('initialize');
|
|
|
|
$Shell->expects($this->never())->method('loadTasks');
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Shell->expects($this->once())->method('main')->will($this->returnValue(true));
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_without_main_not_a');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
2010-05-22 17:10:01 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertEqual($Dispatcher->args, array());
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2010-05-22 17:10:01 +00:00
|
|
|
$Shell = new MockWithoutMainNotAShell($Dispatcher);
|
|
|
|
$this->mockObjects[] = $Shell;
|
|
|
|
$Shell->expects($this->once())->method('initdb')->will($this->returnValue(true));
|
|
|
|
$Shell->expects($this->once())->method('startup');
|
|
|
|
$Dispatcher->TestShell = $Shell;
|
2009-04-30 17:25:58 +00:00
|
|
|
|
2009-05-01 10:08:56 +00:00
|
|
|
$Dispatcher->args = array('mock_without_main_not_a', 'initdb');
|
2009-04-30 17:25:58 +00:00
|
|
|
$result = $Dispatcher->dispatch();
|
2009-05-02 21:34:39 +00:00
|
|
|
$this->assertTrue($result);
|
2009-05-01 10:08:56 +00:00
|
|
|
}
|
2009-08-09 10:54:41 +00:00
|
|
|
|
2009-05-01 01:47:33 +00:00
|
|
|
/**
|
|
|
|
* Verify shifting of arguments
|
2008-11-13 00:33:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testShiftArgs() {
|
2010-05-22 17:10:01 +00:00
|
|
|
$Dispatcher = new TestShellDispatcher();
|
2009-05-01 01:47:33 +00:00
|
|
|
|
|
|
|
$Dispatcher->args = array('a', 'b', 'c');
|
|
|
|
$this->assertEqual($Dispatcher->shiftArgs(), 'a');
|
|
|
|
$this->assertIdentical($Dispatcher->args, array('b', 'c'));
|
|
|
|
|
|
|
|
$Dispatcher->args = array('a' => 'b', 'c', 'd');
|
|
|
|
$this->assertEqual($Dispatcher->shiftArgs(), 'b');
|
|
|
|
$this->assertIdentical($Dispatcher->args, array('c', 'd'));
|
2008-11-13 00:33:53 +00:00
|
|
|
|
2009-05-01 01:47:33 +00:00
|
|
|
$Dispatcher->args = array('a', 'b' => 'c', 'd');
|
|
|
|
$this->assertEqual($Dispatcher->shiftArgs(), 'a');
|
|
|
|
$this->assertIdentical($Dispatcher->args, array('b' => 'c', 'd'));
|
2008-11-13 00:33:53 +00:00
|
|
|
|
2009-05-01 01:47:33 +00:00
|
|
|
$Dispatcher->args = array(0 => 'a', 2 => 'b', 30 => 'c');
|
|
|
|
$this->assertEqual($Dispatcher->shiftArgs(), 'a');
|
|
|
|
$this->assertIdentical($Dispatcher->args, array(0 => 'b', 1 => 'c'));
|
|
|
|
|
|
|
|
$Dispatcher->args = array();
|
|
|
|
$this->assertNull($Dispatcher->shiftArgs());
|
|
|
|
$this->assertIdentical($Dispatcher->args, array());
|
2008-11-13 00:33:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|