Development

Changeset 20488

You must first sign up to be able to contribute.

Changeset 20488

Show
Ignore:
Timestamp:
07/25/09 12:45:57 (5 years ago)
Author:
bschussek
Message:

Implemented handling of PHP errors in LimeOutputPipe?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/lime/branches/2.0-experimental/lib/LimeHarness.php

    r20482 r20488  
    6666    sort($this->files); 
    6767 
    68     $connector = new LimeOutputPipe($this->output); 
     68    $connector = new LimeOutputPipe($this->output, array('start', 'flush')); 
    6969 
    7070    foreach ($this->files as $file) 
    7171    { 
     72      $this->output->start($file); 
    7273      $connector->connect($file); 
    7374    } 
  • tools/lime/branches/2.0-experimental/lib/output/LimeOutputPipe.php

    r20482 r20488  
    1313{ 
    1414  protected 
     15    $suppressedMethods = array(), 
    1516    $error = false, 
    1617    $buffer = '', 
    1718    $output = null; 
    1819 
    19   public function __construct(LimeOutputInterface $output
     20  public function __construct(LimeOutputInterface $output, array $suppressedMethods = array()
    2021  { 
    2122    $this->output = $output; 
     23    $this->suppressedMethods = $suppressedMethods; 
    2224  } 
    2325 
     
    6365        } 
    6466 
    65         if ($method != 'flush'
     67        if (!in_array($method, $this->suppressedMethods)
    6668        { 
    6769          foreach ($arguments as &$argument) 
     
    7880 
    7981    $this->buffer = implode("\n", $lines); 
     82 
     83    while (!empty($this->buffer)) 
     84    { 
     85      if (preg_match('/^\s*([\w\s]+)(: .+) in (.+) on line (\d+)/', $this->buffer, $matches)) 
     86      { 
     87        $this->buffer = trim(substr($this->buffer, strlen($matches[0]))); 
     88 
     89        if ($matches[1] == 'Warning') 
     90        { 
     91          $this->output->warning($matches[1].$matches[2], $matches[3], $matches[4]); 
     92        } 
     93        else 
     94        { 
     95          $this->output->error($matches[1].$matches[2], $matches[3], $matches[4]); 
     96        } 
     97 
     98        // consume Xdebug call stack 
     99        while (preg_match('/^(Call Stack:|\d\.\d+\s+\d+\s+\d+\.\s+.+:\d+)/', $this->buffer, $matches)) 
     100        { 
     101          $this->buffer = trim(substr($this->buffer, strlen($matches[0]))); 
     102        } 
     103      } 
     104      else 
     105      { 
     106        break; 
     107      } 
     108    } 
    80109  } 
    81110 
  • tools/lime/branches/2.0-experimental/test/unit/output/LimeOutputPipeTest.php

    r20482 r20488  
    1414LimeAnnotationSupport::enable(); 
    1515 
    16 $t = new LimeTest(9); 
     16$t = new LimeTest(12); 
    1717 
    1818 
     
    8282 
    8383 
    84 // @Test: The call to flush() is NOT passed 
     84// @Test: Method calls can be suppressed by passing the first constructor parameter 
    8585 
    8686  // fixtures 
    87   $output->flush()->never(); 
     87  $output->invoke('pass')->never(); 
    8888  $output->replay(); 
     89  $connector = new LimeOutputPipe($output, array('pass')); 
    8990  file_put_contents($file, <<<EOF 
    9091<?php 
    91 echo serialize(array("flush", array()))."\n"; 
     92echo serialize(array("pass", array("A passed test", "/test/file", 11)))."\n"; 
    9293EOF 
    9394  ); 
     
    158159  $connector->connect($file); 
    159160 
     161 
     162// @Test: A PHP error is passed to error() - invalid identifier 
     163 
     164  // @Test: Case 1 - Invalid identifier 
     165 
     166  // fixtures 
     167  $output->error("Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$'", $file, 1); 
     168  $output->replay(); 
     169  file_put_contents($file, '<?php $1invalidname;'); 
     170  // test 
     171  $connector->connect($file); 
     172  // assertions 
     173  $output->verify(); 
     174 
     175 
     176  // @Test: Case 2 - Failed require 
     177 
     178  // fixtures 
     179  $output->warning("Warning: require(foobar.php): failed to open stream: No such file or directory", $file, 1); 
     180  $output->error("Fatal error: require(): Failed opening required 'foobar.php' (include_path='".get_include_path()."')", $file, 1); 
     181  $output->replay(); 
     182  file_put_contents($file, '<?php require "foobar.php";'); 
     183  // test 
     184  $connector->connect($file); 
     185  // assertions 
     186  $output->verify();