Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Merge [3916].

  • Loading branch information...
commit 0287ed661d2c6229fb8a557d818a8473da0ee620 1 parent 644313c
@sebastianbergmann authored
View
35 PHPUnit/Framework/Assert.php
@@ -69,6 +69,11 @@
abstract class PHPUnit_Framework_Assert
{
/**
+ * @var integer
+ */
+ protected static $count = 0;
+
+ /**
* Asserts that an array has a specified key.
*
* @param mixed $key
@@ -1473,15 +1478,7 @@ public static function assertNotTag($matcher, $actual, $message = '', $isHtml =
*/
public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
{
- $stack = debug_backtrace();
-
- foreach (debug_backtrace() as $step) {
- if (isset($step['object']) &&
- $step['object'] instanceof PHPUnit_Framework_TestCase) {
- $step['object']->incrementAssertionCounter();
- break;
- }
- }
+ self::$count++;
if (!$constraint->evaluate($value)) {
$constraint->fail($value, $message);
@@ -2022,6 +2019,26 @@ public static function markTestSkipped($message = '')
throw new PHPUnit_Framework_SkippedTestError($message);
}
+ /**
+ * Return the current assertion count.
+ *
+ * @return integer
+ * @since Method available since Release 3.3.3
+ */
+ public static function getCount()
+ {
+ return self::$count;
+ }
+
+ /**
+ * Reset the assertion counter.
+ *
+ * @since Method available since Release 3.3.3
+ */
+ public static function resetCount()
+ {
+ self::$count = 0;
+ }
}
}
View
23 PHPUnit/Framework/TestCase.php
@@ -368,8 +368,6 @@ public function hasFailed()
*/
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
- $this->numAssertions = 0;
-
if ($result === NULL) {
$result = $this->createResult();
}
@@ -509,7 +507,7 @@ protected function runTest()
);
}
- $this->incrementAssertionCounter();
+ $this->numAssertions++;
return;
} else {
@@ -518,7 +516,7 @@ protected function runTest()
}
if ($this->expectedException !== NULL) {
- $this->incrementAssertionCounter();
+ $this->numAssertions++;
$this->fail('Expected exception ' . $this->expectedException);
}
}
@@ -670,24 +668,25 @@ protected function getMock($className, $methods = array(), array $arguments = ar
}
/**
- * Returns the number of assertions performed by this test.
+ * Adds a value to the assertion counter.
*
- * @return integer
- * @since Method available since Release 3.3.0
+ * @param integer $count
+ * @since Method available since Release 3.3.3
*/
- public function getNumAssertions()
+ public function addToAssertionCount($count)
{
- return $this->numAssertions;
+ $this->numAssertions += $count;
}
/**
- * Increments the number of assertions performed by this test.
+ * Returns the number of assertions performed by this test.
*
+ * @return integer
* @since Method available since Release 3.3.0
*/
- public function incrementAssertionCounter()
+ public function getNumAssertions()
{
- $this->numAssertions++;
+ return $this->numAssertions;
}
/**
View
4 PHPUnit/Framework/TestResult.php
@@ -571,6 +571,8 @@ public function getUncoveredWhitelistFiles()
*/
public function run(PHPUnit_Framework_Test $test)
{
+ PHPUnit_Framework_Assert::resetCount();
+
$error = FALSE;
$failure = FALSE;
@@ -630,6 +632,8 @@ public function run(PHPUnit_Framework_Test $test)
restore_error_handler();
}
+ $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
+
if ($error === TRUE) {
$this->addError($test, $e, $time);
}
Please sign in to comment.
Something went wrong with that request. Please try again.