protected function writeServiceBaseAction($serviceId, $serviceName, $action, $actionParams, KalturaParamInfo $outputTypeReflector = null, $testReturnedType = 'int') { $actionName = ucfirst($action); $this->writeIni(""); $this->writeIni("[test{$actionName}]"); $this->writeBase("\t/**"); $this->writeBase("\t * Tests {$serviceName}->{$action} action"); $testParams = array(); $testValues = array(); $validateValues = array(); $addId = false; foreach ($actionParams as $actionParam) { $paramType = $actionParam->getType(); $paramName = $actionParam->getName(); if ($paramType == 'int' && $paramName == 'id') { $addId = true; $testValues[] = '$id'; $this->writeIni("test1.{$paramName}.type = dependency"); continue; } if ($actionParam->isSimpleType() || $actionParam->isEnum()) { $this->writeIni("test1.{$paramName} = " . $actionParam->getDefaultValue()); } elseif ($actionParam->isFile()) { $this->writeIni("test1.{$paramName}.type = file"); $this->writeIni("test1.{$paramName}.path = "); } else { $this->writeIni("test1.{$paramName}.type = {$paramType}"); $actionParamProperties = $actionParam->getTypeReflector()->getProperties(); foreach ($actionParamProperties as $actionParamProperty) { if ($actionParamProperty->isReadOnly() || $actionParamProperty->isInsertOnly()) { continue; } $propertyType = $actionParamProperty->getType(); $propertyName = $actionParamProperty->getName(); if ($actionParamProperty->isSimpleType() || $actionParamProperty->isEnum()) { $this->writeIni("test1.{$paramName}.{$propertyName} = " . $actionParamProperty->getDefaultValue()); } elseif ($actionParamProperty->isFile()) { $this->writeIni("test1.{$paramName}.{$propertyName}.type = file"); $this->writeIni("test1.{$paramName}.{$propertyName}.path = "); } else { $this->writeIni("test1.{$paramName}.{$propertyName}.type = {$propertyType}"); } } } $paramDesc = $actionParam->getDescription(); $this->writeBase("\t * @param {$paramType} \${$paramName} {$paramDesc}"); if (!$actionParam->isComplexType()) { $testParam = "\${$paramName}"; } else { $testParam = "{$paramType} \${$paramName}"; } if ($actionParam->isOptional()) { if ($actionParam->getDefaultValue()) { if ($actionParam->getType() == 'string') { $testParam .= " = '" . $actionParam->getDefaultValue() . "'"; } else { $testParam .= " = " . $actionParam->getDefaultValue(); } } else { $testParam .= " = null"; } } $testParams[] = $testParam; $testValues[] = "\${$paramName}"; $validateValues[] = "\${$paramName}"; } if ($outputTypeReflector) { $paramType = $outputTypeReflector->getType(); if ($outputTypeReflector->isSimpleType() || $outputTypeReflector->isEnum()) { $this->writeIni("test1.reference = " . $outputTypeReflector->getDefaultValue()); } elseif ($outputTypeReflector->isFile()) { $this->writeIni("test1.reference.type = file"); $this->writeIni("test1.reference.path = "); } else { $this->writeIni("test1.reference.type = {$paramType}"); $actionParamProperties = $outputTypeReflector->getTypeReflector()->getProperties(); foreach ($actionParamProperties as $actionParamProperty) { if ($actionParamProperty->isReadOnly()) { continue; } $propertyType = $actionParamProperty->getType(); $propertyName = $actionParamProperty->getName(); if ($actionParamProperty->isSimpleType() || $actionParamProperty->isEnum()) { $this->writeIni("test1.reference.{$propertyName} = " . $actionParamProperty->getDefaultValue()); } elseif ($actionParamProperty->isFile()) { $this->writeIni("test1.reference.{$propertyName}.type = file"); $this->writeIni("test1.reference.{$propertyName}.path = "); } else { $this->writeIni("test1.reference.{$propertyName}.type = {$propertyType}"); } } } $paramDesc = $outputTypeReflector->getDescription(); $this->writeBase("\t * @param {$paramType} \$reference {$paramDesc}"); if (!$outputTypeReflector->isComplexType()) { $testParam = "\$reference"; } else { $testParam = "{$paramType} \$reference"; } if ($outputTypeReflector->isOptional()) { if ($outputTypeReflector->getDefaultValue()) { if ($outputTypeReflector->getType() == 'string') { $testParam .= " = '" . $outputTypeReflector->getDefaultValue() . "'"; } else { $testParam .= " = " . $outputTypeReflector->getDefaultValue(); } } else { $testParam .= " = null"; } } $testParams[] = $testParam; $validateValues[] = "\$reference"; } if ($addId) { $this->writeBase("\t * @param int id - returned from testAdd"); $testParams[] = '$id'; } $testParams = implode(', ', $testParams); $testValues = implode(', ', $testValues); $validateValues = implode(', ', $validateValues); $outputType = null; if ($outputTypeReflector) { $outputType = $outputTypeReflector->getType(); } if ($testReturnedType) { $this->lastDependencyTest = "test{$actionName}"; $this->writeBase("\t * @return {$testReturnedType}"); } if ($addId) { if ($testReturnedType) { $this->writeBase("\t * @depends testAdd with data set #0"); } else { $this->writeBase("\t * @depends testFinished"); } } $this->writeBase("\t * @dataProvider provideData"); $this->writeBase("\t */"); $this->writeBase("\tpublic function test{$actionName}({$testParams})"); $this->writeBase("\t{"); $this->writeBase("\t\t\$resultObject = \$this->client->{$serviceName}->{$action}({$testValues});"); if ($outputType) { $this->writeBase("\t\t\$this->assertType('{$outputType}', \$resultObject);"); } if ($testReturnedType) { $this->writeBase("\t\t\$this->assertNotNull(\$resultObject->id);"); } $this->writeBase("\t\t\$this->validate{$actionName}({$validateValues});"); if ($testReturnedType) { $this->writeBase("\t\treturn \$resultObject->id;"); } $this->writeBase("\t}"); $this->writeBase(""); $this->writeBase("\t/**"); $this->writeBase("\t * Validates test{$actionName} results"); $this->writeBase("\t */"); $this->writeBase("\tprotected function validate{$actionName}({$testParams})"); $this->writeBase("\t{"); // TODO - add compare based on object type $this->writeBase("\t}"); $this->writeBase(""); $this->writeTest("\t/**"); $this->writeTest("\t * Validates test{$actionName} results"); $this->writeTest("\t */"); $this->writeTest("\tprotected function validate{$actionName}({$testParams})"); $this->writeTest("\t{"); $this->writeTest("\t\tparent::validate{$actionName}({$validateValues});"); $this->writeTest("\t\t// TODO - add your own validations here"); $this->writeTest("\t}"); $this->writeTest(""); }
/** * * Sets the test params and values for the given action param * @param string $actionParam * @param array $testParams - passed by reference * @param array $testValues - passed by reference * @param array $validateValues - passed by reference * @param boolean $isBase */ protected function setTestParamsAndValues(KalturaParamInfo $actionParam, &$testParams, &$testValues, &$validateValues, $isBase) { $paramType = $actionParam->getType(); $paramName = $actionParam->getName(); KalturaLog::debug("paramName [{$paramName}] paramType [{$paramType}]"); $isParamContainsId = substr_count($paramName, "id") > 0 || substr_count($paramName, "Id") > 0; if ($actionParam->isSimpleType() || $actionParam->isEnum() || $actionParam->isStringEnum() || $actionParam->isDynamicEnum()) { $paramDefaultValue = $actionParam->getDefaultValue(); $this->writeIni("test1.{$paramName} = " . $paramDefaultValue); } elseif ($actionParam->isFile()) { $this->writeIni("test1.{$paramName}.objectType = file"); $this->writeIni("test1.{$paramName}.path = "); } else { if ($paramName == 'type') { $this->writeIni("test1.objType.{$paramName} = {$paramType}"); } else { $this->writeIni("test1.{$paramName}.objectType = {$paramType}"); } $actionParamProperties = $actionParam->getTypeReflector()->getProperties(); foreach ($actionParamProperties as $actionParamProperty) { if ($actionParamProperty->isReadOnly() || $actionParamProperty->isInsertOnly()) { continue; } $propertyType = $actionParamProperty->getType(); $propertyName = $actionParamProperty->getName(); if ($actionParamProperty->isSimpleType() || $actionParamProperty->isEnum() || $actionParamProperty->isStringEnum() || $actionParamProperty->isDynamicEnum()) { $defaultValue = $actionParamProperty->getDefaultValue(); $this->writeIni("test1.{$paramName}.{$propertyName} = " . $defaultValue); } elseif ($actionParamProperty->isFile()) { $this->writeIni("test1.{$paramName}.{$propertyName}.objectType = file"); $this->writeIni("test1.{$paramName}.{$propertyName}.path = "); } elseif (!$actionParamProperty->isAbstract()) { if ($propertyName == 'type') { $this->writeIni("test1.{$paramName}.objType.{$propertyName} = {$propertyType}"); } else { $this->writeIni("test1.{$paramName}.{$propertyName}.objectType = {$propertyType}"); } } } } $paramDesc = strlen($actionParam->getDescription()) ? ' ' . $actionParam->getDescription() : ''; $this->write("\t * @param {$paramType} \${$paramName}{$paramDesc}", $isBase); if (!$actionParam->isComplexType() || $actionParam->isEnum() || $actionParam->isStringEnum() || $actionParam->isDynamicEnum()) { $testParam = "\${$paramName}"; } else { $testParam = "{$paramType} \${$paramName}"; } if ($actionParam->isOptional()) { if ($actionParam->isSimpleType()) { $defaultValue = $actionParam->getDefaultValue(); if ($defaultValue === "false") { $testParam .= " = false"; } else { if ($defaultValue === "true") { $testParam .= " = true"; } else { if ($defaultValue === "null") { $testParam .= " = null"; } else { if ($paramType == "string") { $testParam .= " = \"{$defaultValue}\""; } else { if ($paramType == "int" || $paramType == "bigint") { if ($defaultValue == "") { $testParam .= " = \"\""; } else { $testParam .= " = {$defaultValue}"; } } } } } } } else { $testParam .= " = null"; } } //Adds the new param / value to the test params / values $testParams[] = $testParam; $testValues[] = "\${$paramName}"; if ($isBase) { $validateValues[] = "\${$paramName}"; } }