Permalink
Browse files

- Merge [4674].

  • Loading branch information...
1 parent 7808e5a commit 1cabb04877b6bb07778da952c04ee37acc065ba6 @sebastianbergmann committed Feb 25, 2009
View
9 PHPUnit/Extensions/OutputTestCase.php
@@ -159,13 +159,16 @@ public function expectOutputString($expectedString)
}
/**
+ * @param mixed $dependencyInput
+ * @return mixed
+ * @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
ob_start();
try {
- parent::runTest();
+ $testResult = parent::runTest($dependencyInput);
}
catch (Exception $e) {
@@ -190,6 +193,8 @@ protected function runTest()
$this->assertEquals($this->expectedString, $this->output);
$this->expectedString = NULL;
}
+
+ return $testResult;
}
}
?>
View
9 PHPUnit/Extensions/PerformanceTestCase.php
@@ -71,11 +71,14 @@
protected $maxRunningTime = 0;
/**
+ * @param mixed $dependencyInput
+ * @return mixed
+ * @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
PHPUnit_Util_Timer::start();
- parent::runTest();
+ $testResult = parent::runTest($dependencyInput);
$time = PHPUnit_Util_Timer::stop();
if ($this->maxRunningTime != 0 &&
@@ -89,6 +92,8 @@ protected function runTest()
)
);
}
+
+ return $testResult;
}
/**
View
6 PHPUnit/Extensions/SeleniumTestCase.php
@@ -361,14 +361,16 @@ protected function getDriver(array $browser)
}
/**
+ * @param mixed $dependencyInput
+ * @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
$this->start();
try {
if (!is_file($this->name)) {
- parent::runTest();
+ parent::runTest($dependencyInput);
} else {
$this->runSelenese($this->name);
}
View
8 PHPUnit/Extensions/Story/SeleniumTestCase.php
@@ -161,15 +161,17 @@ protected function _and($contextOrOutcome)
/**
* Run this test's scenario.
*
+ * @param mixed $dependencyInput
+ * @return mixed
* @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
$autostop = $this->autoStop;
$this->autoStop = FALSE;
try {
- parent::runTest();
+ $testResult = parent::runTest($dependencyInput);
$this->scenario->run($this->world);
$this->autoStop = $autostop;
}
@@ -178,6 +180,8 @@ protected function runTest()
$this->autoStop = $autostop;
throw $e;
}
+
+ return $testResult;
}
/**
View
7 PHPUnit/Extensions/Story/TestCase.php
@@ -179,12 +179,15 @@ protected function _and($contextOrOutcome)
/**
* Run this test's scenario.
*
+ * @param mixed $dependencyInput
+ * @return mixed
* @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
- parent::runTest();
+ $testResult = parent::runTest($dependencyInput);
$this->scenario->run($this->world);
+ return $testResult;
}
/**
View
49 PHPUnit/Framework/TestCase.php
@@ -300,6 +300,11 @@
protected $result;
/**
+ * @var mixed
+ */
+ protected $testResult;
+
+ /**
* Constructs a test case with the given name.
*
* @param string $name
@@ -636,25 +641,29 @@ public function run(PHPUnit_Framework_TestResult $result = NULL)
*/
public function runBare()
{
+ $dependencyInput = NULL;
$this->numAssertions = 0;
if (!empty($this->dependencies)) {
- $className = get_class($this);
- $passed = $this->result->passed();
+ $className = get_class($this);
+ $passed = $this->result->passed();
+ $passedKeys = array_keys($passed);
foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}
- if (!isset($passed[$dependency])) {
+ if (!in_array($dependency, $passedKeys)) {
$this->markTestSkipped(
sprintf(
'This test depends on "%s" to pass.',
$dependency
)
);
+ } else {
+ $dependencyInput = $passed[$dependency];
}
}
}
@@ -687,7 +696,7 @@ public function runBare()
// Assert pre-conditions.
$this->assertPreConditions();
- $this->runTest();
+ $this->testResult = $this->runTest($dependencyInput);
// Assert post-conditions.
$this->assertPostConditions();
@@ -763,9 +772,11 @@ public function runBare()
/**
* Override to run the test and assert its state.
*
+ * @param mixed $dependencyInput
+ * @return mixed
* @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
if ($this->name === NULL) {
throw new RuntimeException(
@@ -784,9 +795,13 @@ protected function runTest()
try {
if (empty($this->data)) {
- $method->invoke($this);
+ if ($dependencyInput !== NULL) {
+ $testResult = $method->invoke($this, $dependencyInput);
+ } else {
+ $testResult = $method->invoke($this);
+ }
} else {
- $method->invokeArgs($this, $this->data);
+ $testResult = $method->invokeArgs($this, $this->data);
}
}
@@ -822,6 +837,8 @@ protected function runTest()
$this->numAssertions++;
$this->fail('Expected exception ' . $this->expectedException);
}
+
+ return $testResult;
}
/**
@@ -913,6 +930,24 @@ public function setSharedFixture($sharedFixture)
}
/**
+ * @return mixed
+ * @since Method available since Release 3.4.0
+ */
+ public function getResult()
+ {
+ return $this->testResult;
+ }
+
+ /**
+ * @param mixed $result
+ * @since Method available since Release 3.4.0
+ */
+ public function setResult($result)
+ {
+ $this->testResult = $result;
+ }
+
+ /**
* This method is a wrapper for the ini_set() function that automatically
* resets the modified php.ini setting to its original value after the
* test is run.
View
3 PHPUnit/Framework/TestResult.php
@@ -195,7 +195,6 @@ public function flushListeners()
/**
* Adds an error to the list of errors.
- * The passed in exception caused the error.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
@@ -325,7 +324,7 @@ public function endTest(PHPUnit_Framework_Test $test, $time)
}
if (!$this->lastTestFailed && $test instanceof PHPUnit_Framework_TestCase) {
- $this->passed[get_class($test) . '::' . $test->getName()] = TRUE;
+ $this->passed[get_class($test) . '::' . $test->getName()] = $test->getResult();
$this->time += $time;
}
}
View
4 PHPUnit/Framework/Warning.php
@@ -80,8 +80,10 @@ public function __construct($message = '')
}
/**
+ * @param mixed $dependencyInput
+ * @throws RuntimeException
*/
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
$this->fail($this->message);
}
View
22 PHPUnit/Tests/TextUI/dependencies2.phpt
@@ -0,0 +1,22 @@
+--TEST--
+phpunit --verbose DependencyTestSuite ../_files/DependencyTestSuite.php
+--FILE--
+<?php
+$_SERVER['argv'][1] = '--no-configuration';
+$_SERVER['argv'][2] = '--verbose';
+$_SERVER['argv'][3] = 'StackTest';
+$_SERVER['argv'][4] = dirname(dirname(__FILE__)) . '/_files/StackTest.php';
+
+require_once dirname(dirname(dirname(__FILE__))) . '/TextUI/Command.php';
+PHPUnit_TextUI_Command::main();
+?>
+--EXPECTF--
+PHPUnit %s by Sebastian Bergmann.
+
+StackTest
+..
+
+Time: %i seconds
+
+OK (2 tests, 5 assertions)
+
View
2 PHPUnit/Tests/_files/Error.php
@@ -1,7 +1,7 @@
<?php
class Error extends PHPUnit_Framework_TestCase
{
- public function runTest()
+ protected function runTest($dependencyInput = NULL)
{
throw new Exception;
}
View
2 PHPUnit/Tests/_files/Failure.php
@@ -1,7 +1,7 @@
<?php
class Failure extends PHPUnit_Framework_TestCase
{
- public function runTest()
+ protected function runTest($dependencyInput = NULL)
{
$this->fail();
}
View
24 PHPUnit/Tests/_files/StackTest.php
@@ -0,0 +1,24 @@
+<?php
+class StackTest extends PHPUnit_Framework_TestCase
+{
+ public function testPush()
+ {
+ $stack = array();
+ $this->assertEquals(0, count($stack));
+
+ array_push($stack, 'foo');
+ $this->assertEquals('foo', $stack[count($stack)-1]);
+ $this->assertEquals(1, count($stack));
+
+ return $stack;
+ }
+
+ /**
+ * @depends testPush
+ */
+ public function testPop(array $stack)
+ {
+ $this->assertEquals('foo', array_pop($stack));
+ $this->assertEquals(0, count($stack));
+ }
+}
View
2 PHPUnit/Tests/_files/Success.php
@@ -1,7 +1,7 @@
<?php
class Success extends PHPUnit_Framework_TestCase
{
- public function runTest()
+ protected function runTest($dependencyInput = NULL)
{
}
}
View
2 PHPUnit/Tests/_files/TornDown.php
@@ -8,7 +8,7 @@ protected function tearDown()
$this->tornDown = TRUE;
}
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
throw new Exception;
}
View
2 PHPUnit/Tests/_files/TornDown2.php
@@ -9,7 +9,7 @@ protected function tearDown()
throw new Exception;
}
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
throw new Exception;
}
View
2 PHPUnit/Tests/_files/WasRun.php
@@ -3,7 +3,7 @@ class WasRun extends PHPUnit_Framework_TestCase
{
public $wasRun = FALSE;
- protected function runTest()
+ protected function runTest($dependencyInput = NULL)
{
$this->wasRun = TRUE;
}
View
4 package.xml
@@ -872,6 +872,7 @@
<file baseinstalldir="/" name="debug.phpt" role="test" />
<file baseinstalldir="/" name="default.phpt" role="test" />
<file baseinstalldir="/" name="dependencies.phpt" role="test" />
+ <file baseinstalldir="/" name="dependencies2.phpt" role="test" />
<file baseinstalldir="/" name="exclude-group.phpt" role="test" />
<file baseinstalldir="/" name="failure.phpt" role="test" />
<file baseinstalldir="/" name="failure-verbose.phpt" role="test" />
@@ -1056,6 +1057,9 @@
<file baseinstalldir="/" name="SleepTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
+ <file baseinstalldir="/" name="StackTest.php" role="test">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
<file baseinstalldir="/" name="Struct.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>

0 comments on commit 1cabb04

Please sign in to comment.