From f41549da7a7570ec9984a53f16abf863a716e55d Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Mon, 28 Oct 2024 23:45:51 +0300 Subject: [PATCH] chore: Remove Redeclaration --- .../cli/helpers/CreateAPITestCase.php | 19 ----- .../framework/writers/APITestCaseWriter.php | 72 +------------------ 2 files changed, 1 insertion(+), 90 deletions(-) diff --git a/webfiori/framework/cli/helpers/CreateAPITestCase.php b/webfiori/framework/cli/helpers/CreateAPITestCase.php index 97ef2a8c..d2691cb9 100644 --- a/webfiori/framework/cli/helpers/CreateAPITestCase.php +++ b/webfiori/framework/cli/helpers/CreateAPITestCase.php @@ -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; diff --git a/webfiori/framework/writers/APITestCaseWriter.php b/webfiori/framework/writers/APITestCaseWriter.php index beb08dfb..367f071c 100644 --- a/webfiori/framework/writers/APITestCaseWriter.php +++ b/webfiori/framework/writers/APITestCaseWriter.php @@ -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);