Exemplo n.º 1
0
/**
 * A shorthand function to call Diagnostics output
 * @param mixed $mixed
 * @param string $title Title of the output
 */
function dump($mixed, $title = 'Variables Dump')
{
    if (is_string($mixed) && substr($mixed, 0, 5) == '<?xml') {
        // an XML dump
        if (!headers_sent()) {
            header('Content-Type:text/xml');
        }
        echo $mixed;
    } else {
        // standard dump
        Fari_ApplicationDiagnostics::dump($mixed, $title);
    }
}
 /**
  * Fire up a display with error message, sourcecode and some trace.
  * @return void
  */
 public function fire()
 {
     // get the specifics of the error
     // where was the error thrown
     $file = $this->getFile();
     // line with the error
     $line = $this->getLine();
     // message we are outputing
     $message = $this->getMessage();
     // trace of error
     $trace = $this->getTrace();
     Fari_ApplicationDiagnostics::display('Fari Exception', $file, $line, $message, $trace);
 }
/**
* Callback function forming a Diagnostics-like output.
* @param file
* @param line
* @param message String with the assertion
*/
function contractsCallback($file, $line, $message)
{
    // parse the comment in the message
    if (($position = strpos($message, '//')) !== FALSE) {
        // get the comment, trim whitespace and capitalize
        $title = ucfirst(trim(substr($message, $position + 2)));
        $message = '';
    } else {
        // don't bother and echo the assert statement
        $title = 'Contract Condition Failed';
        $message = "<br />{$message}";
    }
    // cleanup output
    ob_end_clean();
    ?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <title>Contract Condition Failed</title>
                 <style type="text/css">
                body{background:#fff;color:#33393c;font:12px/1.5 "Trebuchet MS", "Geneva CE", lucida,sans-serif;
                margin:0;}#title{background:#222;color:#565656;border-bottom:1px solid #C52F24;margin:0 auto;
                padding:10px 30px;}#message,.error{background-color:#C52F24;color:#fff;font-weight:700;
                font-size:100%;margin:0;padding:1px 0;}#message{border-top:1px solid #980905;padding:5px 30px 10px;}
                h1{margin-bottom:0;font-weight:400;font-size:175%;}#box{background-color:#EEE;border:1px solid #ADAEAF;
                margin:10px 30px 0;padding:5px;}#file{background-color:#D5E9F6;border:1px solid #8FCDF6;
                color:#234A69;margin:10px 30px 0;padding:5px;}.code{background-color:#FFF9D8;border:1px solid #FECA51;
                margin:10px 30px;padding:5px;}i{color:#999;}.num{color:#9E9E7E;font-style:normal;font-weight:400;}
                a{color:#980905;}table{font:16px/1.5 "Trebuchet MS", "Geneva CE", lucida, sans-serif;font-size:100%;}
                td{padding-right:20px;}#title b,span.err{color:#FFF;}
                </style>
            </head>

            <body>
                <div id="title"><b><?php 
    echo FARI;
    ?>
</b> running <b><?php 
    echo APP_VERSION;
    ?>
</b></div>
                <div id="message"><h1><?php 
    echo $title;
    ?>
</h1><?php 
    echo $message;
    ?>
</div>

                <div id="file">File: <b><?php 
    echo $file;
    ?>
</b> Line: <b><?php 
    echo $line;
    ?>
</b></div>

                <?php 
    Fari_ApplicationDiagnostics::showErrorSource($file, $line);
    ?>

            </body>
        </html>
        <?php 
}
Exemplo n.º 4
0
    /**
     * Show a resulting test report.
     */
    public function report()
    {
        // header formatting
        if ($this->failed === TRUE) {
            $title = 'Test(s) failed';
            $color = '#C52F24';
            $line = '#980905';
        } else {
            $title = 'All tests passed';
            $color = '#26BF26';
            $line = '#059824';
        }
        // HTML output
        ?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <title>Unit Testing</title>
                 <?php 
        Fari_ApplicationDiagnostics::jsToggle();
        ?>
                 <style type="text/css">
                body{background:#fff;color:#33393c;font:12px/1.5 "Trebuchet MS", "Geneva CE", lucida,sans-serif;
                margin:0;}#title{background:#222;color:#565656;border-bottom:1px solid <?php 
        echo $color;
        ?>
;
                margin:0 auto;padding:10px 30px;}#message{background-color:<?php 
        echo $color;
        ?>
;font-weight:700;
                color:#fff;font-size:100%;margin:0;padding:1px 0;}#message{border-top:1px solid <?php 
        echo $line;
        ?>
;
                padding:5px 30px 10px;}h1{margin-bottom:0;font-weight:400;font-size:175%;}#box{background-color:#EEE;
                border:1px solid #ADAEAF;margin:10px 30px 0;padding:5px;}#test{margin:10px 30px 0;padding:5px;background:#F5F5F5;
                color:#33393C;border:1px solid #CCCDCF;}#test .failed{color:#C52F24;}#test .passed{color:#008800;}
                i{color:#999;}.num{color:#9E9E7E;font-style:normal;font-weight:400;}a{color:#980905;}td{padding-right:20px;}
                table{font:16px/1.5 "Trebuchet MS", "Geneva CE", lucida, sans-serif;font-size:100%;}#title b,span.err{color:#FFF;}
                .code{background-color:#FFF9D8;border:1px solid #FECA51;margin:10px 30px;padding:5px;}.error{background-color:#C52F24;
                color:#fff;font-weight:700;background-color:#C52F24;font-size:100%;margin:0;padding:1px 0;}
                </style>
            </head>

            <body>
                <div id="title"><b><?php 
        echo FARI;
        ?>
</b> running <b><?php 
        echo APP_VERSION;
        ?>
</b></div>
                <div id="message"><h1><?php 
        echo $title;
        ?>
</h1></div>
                <?php 
        $i = 1;
        foreach ($this->results as $result) {
            ?>
                    <div id="test">
                        <div style="float:right;">
                            <?php 
            echo '<b>File:</b> ' . $result['trace'][0] . ' <b>Line:</b> ' . $result['trace'][1];
            echo '&nbsp;&nbsp;<a href="" onclick="toggle(\'' . $i . '\');return false;" >source</a>';
            ?>
                        </div>

                        <div class="<?php 
            echo $result['result'];
            ?>
">
                            <?php 
            echo '<b>' . ucfirst($result['result']) . '</b> ' . $result['name'];
            ?>
                        </div>

                        <?php 
            Fari_ApplicationDiagnostics::showErrorSource($result['trace'][0], $result['trace'][1], 6, $i);
            $i++;
            ?>
                    </div>
                <?php 
        }
        ?>
            </body>
        </html>
        <?php 
        die;
    }
Exemplo n.º 5
0
 /**
  * Echo the SQL statement into the view
  * @param string $statement SQL query string
  * @param array $values The values to insert, update
  * @param array/string $where The where clause
  * @return echo Query string into the view
  */
 private function toString($statement, array $values = NULL, $where = NULL)
 {
     // traverse the values and where clause arrays
     if (is_array($where)) {
         $binder = 'set';
         foreach (array($values, $where) as $array) {
             if (isset($array)) {
                 // replace bound parametres with actual values
                 $i = 0;
                 foreach ($array as $value) {
                     // determine value type of string or integer
                     $value = Fari_Filter::isInt($value) ? "{$value}" : "'{$value}'";
                     // we have a variable binding key
                     $statement = preg_replace("/:{$binder}{$i}/", $value, $statement);
                     $i++;
                 }
             }
             // a switch to keep track of which array are we traversing
             $binder = 'id';
         }
     }
     // echo into the view
     Fari_ApplicationDiagnostics::dump($statement, 'Fari_Db Query String');
 }