updated Lime

This commit is contained in:
Fabien Potencier 2010-01-22 15:34:24 +01:00
parent a2a7e4f6b7
commit 75a45a28b3
10 changed files with 262 additions and 447 deletions

View File

@ -54,7 +54,7 @@ class LimeTestSuite extends LimeRegistration
throw new LogicException(sprintf('The output "%s" does not support multi-processing', $type));
}
$this->output = new LimeOutputInspectable($output);
$this->output = new LimeOutputProxy($output);
}
public function run()
@ -109,12 +109,6 @@ class LimeTestSuite extends LimeRegistration
$this->output->flush();
$planned = $this->output->getPlanned();
$passed = $this->output->getPassed();
$failed = $this->output->getFailed();
$errors = $this->output->getErrors();
$warnings = $this->output->getWarnings();
return 0 == ($failed + $errors + $warnings) && $planned == $passed;
return !$this->output->getResult()->isFailed();
}
}

View File

@ -30,7 +30,7 @@
* @package Lime
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: LimeLexer.php 23701 2009-11-08 21:23:40Z bschussek $
* @version SVN: $Id: LimeLexer.php 25934 2009-12-27 20:44:07Z bschussek $
*/
abstract class LimeLexer
{
@ -40,6 +40,7 @@ abstract class LimeLexer
$inClassDeclaration,
$currentFunction,
$inFunctionDeclaration,
$inAssignment,
$endOfCurrentExpr,
$currentLine;
@ -62,6 +63,7 @@ abstract class LimeLexer
$this->inClassDeclaration = false;
$this->currentFunction = array();
$this->inFunctionDeclaration = false;
$this->inAssignment = false;
$this->endOfCurrentExpr = true;
$this->currentLine = 1;
@ -90,6 +92,16 @@ abstract class LimeLexer
case '}':
$this->endOfCurrentExpr = true;
break;
case '=':
$this->endOfCurrentExpr = false;
$this->inAssignment = true;
break;
}
if ($this->endOfCurrentExpr)
{
$this->inAssignment = false;
}
$this->beforeProcess($token, null);
@ -235,6 +247,11 @@ abstract class LimeLexer
break;
}
if ($this->endOfCurrentExpr)
{
$this->inAssignment = false;
}
$this->beforeProcess($text, $id);
$this->process($text, $id);
$this->afterProcess($text, $id);
@ -345,6 +362,16 @@ abstract class LimeLexer
return $this->inFunctionDeclaration;
}
/**
* Returns how many functions are currently nested inside each other.
*
* @return integer
*/
protected function getFunctionNestingLevel()
{
return count($this->currentFunction);
}
/**
* Returns whether the current token marks the end of the last expression.
*
@ -355,6 +382,16 @@ abstract class LimeLexer
return $this->endOfCurrentExpr;
}
/**
* Returns whether the current token is inside an assignment operation.
*
* @return boolean
*/
protected function inAssignment()
{
return $this->inAssignment;
}
/**
* Tells the lexer to stop lexing.
*/

View File

@ -54,7 +54,7 @@
*
* @package Lime
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
* @version SVN: $Id: LimeLexerTransformAnnotations.php 23701 2009-11-08 21:23:40Z bschussek $
* @version SVN: $Id: LimeLexerTransformAnnotations.php 25934 2009-12-27 20:44:07Z bschussek $
* @see LimeLexerAnnotationAware
*/
class LimeLexerTransformAnnotations extends LimeLexerAnnotationAware
@ -181,6 +181,27 @@ class LimeLexerTransformAnnotations extends LimeLexerAnnotationAware
}
}
// Closures and anonymous functions should not be stripped from the output
if ($this->inFunction())
{
if ($this->inFunctionDeclaration())
{
$this->functionBuffer .= $text;
$text = '';
}
// if the name of the function is NULL, it is a closure/anonymous function
else if (!$this->getCurrentFunction() || $this->inClass())
{
$text = $this->functionBuffer.$text;
$this->functionBuffer = '';
}
else
{
$text = str_repeat("\n", count(explode("\n", $this->functionBuffer.$text)) - 1);
$this->functionBuffer = '';
}
}
if ($id == T_OPEN_TAG && !$this->initialized)
{
if (count($this->variables))
@ -189,11 +210,7 @@ class LimeLexerTransformAnnotations extends LimeLexerAnnotationAware
}
$this->initialized = true;
}
else if ($this->inClass() && $this->classNotLoaded)
{
// just print
}
else if ($this->inClass() || $this->inFunction())
else if ($this->inClass() && !$this->classNotLoaded)
{
$text = str_repeat("\n", count(explode("\n", $text)) - 1);
}

