Beispiel #1
0
<?php

include __DIR__ . '/../vendor/autoload.php';
use Slince\Runner\Runner;
use Slince\Runner\ExaminationChain;
use Slince\Runner\Examination;
use Slince\Runner\Api;
use Slince\Runner\Assertion;
use Slince\Runner\Assertion\ResponseAssertion;
$api = new Api('http://www.qimuyu.com', 'GET', ['foo', 'bar']);
$examination = new Examination($api);
$responseAssertion = new ResponseAssertion();
$assertion = new Assertion($responseAssertion, 'isOk');
$examination->addAssertion($assertion);
$chain = new ExaminationChain();
$chain->enqueue($examination);
$runner = new Runner($chain);
$runner->run();
if ($runner->getStatus() == Runner::STATUS_WAITING) {
}
Beispiel #2
0
 /**
  * 生成测试报告
  * @param Runner $runner
  */
 protected function makeReport(Runner $runner)
 {
     $excel = new PHPExcel();
     $sheet = $excel->setActiveSheetIndex(0)->setCellValue('A1', 'ID')->setCellValue('B1', 'Url地址')->setCellValue('C1', '请求方法')->setCellValue('D1', '耗时')->setCellValue('E1', '测试结果')->setCellValue('F1', '备注')->setCellValue('G1', '断言结果')->setCellValue('H1', '响应');
     foreach ($this->extractDataFromChain($runner->getExaminationChain()) as $key => $data) {
         $key += 2;
         $sheet->setCellValue("A{$key}", $data['id'])->setCellValue("B{$key}", $data['url'])->setCellValue("C{$key}", $data['method'])->setCellValue("D{$key}", $data['consume'])->setCellValue("E{$key}", $data['status'])->setCellValue("F{$key}", $data['remark'])->setCellValue("G{$key}", $data['assertion'])->setCellValue("H{$key}", $data['response']);
     }
     $writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
     $filename = getcwd() . DIRECTORY_SEPARATOR . 'report.xlsx';
     if (file_exists($filename)) {
         $filename = str_replace('.xlsx', time() . '.xlsx', $filename);
     }
     $writer->save($filename);
 }