/** * fill the method with a body(test) * * @param \PhpUnitTestGenerator\Generator\TestMethod $method * @return void */ public function handleTestableMethod(\PhpUnitTestGenerator\Generator\TestMethod $method) { //$method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_FINAL); $doc = $this->getParsedDocComment($method); if ($doc !== null) { if ($doc->hasTag("return")) { $returns = $doc->getTagsByName("return"); $return = $returns[0]; $type = $return->getType(); } } if ($method->getOriginalMethod()->isStatic()) { $tpl = 'TestMethodInternalTypeStatic.tpl.dist'; } else { $tpl = 'TestMethodInternalType.tpl.dist'; } $method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_ADDITIONAL); $method->setContent(\PhpUnitTestGenerator\Resource\Helper::getParsedTemplateByNameAndHash($tpl, array('methodName' => ucfirst($method->getName()), 'origMethodName' => $method->getOriginalMethod()->getName(), 'className' => '\\' . $method->getOriginalMethod()->getDeclaringClass()->getName(), 'type' => $type, 'arguments' => $this->getPropertyDummyStub($method, true)))); }
/** * fill the method with a body(test) * * @param \PhpUnitTestGenerator\Generator\TestMethod $method * @return void */ public function handleTestableMethod(\PhpUnitTestGenerator\Generator\TestMethod $method) { //$method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_FINAL); $doc = $this->getParsedDocComment($method); if ($doc !== null) { if ($doc->hasTag("return")) { $returns = $doc->getTagsByName("return"); $return = $returns[0]; $type = $return->getType(); } } /* $this->assert{assertion}( {expected}, {className}::{origMethodName}({arguments}) ); */ $method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_ADDITIONAL); $method->setContent(\PhpUnitTestGenerator\Resource\Helper::getParsedTemplateByNameAndHash('TestMethodStatic.tpl.dist', array('methodName' => ucfirst($method->getName()), 'origMethodName' => $method->getOriginalMethod()->getName(), 'className' => '\\' . $method->getOriginalMethod()->getDeclaringClass()->getName(), 'type' => $type, 'arguments' => $this->getPropertyDummyStub($method, true), 'assertion' => 'InstanceOf', 'expected' => '"' . str_replace('\\', '\\\\', $type) . '"'))); }
public function handleTestableMethod(\PhpUnitTestGenerator\Generator\TestMethod $method) { $method->setStatus(\PhpUnitTestGenerator\Generator\TestMethod::STATUS_FINAL); $method->setContent(\PhpUnitTestGenerator\Resource\Helper::getParsedTemplateByNameAndHash('TestMethodSingleton.tpl.dist', array('methodName' => ucfirst($method->getName()), 'origMethodName' => $method->getOriginalMethod()->getName(), 'className' => '\\' . $method->getOriginalMethod()->getDeclaringClass()->getName()))); }
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))); } }