[Console] Added status code to CommandTester and ApplicationTester

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.
This commit is contained in:
Grégoire Pineau 2013-05-13 09:35:44 +02:00
parent 6d64c9a990
commit 6526166b05
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');
}
}