View File

@ -162,20 +162,151 @@ class lime_test extends LimeTest
}
}
class lime_output extends LimeOutput
class lime_output
{
public function green_bar($message)
const
ERROR = 'ERROR',
INFO = 'INFO',
PARAMETER = 'PARAMETER',
COMMENT = 'COMMENT',
GREEN_BAR = 'GREEN_BAR',
RED_BAR = 'RED_BAR',
INFO_BAR = 'INFO_BAR';
protected static
$styles = array(self::ERROR, self::INFO, self::PARAMETER, self::COMMENT, self::GREEN_BAR, self::RED_BAR, self::INFO_BAR);
protected
$colorizer = null;
/**
* Constructor.
*
* @param boolean $forceColors If set to TRUE, colorization will be enforced
* whether or not the current console supports it
*/
public function __construct($forceColors = false)
{
return $this->greenBar($message);
if (LimeColorizer::isSupported() || $forceColors)
{
$colorizer = new LimeColorizer();
$colorizer->setStyle(self::ERROR, array('bg' => 'red', 'fg' => 'white', 'bold' => true));
$colorizer->setStyle(self::INFO, array('fg' => 'green', 'bold' => true));
$colorizer->setStyle(self::PARAMETER, array('fg' => 'cyan'));
$colorizer->setStyle(self::COMMENT, array('fg' => 'yellow'));
$colorizer->setStyle(self::GREEN_BAR, array('fg' => 'white', 'bg' => 'green', 'bold' => true));
$colorizer->setStyle(self::RED_BAR, array('fg' => 'white', 'bg' => 'red', 'bold' => true));
$colorizer->setStyle(self::INFO_BAR, array('fg' => 'cyan', 'bold' => true));
$this->colorizer = $colorizer;
}
}
public function red_bar($message)
/**
* Colorizes the given text with the given style.
*
* @param string $text Some text
* @param string $style One of the predefined style constants
* @return string The formatted text
*/
protected function colorize($text, $style)
{
return $this->redBar($message);
if (!in_array($style, self::$styles))
{
throw new InvalidArgumentException(sprintf('The style "%s" does not exist', $style));
}
return is_null($this->colorizer) ? $text : $this->colorizer->colorize($text, $style);
}
/**
* ?
*/
public function diag()
{
$messages = func_get_args();
foreach ($messages as $message)
{
echo $this->colorize('# '.join("\n# ", (array) $message), self::COMMENT)."\n";
}
}
/**
* Prints a comment.
*
* @param string $message
*/
public function comment($message)
{
echo $this->colorize(sprintf('# %s', $message), self::COMMENT)."\n";
}
/**
* Prints an informational message.
*
* @param string $message
*/
public function info($message)
{
echo $this->colorize(sprintf('> %s', $message), self::INFO_BAR)."\n";
}
/**
* Prints an error.
*
* @param string $message
*/
public function error($message)
{
echo $this->colorize(sprintf(' %s ', $message), self::RED_BAR)."\n";
}
/**
* Prints and automatically colorizes a line.
*
* You can wrap the whole line into a specific predefined style by passing
* the style constant in the second parameter.
*
* @param string $message The message to colorize
* @param string $style The desired style constant
* @param boolean $colorize Whether to automatically colorize parts of the
* line
*/
public function echoln($message, $style = null, $colorize = true)
{
if ($colorize)
{
$message = preg_replace('/(?:^|\.)((?:not ok|dubious) *\d*)\b/e', '$this->colorize(\'$1\', self::ERROR)', $message);
$message = preg_replace('/(?:^|\.)(ok *\d*)\b/e', '$this->colorize(\'$1\', self::INFO)', $message);
$message = preg_replace('/"(.+?)"/e', '$this->colorize(\'$1\', self::PARAMETER)', $message);
$message = preg_replace('/(\->|\:\:)?([a-zA-Z0-9_]+?)\(\)/e', '$this->colorize(\'$1$2()\', self::PARAMETER)', $message);
}
echo ($style ? $this->colorize($message, $style) : $message)."\n";
}
/**
* Prints a message in a green box.
*
* @param string $message
*/
public function greenBar($message)
{
echo $this->colorize($message.str_repeat(' ', 71 - min(71, strlen($message))), self::GREEN_BAR)."\n";
}
/**
* Prints a message a in a red box.
*
* @param string $message
*/
public function redBar($message)
{
echo $this->colorize($message.str_repeat(' ', 71 - min(71, strlen($message))), self::RED_BAR)."\n";
}
}
class lime_output_color extends LimeOutput
class lime_output_color extends lime_output
{
}

