1<?php 2/* 3 * This file is part of PHPUnit. 4 * 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11/** 12 * Prints TestDox documentation in HTML format. 13 */ 14class PHPUnit_Util_TestDox_ResultPrinter_HTML extends PHPUnit_Util_TestDox_ResultPrinter 15{ 16 /** 17 * @var string 18 */ 19 private $pageHeader = <<<EOT 20<!doctype html> 21<html lang="en"> 22 <head> 23 <meta charset="utf-8"/> 24 <title>Test Documentation</title> 25 <style> 26 body { 27 text-rendering: optimizeLegibility; 28 font-variant-ligatures: common-ligatures; 29 font-kerning: normal; 30 margin-left: 2em; 31 } 32 33 body > ul > li { 34 font-family: Source Serif Pro, PT Sans, Trebuchet MS, Helvetica, Arial; 35 font-size: 2em; 36 } 37 38 h2 { 39 font-family: Tahoma, Helvetica, Arial; 40 font-size: 3em; 41 } 42 43 ul { 44 list-style: none; 45 margin-bottom: 1em; 46 } 47 </style> 48 </head> 49 <body> 50EOT; 51 52 /** 53 * @var string 54 */ 55 private $classHeader = <<<EOT 56 57 <h2 id="%s">%s</h2> 58 <ul> 59 60EOT; 61 62 /** 63 * @var string 64 */ 65 private $classFooter = <<<EOT 66 </ul> 67EOT; 68 69 /** 70 * @var string 71 */ 72 private $pageFooter = <<<EOT 73 74 </body> 75</html> 76EOT; 77 78 /** 79 * Handler for 'start run' event. 80 */ 81 protected function startRun() 82 { 83 $this->write($this->pageHeader); 84 } 85 86 /** 87 * Handler for 'start class' event. 88 * 89 * @param string $name 90 */ 91 protected function startClass($name) 92 { 93 $this->write( 94 sprintf( 95 $this->classHeader, 96 $name, 97 $this->currentTestClassPrettified 98 ) 99 ); 100 } 101 102 /** 103 * Handler for 'on test' event. 104 * 105 * @param string $name 106 * @param bool $success 107 */ 108 protected function onTest($name, $success = true) 109 { 110 $this->write( 111 sprintf( 112 " <li style=\"color: %s;\">%s %s</li>\n", 113 $success ? '#555753' : '#ef2929', 114 $success ? '✓' : '❌', 115 $name 116 ) 117 ); 118 } 119 120 /** 121 * Handler for 'end class' event. 122 * 123 * @param string $name 124 */ 125 protected function endClass($name) 126 { 127 $this->write($this->classFooter); 128 } 129 130 /** 131 * Handler for 'end run' event. 132 */ 133 protected function endRun() 134 { 135 $this->write($this->pageFooter); 136 } 137} 138