public function testParseSimpleMethod() { $className = '\\Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClass'; $reflection = new \ReflectionClass($className); $method = $reflection->getMethod('simpleMethod'); $instance = new MethodParser([new \ReflectionClass('\\Webiny\\Component\\Rest\\Tests\\Mocks\\MockApiClass')], $method, true); $parsedMethod = $instance->parse(); $this->assertInstanceOf('\\Webiny\\Component\\Rest\\Parser\\ParsedMethod', $parsedMethod); // validate parsed method $this->assertSame('simpleMethod', $parsedMethod->name); $this->assertSame('simple-method/', $parsedMethod->urlPattern); $this->assertSame('get', $parsedMethod->method); $this->assertFalse($parsedMethod->role); $this->assertSame(['ttl' => 0], $parsedMethod->cache); $this->assertFalse($parsedMethod->default); $header = ['cache' => ['expires' => 0], 'status' => ['success' => 200, 'error' => 404, 'errorMessage' => '']]; $this->assertSame($header, $parsedMethod->header); $this->assertCount(0, $parsedMethod->params); }
/** * Parsed the class methods and assigns them to the ParsedClass instance. * * @throws RestException */ private function parseMethods() { $methods = $this->reflectionClass->getMethods(); // this still returns the methods for all parent classes if (!is_array($methods) || count($methods) < 1) { throw new RestException('Parser: The class "' . $this->class . '" doesn\'t have any methods defined.'); } foreach ($methods as $m) { if ($m->isPublic()) { $methodParser = new MethodParser($this->parentClasses, $m, $this->normalize); $parsedMethod = $methodParser->parse(); if ($parsedMethod) { $this->parsedClass->addApiMethod($parsedMethod); } } } }