cvs: pear /PHPUnit2/Framework AssertionFailedError.php /PHPUnit2/Util Filter.php /PHPUnit2/Util/Log Eclipse.php
| From: | Sebastian Bergmann | Date: | Fri, 17 Mar 2006 07:20:19 +0000 |
| Subject: | cvs: pear /PHPUnit2/Framework AssertionFailedError.php /PHPUnit2/Util Filter.php /PHPUnit2/Util/Log Eclipse.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-39138@lists.php.net to get a copy of this message | ||
sebastian Fri Mar 17 07:20:19 2006 UTC
Modified files:
/pear/PHPUnit2/Framework AssertionFailedError.php
/pear/PHPUnit2/Util Filter.php
/pear/PHPUnit2/Util/Log Eclipse.php
Log:
Refactoring.
http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/Framework/AssertionFailedError.php?r1=1.16&r2=1.17&diff_format=u
Index: pear/PHPUnit2/Framework/AssertionFailedError.php
diff -u pear/PHPUnit2/Framework/AssertionFailedError.php:1.16
pear/PHPUnit2/Framework/AssertionFailedError.php:1.17
--- pear/PHPUnit2/Framework/AssertionFailedError.php:1.16 Sun Mar 5 07:37:16 2006
+++ pear/PHPUnit2/Framework/AssertionFailedError.php Fri Mar 17 07:20:19 2006
@@ -41,7 +41,7 @@
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php
BSD License
- * @version CVS: $Id: AssertionFailedError.php,v 1.16 2006/03/05 07:37:16 sebastian Exp $
+ * @version CVS: $Id: AssertionFailedError.php,v 1.17 2006/03/17 07:20:19 sebastian Exp $
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 2.0.0
*/
@@ -72,6 +72,18 @@
class PHPUnit2_Framework_AssertionFailedError extends Exception implements
PHPUnit2_Framework_SelfDescribing
{
/**
+ * Returns the location where this failure occured.
+ *
+ * @return array
+ * @access public
+ * @since Method available since Release 3.0.0
+ */
+ public function getLocation()
+ {
+ return PHPUnit2_Util_Filter::getFailureLocation($this);
+ }
+
+ /**
* Wrapper for getMessage() which is declared as final.
*
* @return string
http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/Util/Filter.php?r1=1.56&r2=1.57&diff_format=u
Index: pear/PHPUnit2/Util/Filter.php
diff -u pear/PHPUnit2/Util/Filter.php:1.56 pear/PHPUnit2/Util/Filter.php:1.57
--- pear/PHPUnit2/Util/Filter.php:1.56 Sun Mar 5 07:37:19 2006
+++ pear/PHPUnit2/Util/Filter.php Fri Mar 17 07:20:19 2006
@@ -41,7 +41,7 @@
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php
BSD License
- * @version CVS: $Id: Filter.php,v 1.56 2006/03/05 07:37:19 sebastian Exp $
+ * @version CVS: $Id: Filter.php,v 1.57 2006/03/17 07:20:19 sebastian Exp $
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 2.0.0
*/
@@ -147,9 +147,7 @@
*/
public static function getFilteredCodeCoverage(Array $codeCoverageInformation)
{
- $files = array_keys($codeCoverageInformation);
-
- foreach ($files as $file) {
+ foreach (array_keys($codeCoverageInformation) as $file) {
if (self::$filter && self::isFiltered($file)) {
unset($codeCoverageInformation[$file]);
}
@@ -169,9 +167,8 @@
public static function getFilteredStacktrace(Exception $e)
{
$filteredStacktrace = '';
- $stacktrace = $e->getTrace();
- foreach ($stacktrace as $frame) {
+ foreach ($e->getTrace() as $frame) {
if (!self::$filter || (isset($frame['file']) &&
!self::isFiltered($frame['file']))) {
$filteredStacktrace .= sprintf(
"%s:%s\n",
@@ -186,6 +183,31 @@
}
/**
+ * Returns the location where a failure occured.
+ *
+ * @param PHPUnit2_Framework_AssertionFailedError $e
+ * @return array
+ * @access public
+ * @static
+ * @since Method available since Release 3.0.0
+ */
+ public static function getFailureLocation(PHPUnit2_Framework_AssertionFailedError $e)
+ {
+ foreach ($e->getTrace() as $frame) {
+ if (!isset($frame['line'])) {
+ break;
+ }
+
+ $result = array(
+ 'file' => $frame['file'],
+ 'line' => $frame['line']
+ );
+ }
+
+ return $result;
+ }
+
+ /**
* Activates or deactivates filtering.
*
* @param boolean $filter
http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/Util/Log/Eclipse.php?r1=1.2&r2=1.3&diff_format=u
Index: pear/PHPUnit2/Util/Log/Eclipse.php
diff -u pear/PHPUnit2/Util/Log/Eclipse.php:1.2 pear/PHPUnit2/Util/Log/Eclipse.php:1.3
--- pear/PHPUnit2/Util/Log/Eclipse.php:1.2 Thu Mar 16 08:17:47 2006
+++ pear/PHPUnit2/Util/Log/Eclipse.php Fri Mar 17 07:20:19 2006
@@ -41,7 +41,7 @@
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php
BSD License
- * @version CVS: $Id: Eclipse.php,v 1.2 2006/03/16 08:17:47 sebastian Exp $
+ * @version CVS: $Id: Eclipse.php,v 1.3 2006/03/17 07:20:19 sebastian Exp $
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 3.0.0
*/
@@ -171,33 +171,6 @@
}
/**
- * @param Exception $e
- * @return string
- * @access private
- */
- private function getFileLine(Exception $e)
- {
- $file = '';
- $line = '';
-
- foreach ($e->getTrace() as $frame) {
- if (!isset($frame['line'])) {
- break;
- }
-
- $file = $frame['file'];
- $line = $frame['line'];
- }
-
- return sprintf(
- ' [%s line %s]',
-
- $file,
- $line
- );
- }
-
- /**
* An error occurred.
*
* @param PHPUnit2_Framework_Test $test
@@ -220,7 +193,18 @@
*/
public function addFailure(PHPUnit2_Framework_Test $test,
PHPUnit2_Framework_AssertionFailedError $e)
{
- $this->writeCase('fail', $e->getMessage() . $this->getFileLine($e));
+ $location = $e->getLocation();
+
+ $this->writeCase(
+ 'fail',
+ sprintf(
+ '%s[%s line %s]',
+
+ $e->getMessage(),
+ $location['file'],
+ $location['line']
+ )
+ );
$this->currentTestCasePass = FALSE;
}