Skip to content

Commit

Permalink
feat: Automation of Writing Unit Test Cases for APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Aug 27, 2024
1 parent aef4319 commit 5bab349
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions webfiori/framework/cli/helpers/APITestCaseWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace webfiori\framework\cli\helpers;

use webfiori\framework\writers\ClassWriter;
use webfiori\http\AbstractWebService;
use webfiori\http\APITestCase;

/**
* A helper class which is used to write unit test cases for web services.
*
* @author Ibrahim
*/
class APITestCaseWriter extends ClassWriter {
/**
*
* @var AbstractWebService
*/
private $serviceObj;
/**
* Creates new instance of the class.
*
*/
public function __construct($tableObj = null) {
parent::__construct('NewTable', ROOT_PATH.'tests\\apis', ROOT_PATH.'tests\\apis');
$this->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(" * </ul>\n */");
}

public function writeClassDeclaration() {
$this->append('class '.$this->getName().' extends APITestCase {');
}
private function addAllUse() {
$this->addUseStatement(APITestCase::class);
}

}

0 comments on commit 5bab349

Please sign in to comment.