예제 #1
0
 /**
  * Returns a method in the current specification from a DOMNode
  *
  * @param \DOMNode $node A DOMNode
  *
  * @return Method
  */
 public function getMethod(\DOMNode $node)
 {
     $crawler = new Crawler($node);
     $name = $crawler->attr('name');
     // Initialize
     $method = new Method($name);
     // Type
     $method->setType(preg_match('/(^(get|is)|ToString$)/', $name) ? Method::TYPE_ACCESSOR : Method::TYPE_ACTION);
     // Description
     $descriptions = $crawler->filterXPath('//comment');
     if (count($descriptions) !== 1) {
         throw new \Exception('Only one comment expected');
     }
     $descriptions->rewind();
     $description = $this->getInner($descriptions->current());
     $method->setDescription($description);
     // Parameters
     foreach ($crawler->filterXPath('//parameter') as $node) {
         $method->addParameter($this->getParameter($node));
     }
     // Return
     $returnNodes = $crawler->filterXPath('//return');
     if (count($returnNodes) > 1) {
         throw new \Exception("Should not be more than one return node");
     } elseif (count($returnNodes) == 1) {
         $returnNodes->rewind();
         list($type, $description) = $this->getReturn($returnNodes->current());
         $method->setReturnType($type);
         $method->setReturnDescription($description);
     }
     return $method;
 }
예제 #2
0
 /**
  * Dumps a method.
  *
  * @param Selenium\Specification\Method $method Specification of a method
  */
 protected function dumpMethod(Method $method)
 {
     $builder = new MethodBuilder();
     $documentation = $method->getDescription() . "\n\n";
     $signature = array();
     foreach ($method->getParameters() as $parameter) {
         $builder->addParameter($parameter->getName());
         $documentation .= "@param string \$" . $parameter->getName() . " " . $parameter->getDescription() . "\n\n";
         $signature[] = '$' . $parameter->getName();
     }
     $signature = implode(', ', $signature);
     if ($method->isAction()) {
         $documentation .= '@return Selenium\\Browser Fluid interface';
         $body = '$this->driver->action("' . $method->getName() . '"' . ($signature ? ', ' . $signature : '') . ');' . "\n";
         $body .= "\n";
         $body .= "return \$this;";
     } else {
         $returnType = $method->getReturnType();
         $documentation .= '@return ' . $returnType . ' ' . $method->getReturnDescription();
         if ($returnType === 'boolean') {
             $getMethod = 'getBoolean';
         } elseif ($returnType === 'string') {
             $getMethod = 'getString';
         } elseif ($returnType === 'string[]') {
             $getMethod = 'getStringArray';
         } elseif ($returnType === 'number') {
             $getMethod = 'getNumber';
         }
         $body = 'return $this->driver->' . $getMethod . '("' . $method->getName() . '"' . ($signature ? ', ' . $signature : '') . ');';
     }
     $builder->setName($method->getName());
     $builder->setBody($body);
     $builder->setDocumentation($documentation);
     return $builder->buildCode();
 }