Ejemplo n.º 1
0
 public function getConstructorArgs()
 {
     try {
         $constructor = $this->object->getConstructor();
         if ($constructor !== null) {
             return Data\Generator::getPropsAsStringByReflectionMethod($constructor);
         }
         return '';
     } catch (\Exception $e) {
         echo "Problem with constructor in class " . $this->getOriginalFullClassName() . "\n";
         echo $e;
         exit;
     }
 }
 /**
  * get properties as dummy stub, e.g. "$message, $flag" will be transformed into "1, 2"
  *
  * tries to identify the correct types based on doc comments, otherwise or if comment doesnt match parameters, it will use the type hints
  *
  * @return string
  */
 public function getPropertyDummyStub(\PhpUnitTestGenerator\Generator\TestMethod $method, $withoutValues = false)
 {
     return Generator::getPropsAsStringByReflectionMethod($method->getOriginalMethod(), $withoutValues);
 }
 public function handleTestableMethod(\PhpUnitTestGenerator\Generator\TestMethod $method)
 {
     if ($this->isGetterMethod($method)) {
         $dummyValueType = "string";
         foreach ($method->getOriginalMethod()->getDocBlocks()->getTags() as $tag) {
             /* @var $tag \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag */
             if ($tag->getName() == "return") {
                 $dummyValueType = $tag->getType();
                 break;
             }
         }
         $dummyValue = Generator::getInstance()->getValueByType($dummyValueType);
         $excepted = Generator::getInstance()->getExceptedValueByType($dummyValueType);
         $assertion = Generator::getInstance()->getAssertionByType($dummyValueType);
         $method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_FINAL);
         $method->setContent(\PhpUnitTestGenerator\Resource\Helper::getParsedTemplateByNameAndHash('TestMethodGetter.tpl.dist', array('methodName' => ucfirst($method->getName()), 'origMethodName' => $method->getOriginalMethod()->getName(), 'className' => $method->getOriginalMethod()->getDeclaringClass()->getName(), 'methodShort' => str_replace('get', '', $method->getOriginalMethod()->getName()), 'dummyValue' => $dummyValue, 'excepted' => $excepted, 'assertion' => $assertion)));
     } elseif ($this->isSetterMethod($method)) {
         $dummyValueType = "string";
         foreach ($method->getOriginalMethod()->getDocBlocks()->getTags() as $tag) {
             /* @var $tag \phpDocumentor\Reflection\DocBlock\Tag\ParamTag */
             if ($tag->getName() == "param") {
                 $dummyValueType = $tag->getType();
                 break;
             }
         }
         $dummyValue = Generator::getInstance()->getValueByType($dummyValueType);
         $excepted = Generator::getInstance()->getExceptedValueByType($dummyValueType);
         $assertion = Generator::getInstance()->getAssertionByType($dummyValueType);
         $method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_ADDITIONAL);
         $method->setContent(\PhpUnitTestGenerator\Resource\Helper::getParsedTemplateByNameAndHash('TestMethodSetter.tpl.dist', array('methodName' => ucfirst($method->getName()), 'origMethodName' => $method->getOriginalMethod()->getName(), 'className' => $method->getOriginalMethod()->getDeclaringClass()->getName(), 'methodShort' => str_replace('set', '', $method->getOriginalMethod()->getName()), 'dummyValue' => $dummyValue, 'excepted' => $excepted, 'assertion' => $assertion)));
     }
 }