From 5bab349082328e668f13c5192dd5555b99201fa9 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 27 Aug 2024 09:14:17 +0300 Subject: [PATCH] feat: Automation of Writing Unit Test Cases for APIs --- .../cli/helpers/APITestCaseWriter.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 webfiori/framework/cli/helpers/APITestCaseWriter.php diff --git a/webfiori/framework/cli/helpers/APITestCaseWriter.php b/webfiori/framework/cli/helpers/APITestCaseWriter.php new file mode 100644 index 00000000..cb3852f6 --- /dev/null +++ b/webfiori/framework/cli/helpers/APITestCaseWriter.php @@ -0,0 +1,77 @@ +setSuffix('Test'); + + + } + + + /** + * Returns the web service object which was associated with the writer. + * + * @return AbstractWebService + */ + public function getService() : AbstractWebService { + return $this->serviceObj; + } + + /** + * Sets the table that the writer will use in writing the table class. + * + * @param AbstractWebService $service + */ + public function setService(AbstractWebService $service) { + $this->serviceObj = $service; + } + + /** + * Write the test case class. + * + */ + public function writeClass() { + $this->addAllUse(); + parent::writeClass(); + } + + public function writeClassBody() { + $this->append('}'); + } + + public function writeClassComment() { + $this->append("/**\n" + ." * A unit test class which is used to test the API '".$this->getService()->getName()."'.\n" + ); + $this->append(" * \n */"); + } + + public function writeClassDeclaration() { + $this->append('class '.$this->getName().' extends APITestCase {'); + } + private function addAllUse() { + $this->addUseStatement(APITestCase::class); + } + +}