Ejemplo n.º 1
0
 /**
  * @runInSeparateProcess
  */
 public function testSetPathWithPrefixes()
 {
     $endpoint = new Endpoint();
     Endpoint::pushPrefix('v1');
     $endpoint->setPath('resource');
     $this->assertEquals($endpoint->getPath(), '/v1/resource');
     Endpoint::popPrefix();
     $endpoint->setPath('dummy');
     $this->assertEquals($endpoint->getPath(), '/dummy');
 }
Ejemplo n.º 2
0
 public function testGroupEndpoints()
 {
     $parser = new Parser();
     // <stub>
     $endpointsStub = [];
     $groups = ['first', 'second'];
     for ($i = 0; $i < 10; $i++) {
         $endpoint = new Endpoint();
         $endpoint->setGroup($groups[round(rand(0, 1))]);
         $endpointsStub[] = $endpoint;
     }
     // </stub>
     $grouped = $parser->groupEndpoints($endpointsStub);
     $this->assertGreaterThan(1, count($grouped['first']));
     $this->assertGreaterThan(1, count($grouped['second']));
 }
Ejemplo n.º 3
0
 public function parseTags(&$endpoint, $line)
 {
     $line = trim(preg_replace('/\\*/', '', $line, 1));
     if (empty($line)) {
         return null;
     }
     if ($line[0] === '@') {
         // matching @tags
         if (preg_match('/^@(\\w*?)\\s(.*?)$/i', $line, $matches)) {
             $tag = strtolower($matches[1]);
             $value = $matches[2];
             // check if tag is valid, store it to endpoint
             if (Endpoint::isTag($tag)) {
                 $fn = 'set' . $tag;
                 $endpoint->{$fn}($value);
             }
         }
     } elseif (!$endpoint->getTitle()) {
         // by default
         $endpoint->setTitle($line);
     } elseif (!$endpoint->getDescription()) {
         // also by default
         $endpoint->setDescription($line);
     }
 }