protected function render()
 {
     $printer = new LimePrinter(new LimeColorizer());
     foreach ($this->files as $file) {
         $totalLines = count($this->coveredCode[$file]) + count($this->uncoveredCode[$file]);
         $percent = count($this->coveredCode[$file]) * 100 / max($totalLines, 1);
         $relativeFile = $this->getRelativeFile($file);
         if ($percent == 100) {
             $style = LimePrinter::OK;
         } else {
             if ($percent >= 90) {
                 $style = LimePrinter::INFO;
             } else {
                 if ($percent <= 20) {
                     $style = LimePrinter::NOT_OK;
                 } else {
                     $style = null;
                 }
             }
         }
         $printer->printLine(sprintf("%-76s%3.0f%%", $relativeFile, $percent), $style);
         if ($this->options['verbose'] && $percent > 0 && $percent < 100) {
             $printer->printLine(sprintf("missing: %s", $this->formatRange($this->uncoveredCode[$file])), LimePrinter::COMMENT);
         }
     }
     $totalLines = $this->coveredLines + $this->uncoveredLines;
     $percent = $this->coveredLines * 100 / max($totalLines, 1);
     if ($percent <= 20) {
         $style = LimePrinter::NOT_OK;
     } else {
         $style = LimePrinter::HAPPY;
     }
     $printer->printLine(str_pad(sprintf(" Total Coverage: %3.0f%%", $percent), 80), $style);
 }
Exemplo n.º 2
0
// @Test: printLargeBox() prints text in a large box with a width of 80 characters or more
// fixtures
$paddedText = str_pad('  My text', 80, ' ');
$paddedSpace = str_repeat(' ', 80);
$colorizer->colorize($paddedText, 'RED')->returns('<RED>' . $paddedText . '</RED>');
$colorizer->colorize($paddedSpace, 'RED')->returns('<RED>' . $paddedSpace . '</RED>');
$colorizer->replay();
// test
ob_start();
$printer->printLargeBox('My text', 'RED');
$result = ob_get_clean();
// assertions
$t->is($result, "\n<RED>" . $paddedSpace . "</RED>\n<RED>" . $paddedText . "</RED>\n<RED>" . $paddedSpace . "</RED>\n\n", 'The result was colorized and printed');
// @Test: The printer does also work without colorizer
// fixtures
$printer = new LimePrinter();
// test
ob_start();
$printer->printText('My text');
$result = ob_get_clean();
// assertions
$t->is($result, 'My text', 'The result was printed');
// @Test: Strings in unformatted text are automatically formatted
// fixtures
$colorizer->colorize('"Test string"', LimePrinter::STRING)->returns('<BLUE>"Test string"</BLUE>');
$colorizer->replay();
// test
ob_start();
$printer->printText('My text with a "Test string"');
$result = ob_get_clean();
// assertions
Exemplo n.º 3
0
Arquivo: loc.php Projeto: b00giZm/lime
<?php

/*
 * This file is part of the Lime framework.
 *
 * (c) Fabien Potencier <*****@*****.**>
 * (c) Bernhard Schussek <*****@*****.**>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */
require_once dirname(__FILE__) . '/../../lib/LimeAutoloader.php';
LimeAutoloader::register();
$baseDir = realpath(dirname(__FILE__) . '/..');
$printer = new LimePrinter(new LimeColorizer());
$printer->printLine('Source Lines Of Code', LimePrinter::HAPPY);
$fileLines = 0;
$testLines = 0;
$lexer = new LimeLexerCodeLines();
$suite = new LimeHarness();
$suite->registerGlob($baseDir . '/../lib/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*/*/*.php');
$suite->registerGlob($baseDir . '/../lib/*/*/*/*/*.php');
foreach ($suite->getFiles() as $file) {
    $fileLines += count($lexer->parse($file));
}
$printer->printLine(sprintf('Classes:       %d', $fileLines));
$suite = new LimeHarness();
$suite->registerGlob($baseDir . '/unit/*.php');