Skip to content

Commit

Permalink
chore: Remove Redeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Oct 28, 2024
1 parent 1f27350 commit f41549d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 90 deletions.
19 changes: 0 additions & 19 deletions webfiori/framework/cli/helpers/CreateAPITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,6 @@ private function checkPlace($ns) {
$this->writeClass();
}
}
private function readServiceInfo() {
$selected = $this->getCommand()->getArgValue('--service');
$services = $this->writer->getServicesManager()->getServices();
if ($selected !== null) {
if (!isset($services[$selected])) {
$this->info('Selected services manager has no service with name \''.$selected.'\'.');
} else {
$this->writer->setService($services[$selected]);
return true;
}
}
if (count($services) == 0) {
$this->info('Provided services manager has 0 registered services.');
return false;
}
$selected = $this->select('Which service you would like to have a test case for?', array_keys($services));
$this->writer->setService($services[$selected]);
return true;
}
private function readManagerInfo() {
$m = $this->getCommand()->getArgValue('--manager');
$instance = null;
Expand Down
72 changes: 1 addition & 71 deletions webfiori/framework/writers/APITestCaseWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,77 +152,7 @@ public function writeClassComment() {
public function writeClassDeclaration() {
$this->append('class '.$this->getName().' extends APITestCase {');
}
private function writeRequiredParametersTestCases() {
$params = $this->getService()->getParameters();
$responseMessage = ResponseMessage::get('404-2');
$missingArr = [];
foreach ($params as $param) {

if (!$param->isOptional()) {
$missingArr[] = $param->getName();
}
}
if (count($missingArr) !== 0) {
$requestMethod = $this->getService()->getRequestMethods()[0];
$this->addTestAnnotation();
$this->append('public function testRequiredParameters() {', 1);
$this->append('$output = $this->callEndpoint(new '.$this->getServicesManagerName().'(), RequestMethod::'. strtoupper($requestMethod).', '.$this->getServiceName().'::class, []);', 2);
$this->append("\$this->assertEquals('{'.self::NL", 2);
$this->append(". ' \"message\":\"$responseMessage\'". implode("\',", $missingArr)."\'.\",'.self::NL", 2);
$this->append(". ' \"type\":\"error\",'.self::NL", 2);
$this->append(". ' \"http_code\":404,'.self::NL", 2);
$this->append(". ' \"more_info\":{'.self::NL", 2);
$this->append(". ' \"missing\":['.self::NL", 2);
for ($x = 0 ; $x < count($missingArr) ; $x++) {
$item = $missingArr[$x];
if ($x + 1 == count($missingArr)) {
$this->append(". ' \"$item\"'.self::NL", 2);
} else {
$this->append(". ' \"$item\",'.self::NL", 2);
}
}
$this->append(". ' ]'.self::NL", 2);
$this->append(". ' }'.self::NL", 2);
$this->append(". '}', \$output);", 2);
$this->append('}', 1);
}
}
private function writeTestCases() {
$methods = $this->getService()->getRequestMethods();
$testCasesCount = 0;

foreach (RequestMethod::getAll() as $method) {
if (in_array($method, $methods)) {
$this->addTestAnnotation();
$this->append('public function test'.$method.'Request00() {', 1);
$this->append("//TODO: Write test case for $method request.", 2);
$methodName = $this->getMethName($method);

if (count($this->getService()->getParameters()) == 0) {
if ($methodName == 'callEndpoint') {
$this->append('$output = $this->'.$methodName.'(new '.$this->getServicesManagerName().'(), RequestMethod::'. strtoupper($method).', '.$this->getServiceName().'::class, []);', 2);
} else {
$this->append('$output = $this->'.$methodName.'(new '.$this->getServicesManagerName().'(), '.$this->getServiceName().'::class, []);', 2);
}
} else {
if ($methodName == 'callEndpoint') {
$this->append('$output = $this->'.$methodName.'(new '.$this->getServicesManagerName().'(), RequestMethod::'. strtoupper($method).', '.$this->getServiceName().'::class, [', 2);
} else {
$this->append('$output = $this->'.$methodName.'(new '.$this->getServicesManagerName().'(), '.$this->getServiceName().'::class, [', 2);
}
foreach ($this->getService()->getParameters() as $reqParam) {
$this->append("'".$reqParam->getName()."' => null,", 3);
}
$this->append(']);', 2);
}

$this->append("\$this->assertEquals('{'.self::NL", 2);
$this->append(". '}', \$output);", 2);
$this->append('}', 1);
$testCasesCount++;
}
}
}

private function addAllUse() {
$this->addUseStatement(APITestCase::class);
$this->addUseStatement(RequestMethod::class);
Expand Down

0 comments on commit f41549d

Please sign in to comment.