/**
  * 
  * Cleans all empty failures that were accidently inserted
  */
 private function cleanEmptyFailures()
 {
     //for each failure:
     if (KalturaTestListener::$testCaseFailures != null) {
         foreach (KalturaTestListener::$testCaseFailures->getTestProceduresFailures() as $testProcedureKey => $testProcedureFailure) {
             foreach ($testProcedureFailure->getTestCaseInstanceFailures() as $testCaseInstanceKey => $testCaseInstanceFailure) {
                 //if there were no failures
                 if (count($testCaseInstanceFailure->getFailures()) == 0) {
                     //delete the test case instance failure
                     $testProcedureFailure->removeTestCaseInstanceFailure($testCaseInstanceKey);
                 }
             }
             $cleanCasesFailures = $testProcedureFailure->getTestCaseInstanceFailures();
             if (count($cleanCasesFailures) == 0) {
                 KalturaTestListener::$testCaseFailures->removeTestProcedureFailure($testProcedureKey);
             }
         }
     }
 }
 /**
  * 
  * Update the data with the given failure
  * @param KalturaTestCaseDataFile $unitTestData
  * @param KalturaTestCaseFailures $testsFailures
  * @return KalturaTestCaseDataFile - The new unitTestDataFile with the changes
  */
 private static function update(KalturaTestCaseDataFile $testDataFile, KalturaTestCaseFailures $testCaseFailures)
 {
     //TODO: check this for no errors
     $newTestDataFile = unserialize(serialize($testDataFile));
     //For each test procedure failure
     foreach ($testCaseFailures->getTestProceduresFailures() as $testProcedureFailures) {
         //Get the test procedure name / key
         $testProcedureName = $testProcedureFailures->getTestProcedureName();
         KalturaLog::debug("testProcedureName [" . $testProcedureName . "]\n");
         foreach ($testProcedureFailures->getTestCaseInstanceFailures() as $testCaseInstanceFailure) {
             $testCaseInstanceKey = KalturaTestResultUpdater::getTestCaseInstnaceKey($newTestDataFile, $testCaseInstanceFailure);
             KalturaLog::debug("testCaseInstanceKey  [" . $testCaseInstanceKey . "]\n");
             //If key wasnt found skip the error
             if (is_null($testCaseInstanceKey)) {
                 KalturaLog::debug("Test case instance wasn't found [" . print_r($testCaseInstanceFailure, true) . "] ");
                 KalturaLog::debug("Skipping failure!!!");
                 continue;
             }
             //Update the values by its failures
             foreach ($testCaseInstanceFailure->getFailures() as $failure) {
                 $field = $failure->getField();
                 $actualValue = $failure->getActualValue();
                 $testProcedureData = $newTestDataFile->getTestProcedureData($testProcedureName);
                 $testCaseInstanceData = $testProcedureData->getTestCaseData($testCaseInstanceKey);
                 //Gets the first output reference
                 $outputReferenceObject = $testCaseInstanceData->getOutputReference(0);
                 //We update only the first output reference which is propel
                 $outputReferenceObject->setByName($field, $actualValue);
                 //If there are no dbValues yet we create the first ones
                 $oldComments = $outputReferenceObject->getComments();
                 if (!isset($oldComments[$field])) {
                     $outputReferenceObject->addComment($field, $failure->getOutputReferenceValue());
                 }
             }
         }
     }
     return $newTestDataFile;
 }
 /**
  * 
  * Returns the test cases failures as a DomDocument
  * @throws Exception
  * @return DomDocument
  */
 public static function toXML(KalturaTestCaseFailures $testCaseFailures, $rootNodeName = 'data')
 {
     if (count($testCaseFailures->getTestProceduresFailures()) == 0) {
         return "";
     }
     $dom = new DOMDocument("1.0");
     //Create elements in the Dom referencing the entire test data file
     $testCaseElement = $dom->createElement($rootNodeName);
     $testCaseElement->setAttribute("testCaseName", $testCaseFailures->getTestCaseName());
     $dom->appendChild($testCaseElement);
     //For each test data
     foreach ($testCaseFailures->getTestProceduresFailures() as $testProcedureFailure) {
         //Create the xml from the object
         $objectAsDOM = KalturaTestProcedureFailure::toXml($testProcedureFailure, "TestProcedureFailures");
         kXml::appendDomToElement($objectAsDOM, $testCaseElement, $dom);
     }
     return $dom;
 }