7 require_once('../../lib/DebugHtml.php');
 
   9 class DebugTest extends \PHPUnit\Framework\TestCase
 
  11     protected function setUp()
 
  13         $this->oWithDebuginfo = $this->getMock(Geocode::class, array('debugInfo'));
 
  14         $this->oWithDebuginfo->method('debugInfo')
 
  15                   ->willReturn(array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'));
 
  17         $this->oWithToString = $this->getMock(Geocode::class, array('__toString'));
 
  18         $this->oWithToString->method('__toString')->willReturn('me as string');
 
  21     public function testPrintVar()
 
  23         $this->expectOutputString(<<<EOT
 
  24 <pre><b>Var0:</b>  </pre>
 
  25 <pre><b>Var1:</b>  <i>True</i></pre>
 
  26 <pre><b>Var2:</b>  <i>False</i></pre>
 
  27 <pre><b>Var3:</b>  0</pre>
 
  28 <pre><b>Var4:</b>  'String'</pre>
 
  29 <pre><b>Var5:</b>  0 => 'one'
 
  32 <pre><b>Var6:</b>  'key' => 'value'
 
  33        'key2' => 'value2'</pre>
 
  34 <pre><b>Var7:</b>  me as string</pre>
 
  35 <pre><b>Var8:</b>  'value', 'value2'</pre>
 
  40         Debug::printVar('Var0', null);
 
  41         Debug::printVar('Var1', true);
 
  42         Debug::printVar('Var2', false);
 
  43         Debug::printVar('Var3', 0);
 
  44         Debug::printVar('Var4', 'String');
 
  45         Debug::printVar('Var5', array('one', 'two', 'three'));
 
  46         Debug::printVar('Var6', array('key' => 'value', 'key2' => 'value2'));
 
  47         Debug::printVar('Var7', $this->oWithToString);
 
  48         Debug::printVar('Var8', Debug::fmtArrayVals(array('key' => 'value', 'key2' => 'value2')));
 
  52     public function testDebugArray()
 
  54         $this->expectOutputString(<<<EOT
 
  55 <pre><b>Arr0:</b>  'null'</pre>
 
  56 <pre><b>Arr1:</b>  'key1' => 'val1'
 
  58        'key3' => 'val3'</pre>
 
  63         Debug::printDebugArray('Arr0', null);
 
  64         Debug::printDebugArray('Arr1', $this->oWithDebuginfo);
 
  68     public function testPrintDebugTable()
 
  70         $this->expectOutputString(<<<EOT
 
  80     <th><small>0</small></th>
 
  81     <th><small>1</small></th>
 
  84     <td><pre>'one'</pre></td>
 
  85     <td><pre>'two'</pre></td>
 
  88     <td><pre>'three'</pre></td>
 
  89     <td><pre>'four'</pre></td>
 
  95     <th><small>key1</small></th>
 
  96     <th><small>key2</small></th>
 
  97     <th><small>key3</small></th>
 
 100     <td><pre>'val1'</pre></td>
 
 101     <td><pre>'val2'</pre></td>
 
 102     <td><pre>'val3'</pre></td>
 
 109         Debug::printDebugTable('Table1', null);
 
 111         Debug::printDebugTable('Table2', array());
 
 114         Debug::printDebugTable('Table3', array(array('one', 'two'), array('three', 'four')));
 
 117         Debug::printDebugTable('Table4', array($this->oWithDebuginfo));
 
 120     public function testPrintGroupTable()
 
 122         $this->expectOutputString(<<<EOT
 
 132     <th><small>Group</small></th>
 
 133     <th><small>key1</small></th>
 
 134     <th><small>key2</small></th>
 
 137     <td><pre>group1</pre></td>
 
 138     <td><pre>'val1'</pre></td>
 
 139     <td><pre>'val2'</pre></td>
 
 142     <td><pre>group1</pre></td>
 
 143     <td><pre>'one'</pre></td>
 
 144     <td><pre>'two'</pre></td>
 
 147     <td><pre>group2</pre></td>
 
 148     <td><pre>'val1'</pre></td>
 
 149     <td><pre>'val2'</pre></td>
 
 155     <th><small>Group</small></th>
 
 156     <th><small>key1</small></th>
 
 157     <th><small>key2</small></th>
 
 158     <th><small>key3</small></th>
 
 161     <td><pre>group1</pre></td>
 
 162     <td><pre>'val1'</pre></td>
 
 163     <td><pre>'val2'</pre></td>
 
 164     <td><pre>'val3'</pre></td>
 
 167     <td><pre>group1</pre></td>
 
 168     <td><pre>'val1'</pre></td>
 
 169     <td><pre>'val2'</pre></td>
 
 170     <td><pre>'val3'</pre></td>
 
 177         Debug::printGroupTable('Table1', null);
 
 178         Debug::printGroupTable('Table2', array());
 
 180         // header are taken from first group item, thus no key3 gets printed
 
 183                                  array('key1' => 'val1', 'key2' => 'val2'),
 
 184                                  array('key1' => 'one', 'key2' => 'two', 'unknown' => 1),
 
 187                                  array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'),
 
 190         Debug::printGroupTable('Table3', $aGroups);
 
 193                     'group1' => array($this->oWithDebuginfo, $this->oWithDebuginfo),
 
 195         Debug::printGroupTable('Table4', $aGroups);