View File

@ -1,169 +0,0 @@
<?php
/*
* This file is part of the Lime framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Prints text on the console in different formats.
*
* You can use the various methods in this class to print nicely formatted
* text message in the console. If the console does not support text formatting,
* text formatting is suppressed, unless you pass the argument $forceColors=TRUE
* in the constructor.
*
* @package symfony
* @subpackage lime
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
* @version SVN: $Id$
*/
class LimeOutput
{
const
ERROR = 'ERROR',
INFO = 'INFO',
PARAMETER = 'PARAMETER',
COMMENT = 'COMMENT',
GREEN_BAR = 'GREEN_BAR',
RED_BAR = 'RED_BAR',
INFO_BAR = 'INFO_BAR';
protected static
$styles = array(self::ERROR, self::INFO, self::PARAMETER, self::COMMENT, self::GREEN_BAR, self::RED_BAR, self::INFO_BAR);
protected
$colorizer = null;
/**
* Constructor.
*
* @param boolean $forceColors If set to TRUE, colorization will be enforced
* whether or not the current console supports it
*/
public function __construct($forceColors = false)
{
if (LimeColorizer::isSupported() || $forceColors)
{
$colorizer = new LimeColorizer();
$colorizer->setStyle(self::ERROR, array('bg' => 'red', 'fg' => 'white', 'bold' => true));
$colorizer->setStyle(self::INFO, array('fg' => 'green', 'bold' => true));
$colorizer->setStyle(self::PARAMETER, array('fg' => 'cyan'));
$colorizer->setStyle(self::COMMENT, array('fg' => 'yellow'));
$colorizer->setStyle(self::GREEN_BAR, array('fg' => 'white', 'bg' => 'green', 'bold' => true));
$colorizer->setStyle(self::RED_BAR, array('fg' => 'white', 'bg' => 'red', 'bold' => true));
$colorizer->setStyle(self::INFO_BAR, array('fg' => 'cyan', 'bold' => true));
$this->colorizer = $colorizer;
}
}
/**
* Colorizes the given text with the given style.
*
* @param string $text Some text
* @param string $style One of the predefined style constants
* @return string The formatted text
*/
protected function colorize($text, $style)
{
if (!in_array($style, self::$styles))
{
throw new InvalidArgumentException(sprintf('The style "%s" does not exist', $style));
}
return is_null($this->colorizer) ? $text : $this->colorizer->colorize($text, $style);
}
/**
* ?
*/
public function diag()
{
$messages = func_get_args();
foreach ($messages as $message)
{
echo $this->colorize('# '.join("\n# ", (array) $message), self::COMMENT)."\n";
}
}
/**
* Prints a comment.
*
* @param string $message
*/
public function comment($message)
{
echo $this->colorize(sprintf('# %s', $message), self::COMMENT)."\n";
}
/**
* Prints an informational message.
*
* @param string $message
*/
public function info($message)
{
echo $this->colorize(sprintf('> %s', $message), self::INFO_BAR)."\n";
}
/**
* Prints an error.
*
* @param string $message
*/
public function error($message)
{
echo $this->colorize(sprintf(' %s ', $message), self::RED_BAR)."\n";
}
/**
* Prints and automatically colorizes a line.
*
* You can wrap the whole line into a specific predefined style by passing
* the style constant in the second parameter.
*
* @param string $message The message to colorize
* @param string $style The desired style constant
* @param boolean $colorize Whether to automatically colorize parts of the
* line
*/
public function echoln($message, $style = null, $colorize = true)
{
if ($colorize)
{
$message = preg_replace('/(?:^|\.)((?:not ok|dubious) *\d*)\b/e', '$this->colorize(\'$1\', self::ERROR)', $message);
$message = preg_replace('/(?:^|\.)(ok *\d*)\b/e', '$this->colorize(\'$1\', self::INFO)', $message);
$message = preg_replace('/"(.+?)"/e', '$this->colorize(\'$1\', self::PARAMETER)', $message);
$message = preg_replace('/(\->|\:\:)?([a-zA-Z0-9_]+?)\(\)/e', '$this->colorize(\'$1$2()\', self::PARAMETER)', $message);
}
echo ($style ? $this->colorize($message, $style) : $message)."\n";
}
/**
* Prints a message in a green box.
*
* @param string $message
*/
public function greenBar($message)
{
echo $this->colorize($message.str_repeat(' ', 71 - min(71, strlen($message))), self::GREEN_BAR)."\n";
}
/**
* Prints a message a in a red box.
*
* @param string $message
*/
public function redBar($message)
{
echo $this->colorize($message.str_repeat(' ', 71 - min(71, strlen($message))), self::RED_BAR)."\n";
}
}

