Skip to content

Commit

Permalink
CLI parameters now work like MVC parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
SidRoberts committed Oct 30, 2016
1 parent 5815135 commit 1169273
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 73 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
# [4.0.0](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0) (2017-XX-XX)
- CLI parameters now work like MVC parameters

# [3.0.2](https://github.com/phalcon/cphalcon/releases/tag/v3.0.2) (2016-XX-XX)
- Fixed saving snapshot data while caching model [#12170](https://github.com/phalcon/cphalcon/issues/12170), [#12000](https://github.com/phalcon/cphalcon/issues/12000)
- Fixed `Phalcon\Http\Response\Headers::send` to send correct status header [#12179](https://github.com/phalcon/cphalcon/issues/12179)
Expand Down
5 changes: 0 additions & 5 deletions phalcon/cli/dispatcher.zep
Expand Up @@ -148,9 +148,4 @@ class Dispatcher extends \Phalcon\Dispatcher implements DispatcherInterface
{
return this->_options;
}

public function callActionMethod(handler, string actionMethod, array! params = [])
{
return call_user_func_array([handler, actionMethod], [params]);
}
}
7 changes: 1 addition & 6 deletions phalcon/dispatcher.zep
Expand Up @@ -585,7 +585,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac

try {
// We update the latest value produced by the latest handler
let this->_returnedValue = this->callActionMethod(handler, actionMethod, params);
let this->_returnedValue = call_user_func_array([handler, actionMethod], params);
} catch \Exception, e {
if this->{"_handleException"}(e) === false {
if this->_finished === false {
Expand Down Expand Up @@ -731,11 +731,6 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
return handlerClass;
}

public function callActionMethod(handler, string actionMethod, array! params = [])
{
return call_user_func_array([handler, actionMethod], params);
}

/**
* Set empty properties to their defaults (where defaults are available)
*/
Expand Down
5 changes: 1 addition & 4 deletions tests/_data/tasks/MainTask.php
Expand Up @@ -12,11 +12,8 @@ public function requestRegistryAction()
return $this->di['registry']->data;
}

public function helloAction($params = array())
public function helloAction($world = "", $symbol = "!")
{
$world = isset($params[0]) ? $params[0] : "";
$symbol = isset($params[1]) ? $params[1] : "!";

return "Hello " . $world . $symbol;
}
}
12 changes: 6 additions & 6 deletions tests/_data/tasks/ParamsTask.php
Expand Up @@ -2,16 +2,16 @@

class ParamsTask extends \Phalcon\CLI\Task
{
public function paramsAction($params)
public function paramsAction()
{
return ($params === $this->dispatcher->getParams())
? '$params is the same as $this->dispatcher->getParams()'
: '$params is not the same as $this->dispatcher->getParams()';
return (func_get_args() === $this->dispatcher->getParams())
? 'Action params are the same as $this->dispatcher->getParams()'
: 'Action params are not the same as $this->dispatcher->getParams()';
}

public function paramAction($params)
public function paramAction($param)
{
return ($params[0] === $this->dispatcher->getParam(0))
return ($param === $this->dispatcher->getParam(0))
? '$param[0] is the same as $this->dispatcher->getParam(0)'
: '$param[0] is not the same as $this->dispatcher->getParam(0)';
}
Expand Down
25 changes: 1 addition & 24 deletions tests/unit/Cli/DispatcherTest.php
Expand Up @@ -113,7 +113,7 @@ function () {
$dispatcher->setActionName('params');
$dispatcher->setParams(array('This', 'Is', 'An', 'Example'));
$dispatcher->dispatch();
expect($dispatcher->getReturnedValue())->equals('$params is the same as $this->dispatcher->getParams()');
expect($dispatcher->getReturnedValue())->equals('Action params are the same as $this->dispatcher->getParams()');

// Test $this->dispatcher->getParam()
$dispatcher->setTaskName('params');
Expand All @@ -124,27 +124,4 @@ function () {
}
);
}

public function testCallActionMethod()
{
$this->specify(
"CLI Dispatcher's callActionMethod doesn't work as expected",
function () {
$di = new CliFactoryDefault();

$dispatcher = new Dispatcher();

$di->setShared("dispatcher", $dispatcher);

$dispatcher->setDI($di);

$mainTask = new \MainTask();
$mainTask->setDI($di);

expect($dispatcher->callActionMethod($mainTask, 'mainAction', []))->equals('mainAction');
expect($dispatcher->callActionMethod($mainTask, 'helloAction', ['World']))->equals('Hello World!');
expect($dispatcher->callActionMethod($mainTask, 'helloAction', ['World', '.']))->equals('Hello World.');
}
);
}
}
2 changes: 1 addition & 1 deletion tests/unit/Cli/TaskTest.php
Expand Up @@ -45,7 +45,7 @@ function () {

expect($task->requestRegistryAction())->equals("data");
expect($task->helloAction())->equals("Hello !");
expect($task->helloAction(["World"]))->equals("Hello World!");
expect($task->helloAction("World"))->equals("Hello World!");

$task2 = new \EchoTask();
$task2->setDI($di);
Expand Down
27 changes: 0 additions & 27 deletions tests/unit/Mvc/DispatcherTest.php
Expand Up @@ -473,33 +473,6 @@ function () {
);
}

public function testCallActionMethod()
{
$this->specify(
"Action method isn't called properly",
function () {
$di = new FactoryDefault();

$dispatcher = new Dispatcher();

$di->setShared("dispatcher", $dispatcher);

$dispatcher->setDI($di);

$mainTask = new \Test2Controller();
$mainTask->setDI($di);

$actionMethod = $dispatcher->callActionMethod(
$mainTask,
"anotherTwoAction",
[1, 2]
);

expect($actionMethod)->equals(3);
}
);
}

public function testLastController()
{
$this->specify(
Expand Down

0 comments on commit 1169273

Please sign in to comment.