/**
  * 
  * 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;
 }
 /**
  * 
  * Generates a new KalturaTestsFailures object from a given failure file path 
  * @param string $failureFilePath
  */
 public static function generateFromXml($failureFilePath)
 {
     $testsFailures = new KalturaTestCaseFailures();
     $testsFailures->fromXml($failureFilePath);
     return $testsFailures;
 }
 /**
  * 
  * Writes the listener failures to the given file
  */
 private function writeFailuresToFile()
 {
     if (KalturaTestListener::$testCaseFailures != null) {
         $testCaseFailuresXml = KalturaTestCaseFailures::toXml(KalturaTestListener::$testCaseFailures, "TestCaseFailures");
         if ($testCaseFailuresXml != null) {
             $testCaseFailuresXml->formatOutput = true;
             $failuresAsXml = $testCaseFailuresXml->saveXML();
             fwrite(KalturaTestListener::$failuresFile, $failuresAsXml);
             KalturaTestResultUpdater::UpdateResults(KalturaTestListener::$dataFilePath, KalturaTestListener::$failureFilePath);
             //Write the failures into the global failures file
             fwrite(KalturaTestListener::$totalFailureFile, $failuresAsXml);
         } else {
             //				print("failures XML is null!!!\n");
             KalturaLog::debug("failures XML is null!!!");
         }
     }
 }