View File

@ -18,7 +18,7 @@
*
* @package Lime
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
* @version SVN: $Id: LimeOutputConsoleSummary.php 23701 2009-11-08 21:23:40Z bschussek $
* @version SVN: $Id: LimeOutputConsoleSummary.php 25932 2009-12-27 19:55:32Z bschussek $
*/
class LimeOutputConsoleSummary implements LimeOutputInterface
{
@ -27,18 +27,12 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
$options = array(),
$startTime = 0,
$file = null,
$results = array(),
$actualFiles = 0,
$failedFiles = 0,
$actualTests = 0,
$failedTests = 0,
$expected = array(),
$actual = array(),
$passed = array(),
$failed = array(),
$errors = array(),
$warnings = array(),
$todos = array(),
$line = array();
$expectedTests = 0,
$failedTests = 0;
/**
* Constructor.
@ -64,28 +58,24 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
public function focus($file)
{
$this->file = $file;
if (!array_key_exists($file, $this->line))
if (!array_key_exists($file, $this->results))
{
$this->line[$file] = count($this->line);
$this->expected[$file] = 0;
$this->actual[$file] = 0;
$this->passed[$file] = 0;
$this->failed[$file] = array();
$this->errors[$file] = array();
$this->warnings[$file] = array();
$this->todos[$file] = array();
$this->results[$file] = new LimeOutputResult();
}
$this->file = $file;
}
public function close()
{
if (!is_null($this->file))
{
$result = $this->results[$this->file];
$this->actualFiles++;
$this->actualTests += $this->getActual();
$this->failedTests += $this->getFailed();
$this->actualTests += $result->getNbActual();
$this->expectedTests += $result->getNbExpected();
$this->failedTests += $result->getNbFailures();
$path = $this->truncate($this->file);
@ -96,14 +86,12 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
$this->printer->printText(str_pad($path, 73, '.'));
$incomplete = ($this->getExpected() > 0 && $this->getActual() != $this->getExpected());
if ($this->getErrors() || $this->getFailed() || $incomplete)
if ($result->hasErrors() || $result->hasFailures() || $result->isIncomplete())
{
$this->failedFiles++;
$this->printer->printLine("not ok", LimePrinter::NOT_OK);
}
else if ($this->getWarnings())
else if ($result->hasWarnings())
{
$this->printer->printLine("warning", LimePrinter::WARNING);
}
@ -112,29 +100,29 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
$this->printer->printLine("ok", LimePrinter::OK);
}
if ($this->getExpected() > 0 && $this->getActual() != $this->getExpected())
if ($result->isIncomplete())
{
$this->printer->printLine(' Plan Mismatch:', LimePrinter::COMMENT);
if ($this->getActual() > $this->getExpected())
if ($result->getNbActual() > $result->getNbExpected())
{
$this->printer->printLine(sprintf(' Looks like you only planned %s tests but ran %s.', $this->getExpected(), $this->getActual()));
$this->printer->printLine(sprintf(' Looks like you only planned %s tests but ran %s.', $result->getNbExpected(), $result->getNbActual()));
}
else
{
$this->printer->printLine(sprintf(' Looks like you planned %s tests but only ran %s.', $this->getExpected(), $this->getActual()));
$this->printer->printLine(sprintf(' Looks like you planned %s tests but only ran %s.', $result->getNbExpected(), $result->getNbActual()));
}
}
if ($this->getFailed())
if ($result->hasFailures())
{
$this->printer->printLine(' Failed Tests:', LimePrinter::COMMENT);
$i = 0;
foreach ($this->failed[$this->file] as $number => $failed)
foreach ($result->getFailures() as $number => $failed)
{
if (!$this->options['verbose'] && $i > 2)
{
$this->printer->printLine(sprintf(' ... and %s more', $this->getFailed()-$i));
$this->printer->printLine(sprintf(' ... and %s more', $result->getNbFailures()-$i));
break;
}
@ -144,15 +132,15 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
}
}
if ($this->getWarnings())
if ($result->hasWarnings())
{
$this->printer->printLine(' Warnings:', LimePrinter::COMMENT);
foreach ($this->warnings[$this->file] as $i => $warning)
foreach ($result->getWarnings() as $i => $warning)
{
if (!$this->options['verbose'] && $i > 2)
{
$this->printer->printLine(sprintf(' ... and %s more', $this->getWarnings()-$i));
$this->printer->printLine(sprintf(' ... and %s more', $result->getNbWarnings()-$i));
break;
}
@ -169,15 +157,15 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
}
}
if ($this->getErrors())
if ($result->hasErrors())
{
$this->printer->printLine(' Errors:', LimePrinter::COMMENT);
foreach ($this->errors[$this->file] as $i => $error)
foreach ($result->getErrors() as $i => $error)
{
if (!$this->options['verbose'] && $i > 2)
{
$this->printer->printLine(sprintf(' ... and %s more', $this->getErrors()-$i));
$this->printer->printLine(sprintf(' ... and %s more', $result->getNbErrors()-$i));
break;
}
@ -194,15 +182,15 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
}
}
if ($this->getTodos())
if ($result->hasTodos())
{
$this->printer->printLine(' TODOs:', LimePrinter::COMMENT);
foreach ($this->todos[$this->file] as $i => $todo)
foreach ($result->getTodos() as $i => $todo)
{
if (!$this->options['verbose'] && $i > 2)
{
$this->printer->printLine(sprintf(' ... and %s more', $this->getTodos()-$i));
$this->printer->printLine(sprintf(' ... and %s more', $result->getNbTodos()-$i));
break;
}
@ -212,77 +200,39 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
}
}
protected function getExpected()
{
return $this->expected[$this->file];
}
protected function getActual()
{
return $this->actual[$this->file];
}
protected function getPassed()
{
return $this->passed[$this->file];
}
protected function getFailed()
{
return count($this->failed[$this->file]);
}
protected function getErrors()
{
return count($this->errors[$this->file]);
}
protected function getWarnings()
{
return count($this->warnings[$this->file]);
}
protected function getTodos()
{
return count($this->todos[$this->file]);
}
public function plan($amount)
{
$this->expected[$this->file] = $amount;
$this->results[$this->file]->addPlan($amount);
}
public function pass($message, $file, $line)
{
$this->passed[$this->file]++;
$this->actual[$this->file]++;
$this->results[$this->file]->addPassed();
}
public function fail($message, $file, $line, $error = null)
{
$this->actual[$this->file]++;
$this->failed[$this->file][$this->actual[$this->file]] = array($message, $file, $line, $error);
$this->results[$this->file]->addFailure(array($message, $file, $line, $error));
}
public function skip($message, $file, $line)
{
$this->actual[$this->file]++;
$this->results[$this->file]->addSkipped();
}
public function todo($message, $file, $line)
{
$this->actual[$this->file]++;
$this->todos[$this->file][] = $message;
$this->results[$this->file]->addTodo($message);
}
public function warning($message, $file, $line)
{
$this->warnings[$this->file][] = array($message, $file, $line);
$this->results[$this->file]->addWarning(array($message, $file, $line));
}
public function error(LimeError $error)
{
$this->errors[$this->file][] = $error;
$this->results[$this->file]->addError($error);
}
public function comment($message) {}
@ -293,7 +243,7 @@ class LimeOutputConsoleSummary implements LimeOutputInterface
{
$stats = sprintf(' Failed %d/%d test scripts, %.2f%% okay. %d/%d subtests failed, %.2f%% okay.',
$this->failedFiles, $this->actualFiles, 100 - 100*$this->failedFiles/max(1,$this->actualFiles),
$this->failedTests, $this->actualTests, 100 - 100*$this->failedTests/max(1,$this->actualTests));
$this->failedTests, $this->expectedTests, 100 - 100*$this->failedTests/max(1,$this->expectedTests));
$this->printer->printBox($stats, LimePrinter::NOT_OK);
}

View File

@ -1,140 +0,0 @@
<?php
/*
* This file is part of the Lime framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
* (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
class LimeOutputInspectable implements LimeOutputInterface
{
private
$output = null,
$planned = 0,
$passed = 0,
$failed = 0,
$skipped = 0,
$todos = 0,
$errors = 0,
$warnings = 0,
$failedFiles = array();
public function __construct(LimeOutputInterface $output = null)
{
$this->output = is_null($output) ? new LimeOutputNone() : $output;
}
public function supportsThreading()
{
return $this->output->supportsThreading();
}
public function getPlanned()
{
return $this->planned;
}
public function getPassed()
{
return $this->passed;
}
public function getFailed()
{
return $this->failed;
}
public function getSkipped()
{
return $this->skipped;
}
public function getTodos()
{
return $this->todos;
}
public function getErrors()
{
return $this->errors;
}
public function getWarnings()
{
return $this->warnings;
}
public function getFailedFiles()
{
return $this->failedFiles;
}
public function focus($file)
{
$this->output->focus($file);
}
public function close()
{
$this->output->close();
}
public function plan($amount)
{
$this->planned += $amount;
$this->output->plan($amount);
}
public function pass($message, $file, $line)
{
$this->passed++;
$this->output->pass($message, $file, $line);
}
public function fail($message, $file, $line, $error = null)
{
$this->failed++;
$this->failedFiles[] = $file;
$this->output->fail($message, $file, $line, $error);
}
public function skip($message, $file, $line)
{
$this->skipped++;
$this->output->skip($message, $file, $line);
}
public function todo($message, $file, $line)
{
$this->todos++;
$this->output->todo($message, $file, $line);
}
public function warning($message, $file, $line)
{
$this->warnings++;
$this->failedFiles[] = $file;
$this->output->warning($message, $file, $line);
}
public function error(LimeError $error)
{
$this->errors++;
$this->failedFiles[] = $error->getFile();
$this->output->error($error);
}
public function comment($message)
{
$this->output->comment($message);
}
public function flush()
{
$this->output->flush();
}
}

View File

@ -14,6 +14,7 @@ class LimeOutputTap implements LimeOutputInterface
{
protected
$options = array(),
$result = null,
$expected = null,
$passed = 0,
$actual = 0,
@ -25,6 +26,7 @@ class LimeOutputTap implements LimeOutputInterface
public function __construct(LimePrinter $printer, array $options = array())
{
$this->printer = $printer;
$this->result = new LimeOutputResult();
$this->options = array_merge(array(
'verbose' => false,
'base_dir' => null,
@ -57,36 +59,35 @@ class LimeOutputTap implements LimeOutputInterface
public function plan($amount)
{
$this->expected += $amount;
$this->result->addPlan($amount);
}
public function pass($message, $file, $line)
{
$this->actual++;
$this->passed++;
$this->result->addPassed();
if (empty($message))
{
$this->printer->printLine('ok '.$this->actual, LimePrinter::OK);
$this->printer->printLine('ok '.$this->result->getNbActual(), LimePrinter::OK);
}
else
{
$this->printer->printText('ok '.$this->actual, LimePrinter::OK);
$this->printer->printText('ok '.$this->result->getNbActual(), LimePrinter::OK);
$this->printer->printLine(' - '.$message);
}
}
public function fail($message, $file, $line, $error = null)
{
$this->actual++;
$this->result->addFailure(array($message, $file, $line, $error));
if (empty($message))
{
$this->printer->printLine('not ok '.$this->actual, LimePrinter::NOT_OK);
$this->printer->printLine('not ok '.$this->result->getNbActual(), LimePrinter::NOT_OK);
}
else
{
$this->printer->printText('not ok '.$this->actual, LimePrinter::NOT_OK);
$this->printer->printText('not ok '.$this->result->getNbActual(), LimePrinter::NOT_OK);
$this->printer->printLine(' - '.$message);
}
@ -103,17 +104,16 @@ class LimeOutputTap implements LimeOutputInterface
public function skip($message, $file, $line)
{
$this->actual++;
$this->passed++;
$this->result->addSkipped();
if (empty($message))
{
$this->printer->printText('ok '.$this->actual, LimePrinter::SKIP);
$this->printer->printText('ok '.$this->result->getNbActual(), LimePrinter::SKIP);
$this->printer->printText(' ');
}
else
{
$this->printer->printText('ok '.$this->actual, LimePrinter::SKIP);
$this->printer->printText('ok '.$this->result->getNbActual(), LimePrinter::SKIP);
$this->printer->printText(' - '.$message.' ');
}
@ -122,17 +122,16 @@ class LimeOutputTap implements LimeOutputInterface
public function todo($message, $file, $line)
{
$this->actual++;
$this->passed++;
$this->result->addTodo($message);
if (empty($message))
{
$this->printer->printText('not ok '.$this->actual, LimePrinter::TODO);
$this->printer->printText('not ok '.$this->result->getNbActual(), LimePrinter::TODO);
$this->printer->printText(' ');
}
else
{
$this->printer->printText('not ok '.$this->actual, LimePrinter::TODO);
$this->printer->printText('not ok '.$this->result->getNbActual(), LimePrinter::TODO);
$this->printer->printText(' - '.$message.' ');
}
@ -141,7 +140,7 @@ class LimeOutputTap implements LimeOutputInterface
public function warning($message, $file, $line)
{
$this->warnings++;
$this->result->addWarning(array($message, $file, $line));
$message .= sprintf("\n(in %s on line %s)", $this->stripBaseDir($file), $line);
@ -150,7 +149,7 @@ class LimeOutputTap implements LimeOutputInterface
public function error(LimeError $error)
{
$this->errors++;
$this->result->addError($error);
$message = sprintf("%s: %s\n(in %s on line %s)", $error->getType(),
$error->getMessage(), $this->stripBaseDir($error->getFile()), $error->getLine());
@ -261,14 +260,10 @@ class LimeOutputTap implements LimeOutputInterface
public function flush()
{
if (is_null($this->expected))
{
$this->plan($this->actual);
}
$result = $this->result;
$this->printer->printLine('1..'.$result->getNbExpected());
$this->printer->printLine('1..'.$this->expected);
$messages = self::getMessages($this->actual, $this->expected, $this->passed, $this->errors, $this->warnings);
$messages = self::getMessages($result->getNbActual(), $result->getNbExpected(), $result->getNbPassed(), $result->getNbErrors(), $result->getNbWarnings());
foreach ($messages as $message)
{

View File

@ -13,7 +13,7 @@
class LimeOutputXml implements LimeOutputInterface
{
protected
$ouptut = null;
$output = null;
public function __construct()
{

View File

@ -215,12 +215,12 @@ class LimeTesterArray extends LimeTester implements ArrayAccess, Iterator
foreach ($this->value as $k => $v)
{
if ((is_null($key) || $key != $k) && !$truncated)
if ((is_null($key) || $key !== $k) && !$truncated)
{
$result .= " ...\n";
$truncated = true;
}
else if ($k == $key)
else if ($k === $key)
{
$value = is_null($value) ? $v : $value;
$result .= sprintf(" %s => %s,\n", var_export($k, true), $this->indent($value));