/** * Render CSV output * * @param Suite $suite * @return void */ public static function render(Suite $suite) { $name = preg_replace('#[^a-z0-9]+#i', '-', strtolower($suite->getName())); // sanitize filename header('Content-type: text/csv'); header('Content-Disposition: attachment; filename=' . trim($name, '-') . '.env.csv'); header('Pragma: no-cache'); header('Expires: 0'); foreach ($suite as $group => $tests) { foreach ($tests as $order => $test) { $message = is_scalar($message = $test->getStatusMessage()) ? $message : json_encode($message); $options = $test->getOptions() ? '<br/>' . json_encode($test->getOptions()) : ''; if ($test->isEnabled()) { $data = array($test->getStatus(), $group . ':' . $test->getName(), $test->getNotice(), $test->getType(), $test->isOk() ? 'OK' : preg_replace('/\\s+/i', ' ', trim($message . $options)), $order); echo addslashes(implode(', ', $data)) . PHP_EOL; } } } }
<?php /** * Example how to test Memcached connection and return HTML output * * @author Roman Ozana <*****@*****.**> */ require_once dirname(__DIR__) . '/vendor/autoload.php'; if (PHP_SAPI === 'cli') { // client $_SERVER['REQUEST_URI'] = 'http://example.com/envtesting/'; $_SERVER['QUERY_STRING'] = 'type=sometype'; } $suite = \envtesting\Suite::instance('memcached suit'); $suite->addTest('memcache', new \envtests\services\memcache\Connection('127.0.0.1', 11211), 'service'); // KISS $suite->run()->render('html');
/** * Render HTML output * * @param Suite $suite * @return void */ public static function render(Suite $suite) { $total = $error = $warning = $exception = $ok = $disabled = 0; $filter = $suite->getFilter(); require __DIR__ . '/layout.phtml'; }
static function render(Suite $suite) { $total = $error = $warning = $exception = $ok = $disabled = 0; $filter = $suite->getFilter(); ?> <!DOCTYPE html> <html lang="en-us" dir="ltr"> <head> <meta charset="UTF-8"> <title><?php echo $suite->getName(); ?> </title> <meta name="robots" content="noindex, nofollow, noarchive, noodp"/> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"> <style type="text/css"> .table>tbody>tr.disabled>td, .table>tbody>tr.disabled>td>a { background-color: #cfcfcf; border-color: rgba(255, 255, 255, .3); color: #555; } .table>thead>tr>th { border: 0; } .table>tbody>tr.warning>td, .table>tbody>tr.warning>td>a { background-color: #F89406; border-color: rgba(255, 255, 255, .3); color: #593503; } .table>tbody>tr.danger>td, .table>tbody>tr.danger>td>a, .table>tbody>tr.exception>td, .table>tbody>tr.exception>td>a { background-color: #BD362F; border-color: rgba(255, 255, 255, .3); color: #661c1a; } .table>tbody>tr.success>td, .table>tbody>tr.success>td>a { background: #5BB75B; border-color: rgba(255, 255, 255, .3); color: #204020; } .modal pre { overflow: auto; height: 150px; } .glyphicon-question-sign { float: right; font-size: 18px; color: #555; } table a, table a:hover { color: #333; } footer { padding-top: 1em; padding-bottom: 4em; } footer .label { margin-right: 5px; } </style> </head> <body> <div class="container"> <header class="row"> <h3>Envtesting<?php echo $suite->getName() ? ' : ' . $suite->getName() : null; ?> </h3> <?php if ($filter->isActive()) { ?> <div class="alert alert-info"> <a href="<?php echo Html::link(); ?> " class="close">×</a>Test results are filtered! </div> <?php } ?> </header> <div class="row"> <table class="table table-condensed "> <colgroup style="width:25px;"/> <colgroup style="width:80px;"/> <colgroup style="width:150px;"/> <colgroup style="width:150px;"/> <colgroup style="width:120px;"/> <colgroup style="width:100px;"/> <thead> <tr> <th></th> <th title="Warning | Error | Ok or disabled">Result</th> <th title="Unique test name"> Name<?php echo $filter->name ? ' = <span class="label label-default">' . $filter->name . '</span>' : ''; ?> </th> <th title="Test group"> Group<?php echo $filter->group ? ' = <span class="label label-default">' . $filter->group . '</span>' : ''; ?> </th> <th title="Test type"> Type<?php echo $filter->type ? ' = <span class="label label-default">' . $filter->type . '</span>' : ''; ?> </th> <th title="Notice eg. stable server">Notice</th> <th title="Response message">Message</th> </tr> </thead> <tbody> <?php $total = $ok = $disabled = $error = $warning = 0; ?> <?php foreach ($suite as $group => $tests) { ?> <?php foreach ($tests as $order => $test) { ?> <?php $total++; ?> <tr class="<?php echo Html::getStatusAsClass($test->getStatus()); ?> "> <td> <i class="icon-<?php echo $test->isOk() ? 'ok' : 'remove'; ?> "></i> </td> <td><?php echo $test->getStatus(); ?> </td> <td><a href="<?php echo Html::link('name=' . $test->getName()); ?> "><?php echo $test->getName(); ?> </a></td> <td><a href="<?php echo Html::link('group=' . $group); ?> "><?php echo $group; ?> </a></td> <td> <a href="<?php echo Html::link('type=' . $test->getType()); ?> "><?php echo $test->getType(); ?> </a> </td> <td><?php echo $test->getNotice(); ?> </td> <td> <?php echo $test->getStatusMessage(true); ?> <?php if ($test->hasOptions()) { ?> <br><code>Options: <?php echo json_encode((array) $test->getOptions()); ?> </code> <?php } ?> </td> </tr> <?php if ($test->isOk() && $test->isEnabled()) { $ok++; } ?> <?php if (!$test->isEnabled()) { $disabled++; } ?> <?php if ($test->isError()) { $error++; } ?> <?php if ($test->isWarning()) { $warning++; } ?> <?php } ?> <?php } ?> <?php $enabled = $total - $disabled; ?> </tbody> </table> <div class="btn-group"> <a href="<?php echo Html::link(null, true); ?> " class="btn btn-primary" title="Refresh current tests"><i class="icon-refresh icon-white"></i> Refresh</a> <a href="<?php echo Html::link('output=csv', true); ?> " class="btn btn-default" title="Download CSV output">CSV <i class="icon-arrow-down"></i></a> <?php if ($filter->isActive()) { ?> <a href="<?php echo Html::link(null); ?> " class="btn btn-danger" title="Cancel filter">Cancel filter</a> <?php } ?> </div> </div> <footer class="row"> <?php if ($disabled > 0) { ?> <span class="label label-default"> <?php echo $disabled; ?> DISABLED <?php echo $total ? round(100 * $disabled / $total) : 0; ?> % </span> <?php } ?> <?php if ($error > 0) { ?> <span class="label label-danger"> <?php echo $error; ?> ERROR <?php echo $enabled ? round(100 * $error / $enabled) : 0; ?> % </span> <?php } ?> <?php if ($warning > 0) { ?> <span class="label label-warning"> <?php echo $warning; ?> WARNING <?php echo $enabled ? round(100 * $warning / $enabled) : 0; ?> % </span> <?php } ?> <span class="label label-success"> <?php echo $ok; ?> OK <?php echo $total - $disabled ? round(100 * $ok / ($total - $disabled)) : 0; ?> % </span> <span class="label label-default"><?php echo $total; ?> TESTS</span> <a data-toggle="modal" href="#about" class="glyphicon glyphicon-question-sign"></a> </footer> <div class="modal" id="about" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h3>Envtesting</h3> </div> <div class="modal-body"> <p>Envtesting is fast simple and <strong>easy to use</strong> environment testing written in PHP. Can check library, services and services response. Produce console, HTML or CSV output. </p> <h4>Authors</h4> <p> <a href="http://www.wikidi.com">wikidi.com</a> + <a href="https://twitter.com/#!/OzzyCzech" title="Roman Ožana" target="_blank">@OzzyCzech</a> </p> <h4>Copyright & License</h4> <pre><?php ?> Copyright (c) 2012, Envtesting (Roman Ozana <*****@*****.**>) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Morphine nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. </pre> </div> <div class="modal-footer"> <a href="https://github.com/wikidi/envtesting" class="btn btn-primary" target="blank">Fork me on GitHub</a> <a href="#" class="btn btn-success" data-dismiss="modal">Thanks!</a> </div> </div> </div> </div> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> </body> <!-- Generated at <?php echo date('j.n.Y H:i:s'); ?> by Envtesting https://github.com/wikidi/envtesting --> </html> <?php }