Exemplo n.º 1
0
 /**
  * List the endpoints the controller provides.
  *
  * It is the endpoint name, not the method name that is given. Endpoints
  * are grouped by http verb and will have their documentation listed. If
  * the endpoint has been "hidden" by the controller, it will not be listed.
  *
  * @return array
  */
 protected function getEndpoints()
 {
     if (!$this->endpointsCache) {
         $isHidden = $this->getControllerMethod('isMethodHidden');
         $endpoints = [];
         $parts = [];
         $methods = $this->reflectedController->getMethods(\ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             if (preg_match('/([a-z]+)([A-Z]\\w+)Endpoint$/', $method->getName(), $parts)) {
                 if (!$isHidden($method->getName())) {
                     $httpVerb = strtolower($parts[1]);
                     $endpoint = $this->camelcaseToHyphenated($parts[2]);
                     if (!array_key_exists($httpVerb, $endpoints)) {
                         $endpoints[$httpVerb] = array();
                     }
                     $endpoints[$httpVerb][$endpoint] = $this->documentation->getMethodDocumentation($method);
                 }
             }
         }
         $this->endpointsCache = $endpoints;
     }
     return $this->endpointsCache;
 }
Exemplo n.º 2
0
 /**
  * @test
  * @covers ::getMethodDocumentation
  * @uses \AyeAye\Api\Documentation
  */
 public function testGetMethodDocumentation()
 {
     $documentation = new Documentation();
     $method = $this->createDocBlock();
     $expected = ['summary' => "Test Summary\non two lines.", 'description' => "Test Description\non\nthree lines.", 'parameters' => ['incomplete' => ['type' => '', 'description' => ''], 'integer' => ['type' => 'int', 'description' => 'Test integer'], 'string' => ['type' => 'string', 'description' => "Test string\nSecond line"]], 'returnType' => ['string']];
     $this->assertSame($expected, $documentation->getMethodDocumentation($method));
     $method = $this->createDocBlockWithLineBreak();
     $expected = ['summary' => "This is a\nthree line summary\nwith a break", 'description' => "This is a one line description", 'parameters' => [], 'returnType' => ['self']];
     $this->assertSame($expected, $documentation->getMethodDocumentation($method));
     $method = $this->createDocBlockNoDescriptionMultiReturnType();
     $expected = ['summary' => "This is a summary. There is no description", 'parameters' => [], 'returnType' => ['null', 'mixed']];
     $this->assertSame($expected, $documentation->getMethodDocumentation($method));
     $method = $this->createEmptyDocBlock();
     $expected = ['parameters' => [], 'returnType' => []];
     $this->assertSame($expected, $documentation->getMethodDocumentation($method));
 }