From 1a004f912fbfb4931632b0063c3bdefcc09bba28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Fri, 11 Apr 2014 00:30:12 +0200 Subject: [PATCH] Removing Object::dispatchMethod, previously used by collections. --- src/Core/Object.php | 29 ------------- tests/TestCase/Core/ObjectTest.php | 66 ------------------------------ 2 files changed, 95 deletions(-) diff --git a/src/Core/Object.php b/src/Core/Object.php index e7e03b9ffc4..473c2a3edaa 100644 --- a/src/Core/Object.php +++ b/src/Core/Object.php @@ -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. diff --git a/tests/TestCase/Core/ObjectTest.php b/tests/TestCase/Core/ObjectTest.php index 34d15053df5..490e47f6fb4 100644 --- a/tests/TestCase/Core/ObjectTest.php +++ b/tests/TestCase/Core/ObjectTest.php @@ -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); - } - }