merged branch lyrixx/console-tester-status-code (PR #8023)

This PR was merged into the master branch.

Discussion
----------

[2.4][Console] Added status code to CommandTester and ApplicationTester

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes, but not on travis (segfault)
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Theses classes are already statefull. They contain the input and the
output data. So we can safely add the last status code to the class.

Commits
-------

6526166 [Console] Added status code to CommandTester and ApplicationTester
This commit is contained in:
Fabien Potencier 2013-06-04 17:09:18 +02:00
commit a8929762bc
4 changed files with 34 additions and 2 deletions

View File

@ -32,6 +32,7 @@ class ApplicationTester
private $application;
private $input;
private $output;
private $statusCode;
/**
* Constructor.
@ -72,7 +73,7 @@ class ApplicationTester
$this->output->setVerbosity($options['verbosity']);
}
return $this->application->run($this->input, $this->output);
return $this->statusCode = $this->application->run($this->input, $this->output);
}
/**
@ -114,4 +115,14 @@ class ApplicationTester
{
return $this->output;
}
/**
* Gets the status code returned by the last execution of the application.
*
* @return integer The status code
*/
public function getStatusCode()
{
return $this->statusCode;
}
}

View File

@ -25,6 +25,7 @@ class CommandTester
private $command;
private $input;
private $output;
private $statusCode;
/**
* Constructor.
@ -65,7 +66,7 @@ class CommandTester
$this->output->setVerbosity($options['verbosity']);
}
return $this->command->run($this->input, $this->output);
return $this->statusCode = $this->command->run($this->input, $this->output);
}
/**
@ -107,4 +108,14 @@ class CommandTester
{
return $this->output;
}
/**
* Gets the status code returned by the last execution of the application.
*
* @return integer The status code
*/
public function getStatusCode()
{
return $this->statusCode;
}
}

View File

@ -61,4 +61,9 @@ class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
}
public function testGetStatusCode()
{
$this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
}
}

View File

@ -59,4 +59,9 @@ class CommandTesterTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
}
public function testGetStatusCode()
{
$this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
}
}