PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/_src/core/zepto/testcase/test/fet/bin/record.php

https://github.com/leaven/gmu
PHP | 111 lines | 84 code | 9 blank | 18 comment | 8 complexity | de24b629d7bbd7e781fb0e7f66cf4691 MD5 | raw file
  1. <?php
  2. /**
  3. * 追加接口参数,支持过滤成功用例
  4. * @param unknown_type $onlyfails
  5. */
  6. require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '../conf/Config.php';
  7. require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '../lib/php/geneHTML.php';
  8. function interXML( $onlyfails )
  9. {
  10. $report = ConfigTest::$testdir . 'report/report.xml';
  11. if ( !file_exists( $report ) )
  12. return array();
  13. $xmlFile = simpleXML_load_file( $report );
  14. $caseList = array();
  15. foreach ( $xmlFile->testsuite as $testsuite ) {
  16. foreach ( $testsuite->testcase as $testResult ) {
  17. // $totalCov = 0;
  18. $browser = $testResult[ 'browserInfo' ];
  19. $host = $testResult[ 'hostInfo' ];
  20. $caseName = $testResult[ 'name' ]; //得到用例名称
  21. settype( $caseName , "string" ); //$caseName本来类型为object,需要做转换
  22. $fail = $testResult[ 'failNumber' ];
  23. $total = $testResult[ 'totalNumber' ];
  24. $cov = $testResult[ 'cov' ];
  25. $recordCovForBrowser = $testResult[ 'recordCovForBrowser' ];
  26. settype( $browser , "string" );
  27. settype( $recordCovForBrowser , "string" );
  28. settype( $host , "string" );
  29. settype( $fail , "string" );
  30. settype( $total , "string" );
  31. settype( $cov , "float" );
  32. if ( !array_key_exists( $caseName , $caseList ) ) { //如果这个用例不存在
  33. $caseInfo = array(
  34. 'hostInfo' => $host ,
  35. 'fail' => $fail ,
  36. 'total' => $total ,
  37. 'cov' => $cov ,
  38. 'recordCovForBrowser' => $recordCovForBrowser
  39. );
  40. // $totalCov += $cov;
  41. $caseList[ $caseName ] = array(
  42. $browser => $caseInfo //,
  43. // 'totalCov'=>$totalCov
  44. );
  45. // $caseList['totalCov'] = $totalCov;
  46. } else { //否则添加到相应的用例中去
  47. $foundCase = $caseList[ $caseName ]; //找到用例名称对应的array,$caseName为key
  48. if ( !array_key_exists( $browser , $foundCase ) ) { //如果没有该浏览器信息,则添加
  49. // $totalCov += $cov;
  50. $caseList[ $caseName ][ $browser ] = array(
  51. 'hostInfo' => $host ,
  52. 'fail' => $fail ,
  53. 'total' => $total ,
  54. 'cov' => $cov ,
  55. 'recordCovForBrowser' => $recordCovForBrowser
  56. );
  57. // $caseList[$caseName]['totalCov'] = $totalCov;
  58. } else {
  59. $foundBrowser = $foundCase[ $browser ]; //有这个浏览器
  60. array_push( $foundBrowser , array(
  61. 'hostInfo' => $host ,
  62. 'fail' => $fail ,
  63. 'total' => $total ,
  64. 'cov' => $cov ,
  65. 'recordCovForBrowser' => $recordCovForBrowser
  66. ) );
  67. }
  68. }
  69. }
  70. }
  71. //根据需求添加仅记录失败情况的接口
  72. if ( $onlyfails ) { //如果仅考虑失败情况,此处根据用例情况过滤
  73. foreach ( $caseList as $name => $info ) {
  74. $all_success = true; //记录当前用例是否全部运行成功
  75. foreach ( $info as $b => $result ) {
  76. if ( $result[ 'fail' ] > 0 )
  77. $all_success = false;
  78. //如果有失败情况则终止循环并进入下一个用例分析
  79. break;
  80. }
  81. //if($all_success) //如果全部通过则从记录中移除
  82. //unset($caseList[$name]);
  83. }
  84. }
  85. return $caseList;
  86. }
  87. function record()
  88. {
  89. $kissList = interXML( false );
  90. if ( sizeof( $kissList ) > 0 ) {
  91. //针对kissList过滤,移除全部正确用例
  92. $html = geneHTML( $kissList );
  93. // echo $html;
  94. $report = ConfigTest::$testdir . 'report/report.html';
  95. $handle = fopen( "$report" , "w" );
  96. fwrite( $handle , $html );
  97. fclose( $handle );
  98. // require_once 'geneHistory.php';
  99. // geneHistory($html);
  100. }
  101. }
  102. ?>