/** * (non-PHPdoc) * @see ClientGeneratorFromPhp::writeServiceAction() */ protected function writeServiceAction($serviceId, $serviceName, $action, $actionParams, $outputTypeReflector) { KalturaLog::debug("Service id [{$serviceId}] name [{$serviceName}] action [{$action}]"); /* @var $outputTypeReflector KalturaParamInfo */ if ($outputTypeReflector && $outputTypeReflector->isFile()) { KalturaLog::debug("Service id [{$serviceId}] name [{$serviceName}] action [{$action}] is file"); return; } if (in_array($action, array("list", "clone", "goto"))) { $action = "{$action}Action"; } //KalturaLog::info("Generates action [$serviceName.$action]"); $isBase = false; $testReturnedType = null; $dependency = null; //Set the tests to be the regression tests if ($action == 'add' || $action == 'update' || $action == 'get' || $action == 'listAction' || $action == 'delete') { $isBase = true; } //Createds the dependency between the tests to the add tests if ($action == 'update') { $dependency = 'testAdd'; } if ($action == 'get') { $dependency = 'testUpdate'; } if ($action == 'delete') { $dependency = 'testGet'; } //Special care for add method as it needs to return the id to the other tests if ($action == 'add' || $action == 'update' || $action == 'get') { $outputType = $outputTypeReflector->getType(); $testReturnedType = "{$outputType}"; // for the dependency (CRUD) } if ($action) { $actionName = ucfirst($action); } $this->writeIni(""); $this->writeIni("[test{$actionName}]"); $this->write("\t/**", $isBase); $this->write("\t * Tests {$serviceName}->{$action} action", $isBase); $testParams = array(); $testValues = array(); $validateValues = array(); foreach ($actionParams as $actionParam) { $this->setTestParamsAndValues($actionParam, $testParams, $testValues, $validateValues, $isBase); } if ($outputTypeReflector) { $this->setOutputData($outputTypeReflector, $testParams, $testValues, $isBase, $validateValues); } $testParams = implode(', ', $testParams); $testValues = implode(', ', $testValues); $validateValues = implode(', ', $validateValues); $outputType = null; if ($outputTypeReflector) { $outputType = $outputTypeReflector->getType(); } if ($testReturnedType) { $this->lastDependencyTest = "test{$actionName}"; $this->write("\t * @return {$testReturnedType}", $isBase); //will always be for the base } if ($dependency) { $this->write("\t * @depends {$dependency} with data set #0", $isBase); } if (count($testValues)) { $this->write("\t * @dataProvider provideData", $isBase); } $this->writeActionTest($serviceName, $actionName, $action, $testParams, $testValues, $outputType, $isBase, $testReturnedType, $validateValues); if ($isBase && $outputType) { $this->writeBase("\t/**"); $this->writeBase("\t * Validates test{$actionName} results"); $this->writeBase("\t * Hook to be overriden by the extending class"); $this->writeBase("\t * "); $this->writeBase("\t * @param {$outputType} \$resultObject"); $this->writeBase("\t */"); $this->writeBase("\tprotected function validate{$actionName}({$outputType} \$resultObject){}"); $this->writeBase(""); $serviceReflector = KalturaServiceReflector::constructFromServiceId($serviceId); $serviceClass = $serviceReflector->getServiceClass(); $this->writeTest("\t/* (non-PHPdoc)"); $this->writeTest("\t * @see {$serviceClass}TestBase::validate{$actionName}()"); $this->writeTest("\t */"); $this->writeTest("\tprotected function validate{$actionName}({$outputType} \$resultObject)"); $this->writeTest("\t{"); //$this->writeTest(" parent::validate{$actionName}($validateValues);"); $this->writeTest("\t\t// TODO - add your own validations here"); $this->writeTest("\t}"); $this->writeTest(""); } }
/** * (non-PHPdoc) * @see ClientGeneratorFromPhp::writeServiceAction() */ protected function writeServiceAction($serviceId, $serviceName, $action, $actionParams, $outputTypeReflector) { if ($outputTypeReflector && $outputTypeReflector->isFile()) { return; } if (in_array($action, array("list", "clone", "goto"))) { $action = "{$action}Action"; } //KalturaLog::info("Generates action [$serviceName.$action]"); $isBase = false; $testReturnedType = null; $addId = false; //Set the tests to be the regression tests if ($action == 'add' || $action == 'update' || $action == 'get' || $action == 'listAction' || $action == 'delete' || $action == 'addFromEntry' && $serviceName == 'documents') { $isBase = true; } //Createds the dependency between the tests to the add tests if ($action == 'update' || $action == 'get' || $action == 'delete') { // || $action == 'listAction' TODO: add list if needed $addId = true; } //Special care for add method as it needs to return the id to the other tests if ($action == 'add' || $action == 'addFromEntry' && $serviceName == 'documents') { //TODO: support return type of int $outputType = $outputTypeReflector->getType(); $testReturnedType = "{$outputType}"; // for the dependency (CRUD) } //TODO:delete this $resgressionTests = array('add', 'get', 'delete', 'update', 'listAction'); if (!in_array($action, $resgressionTests)) { return; } if ($action) { $actionName = ucfirst($action); } $this->writeIni(""); $this->writeIni("[test{$actionName}]"); $this->writeXml("<TestProcedureData testProcedureName='test{$actionName}'>"); $this->writeXml("\t<TestCaseData testCaseInstanceName='test{$actionName} with data set #0'>"); $this->writeXmlSource("\t\t<TestProcedureData testProcedureName='test{$actionName}'>"); $this->writeXmlSource("\t\t\t<TestCaseData testCaseInstanceName='test{$actionName} with template data set'>"); $this->write("\t/**", $isBase); $this->write("\t * Tests {$serviceName}->{$action} action", $isBase); $testParams = array(); $testValues = array(); $validateValues = array(); foreach ($actionParams as $actionParam) { $this->setTestParamsAndValues($actionParam, $testParams, $testValues, $validateValues, $addId, $isBase); } if ($outputTypeReflector) { $this->setOutputData($outputTypeReflector, $testParams, $testValues, $isBase, $validateValues); } $this->writeXml("\t</TestCaseData>"); $this->writeXml("</TestProcedureData>"); $this->writeXmlSource("\t\t\t</TestCaseData>"); $this->writeXmlSource("\t\t</TestProcedureData>"); $testParams = implode(', ', $testParams); $testValues = implode(', ', $testValues); $validateValues = implode(', ', $validateValues); $outputType = null; if ($outputTypeReflector) { $outputType = $outputTypeReflector->getType(); } if ($testReturnedType) { $this->lastDependencyTest = "test{$actionName}"; $this->write("\t * @return {$testReturnedType}", $isBase); //will always be for the base } if ($addId) { $this->write("\t * @depends testAdd with data set #{$this->dependencyIndex}", $isBase); $this->dependencyIndex++; } if (count($testValues)) { $this->write("\t * @dataProvider provideData", $isBase); } $this->writeActionTest($serviceName, $actionName, $action, $testParams, $testValues, $outputType, $isBase, $testReturnedType, $validateValues); if ($isBase && $outputType) { $this->writeBase("\t/**"); $this->writeBase("\t * Validates test{$actionName} results"); $this->writeBase("\t * Hook to be overriden by the extending class"); $this->writeBase("\t * "); $this->writeBase("\t * @param {$outputType} \$resultObject"); $this->writeBase("\t */"); $this->writeBase("\tprotected function validate{$actionName}({$outputType} \$resultObject){}"); $this->writeBase(""); $serviceReflector = KalturaServiceReflector::constructFromServiceId($serviceId); $serviceClass = $serviceReflector->getServiceClass(); $this->writeTest("\t/* (non-PHPdoc)"); $this->writeTest("\t * @see {$serviceClass}TestBase::validate{$actionName}()"); $this->writeTest("\t */"); $this->writeTest("\tprotected function validate{$actionName}({$outputType} \$resultObject)"); $this->writeTest("\t{"); //$this->writeTest(" parent::validate{$actionName}($validateValues);"); $this->writeTest("\t\t// TODO - add your own validations here"); $this->writeTest("\t}"); $this->writeTest(""); } }