Ejemplo n.º 1
0
 function generar_layout()
 {
     $selecciones = $this->controlador->get_selecciones();
     echo "<div style='background-color: white; border: 1px solid black; text-align: left; padding: 15px'>";
     try {
         //Se construye un suite por categoria que tenga test seleccionados
         foreach (toba_test_lista_casos::get_categorias() as $categoria) {
             $test = new GroupTest($categoria['nombre']);
             $hay_uno = false;
             foreach (toba_test_lista_casos::get_casos() as $caso) {
                 if ($caso['categoria'] == $categoria['id'] && in_array($caso['id'], $selecciones['casos'])) {
                     $hay_uno = true;
                     require_once $caso['archivo'];
                     $test->addTestCase(new $caso['id']($caso['nombre']));
                 }
             }
             if ($hay_uno) {
                 //--- COBERTURA DE CODIGO (OPCIONAL) ----
                 if (function_exists('xdebug_start_code_coverage')) {
                     xdebug_start_code_coverage();
                 }
                 //-------
                 $test->run(new toba_test_reporter());
                 //--- COBERTURA DE CODIGO (OPCIONAL) ----
                 $arch = 'PHPUnit2/Util/CodeCoverage/Renderer.php';
                 $existe = toba_manejador_archivos::existe_archivo_en_path($arch);
                 if (function_exists('xdebug_start_code_coverage') && $existe) {
                     require_once $arch;
                     $cubiertos = xdebug_get_code_coverage();
                     //Se limpian las referencias a simpletest y a librerias de testing en gral.
                     $archivos = array();
                     foreach (array_keys($cubiertos) as $archivo) {
                         if (!strpos($archivo, 'simpletest') && !strpos($archivo, 'PHPUnit') && !strpos($archivo, 'testing_automatico/') && !strpos($archivo, '/test_')) {
                             $archivos[$archivo] = $cubiertos[$archivo];
                         }
                     }
                     $cc = PHPUnit2_Util_CodeCoverage_Renderer::factory('HTML', array('tests' => $archivos));
                     $path_temp = toba::proyecto()->get_path_temp_www();
                     $salida = $path_temp['real'] . '/cobertura.html';
                     $cc->renderToFile($salida);
                     echo "<a href='{$path_temp['browser']}/cobertura.html' target='_blank'>Ver cobertura de código</a>";
                 }
                 //-------
             }
         }
     } catch (Exception $e) {
         if (method_exists($e, 'mensaje_web')) {
             echo ei_mensaje($e->mensaje_web(), 'error');
         } else {
             echo $e;
         }
     }
     echo '</div><br>';
     $this->dep('lista_archivos')->generar_html();
 }
Ejemplo n.º 2
0
 /**
  * @param  PHPUnit2_Framework_TestResult $result
  * @param  mixed                         $coverageDataFile
  * @param  mixed                         $coverageHTMLFile
  * @param  mixed                         $coverageTextFile
  * @access protected
  * @since  Method available since Release 2.1.0
  */
 protected function handleCodeCoverageInformation(PHPUnit2_Framework_TestResult $result, $coverageDataFile, $coverageHTMLFile, $coverageTextFile)
 {
     if ($coverageDataFile !== FALSE && ($fp = fopen($coverageDataFile, 'w'))) {
         fputs($fp, serialize($result->getCodeCoverageInformation()));
         fclose($fp);
     }
     if ($coverageHTMLFile !== FALSE || $coverageTextFile !== FALSE) {
         require_once 'PHPUnit2/Util/CodeCoverage/Renderer.php';
         if ($coverageHTMLFile !== FALSE) {
             $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory('HTML', $result->getCodeCoverageInformation());
             $renderer->renderToFile($coverageHTMLFile);
         }
         if ($coverageTextFile !== FALSE) {
             $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory('Text', $result->getCodeCoverageInformation());
             $renderer->renderToFile($coverageTextFile);
         }
     }
 }