public function testRegisterMethodByProvidingEachArgument() { $method = new Method('rpcMethod', 'array_map', MethodTypes::ONE_WAY); $result = $this->server->registerMethod($method->getName(), $method->getCallback(), $method->getType()); $this->assertSame($this->server, $result, 'Method chaining violation at "registerMethod"'); $this->assertEquals(array($method), $this->server->getMethods()); }
public function testShouldThrowExceptionWhenResponseHeadersArgumentIsNotProvidedForMethodsOtherThanOneWay() { $method = new Method('name', function () { }); $this->setExpectedException('\\InvalidArgumentException', 'Response headers argument is required'); $method->call(array(), $this->request); }
/** * {@inheritDoc} */ public function registerMethod($name, $callback = null, $type = MethodTypes::BASIC) { if (!$name instanceof Method) { $name = new Method($name, $callback, $type); } $methodName = $name->getName(); foreach ($this->methods as &$methods) { if (isset($methods[$methodName])) { unset($methods[$methodName]); } } $this->methods[$name->getType()][$name->getName()] = $name; return $this; }