Skip to content

Commit

Permalink
Removing Object::dispatchMethod, previously used by collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Apr 17, 2014
1 parent b80a970 commit 1a004f9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 95 deletions.
29 changes: 0 additions & 29 deletions src/Core/Object.php
Expand Up @@ -45,35 +45,6 @@ public function toString() {
return get_class($this);
}

/**
* Calls a method on this object with the given parameters. Provides an OO wrapper
* for `call_user_func_array`
*
* @param string $method Name of the method to call
* @param array $params Parameter list to use when calling $method
* @return mixed Returns the result of the method call
*/
public function dispatchMethod($method, array $params = []) {
switch (count($params)) {
case 0:
return $this->{$method}();
case 1:
return $this->{$method}($params[0]);
case 2:
return $this->{$method}($params[0], $params[1]);
case 3:
return $this->{$method}($params[0], $params[1], $params[2]);
case 4:
return $this->{$method}($params[0], $params[1], $params[2], $params[3]);
case 5:
return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
default:
// @codingStandardsIgnoreStart
return call_user_func_array([&$this, $method], $params);
// @codingStandardsIgnoreEnd
}
}

/**
* Stop execution of the current script. Wraps exit() making
* testing easier.
Expand Down
66 changes: 0 additions & 66 deletions tests/TestCase/Core/ObjectTest.php
Expand Up @@ -258,70 +258,4 @@ public function testToString() {
$this->assertEquals(strtolower(__NAMESPACE__) . '\testobject', $result);
}

/**
* testMethodDispatching method
*
* @return void
*/
public function testMethodDispatching() {
$this->object->emptyMethod();
$expected = array('emptyMethod');
$this->assertSame($this->object->methodCalls, $expected);

$this->object->oneParamMethod('Hello');
$expected[] = array('oneParamMethod' => array('Hello'));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->twoParamMethod(true, false);
$expected[] = array('twoParamMethod' => array(true, false));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->threeParamMethod(true, false, null);
$expected[] = array('threeParamMethod' => array(true, false, null));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->crazyMethod(1, 2, 3, 4, 5, 6, 7);
$expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
$this->assertSame($this->object->methodCalls, $expected);

$this->object = new TestObject();
$this->assertSame($this->object->methodCalls, array());

$this->object->dispatchMethod('emptyMethod');
$expected = array('emptyMethod');
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('oneParamMethod', array('Hello'));
$expected[] = array('oneParamMethod' => array('Hello'));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('twoParamMethod', array(true, false));
$expected[] = array('twoParamMethod' => array(true, false));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('threeParamMethod', array(true, false, null));
$expected[] = array('threeParamMethod' => array(true, false, null));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('fourParamMethod', array(1, 2, 3, 4));
$expected[] = array('fourParamMethod' => array(1, 2, 3, 4));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('fiveParamMethod', array(1, 2, 3, 4, 5));
$expected[] = array('fiveParamMethod' => array(1, 2, 3, 4, 5));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('crazyMethod', array(1, 2, 3, 4, 5, 6, 7));
$expected[] = array('crazyMethod' => array(1, 2, 3, 4, 5, 6, 7));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('methodWithOptionalParam', array('Hello'));
$expected[] = array('methodWithOptionalParam' => array("Hello"));
$this->assertSame($this->object->methodCalls, $expected);

$this->object->dispatchMethod('methodWithOptionalParam');
$expected[] = array('methodWithOptionalParam' => array(null));
$this->assertSame($this->object->methodCalls, $expected);
}

}

0 comments on commit 1a004f9

Please sign in to comment.