John Wildenauer - 2004-08-05

G'day All,

Re: PHP5.0.0 Compliance Testing 04.Aug.2004

Here's some patches to get phpunit to run with PHP4 legacy code

Perhaps it may be of help ... perhaps not !!!

Regards
John

php.MVC is an open source framework for PHP Web applications
http://www.phpmvc.net/

<?php
//
// PHP framework for testing, based on the design of "JUnit".
//
// Written by Fred Yankowski <fred@ontosys.com>
//            OntoSys, Inc  <http://www.OntoSys.com>
//
// $Id: phpunit.php,v 1.20 2004/07/31 07:35:03 shleh Exp $

// Copyright (c) 2000 Fred Yankowski

--- cut ---

// JCW: PHP5.0.0 Compliance Testing 04.Aug.2004

// Modified JCW 04.Aug.2004
// ~~~~~~~~~~~~~~~~~~~~~~~~
// Note: E_STRICT  (PHP5 compliance) will cause PHP4 code to fail.
//       So we skip non E_STRICT errors that copntain the string 'var: Deprecated'
//       As in: var: Deprecated. Please use the public/private/protected modifiers
// Note: Exception is a PHP(5)! reserved word.
//       So rename all instances of "Exception" to "Exception_"

// This does NOT work here !
// It will work for included files !!!.
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE |
        E_CORE_ERROR | E_CORE_WARNING);

/*
interface Test {
  function run(&$aTestResult);
  function countTestCases();
}
*/

function trace($msg) {
  return;
  print($msg);
  flush();
}

// Modified JCW 04.Aug.2004
// See: L231 set_error_handler("PHPUnit_error_handler")
if (phpversion() >= '4') {
    function PHPUnit_error_handler($errno, $errstr, $errfile, $errline) {
        global $PHPUnit_testRunning;
        #echo $errno.'<br><br>';
        if( (error_reporting() < E_STRICT && ! strstr($errstr, 'var: Deprecated') )
            || (error_reporting() == E_STRICT) ) {
            echo "<br>".error_reporting()."$errstr <br>";
            $PHPUnit_testRunning[0]->fail("<B>PHP ERROR:</B> ".$errstr." <B>in</B> ".
                                                        $errfile." <B>at line</B> ".$errline);
        }
    }
}

// Modified JCW 04.Aug.2004
class Exception_ {
    /* Emulate a Java Exception_, sort of... */
  var $message;
  var $type;
  function Exception_($message, $type = 'FAILURE') {
    $this->message = $message;
    $this->type = $type;
  }
  function getMessage() {
    return $this->message;
  }
  function getType() {
    return $this->type;
  }
}

--- cut ---

}