[Console] Added more semantic commands to detect verbosity

This commit is contained in:
Grégoire Pineau 2013-08-02 11:18:33 +02:00 committed by Fabien Potencier
parent 5cbfe302c2
commit 0fa3a7475f
3 changed files with 50 additions and 0 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
2.4.0
-----
* added convevient method to detect verbosity level
* [BC BREAK] made descriptors use output instead of returning a string
2.3.0

View File

@ -98,6 +98,26 @@ abstract class Output implements OutputInterface
return $this->verbosity;
}
public function isQuiet()
{
return self::VERBOSITY_QUIET === $this->verbosity;
}
public function isVerbose()
{
return self::VERBOSITY_VERBOSE <= $this->verbosity;
}
public function isVeryVerbose()
{
return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
}
public function isDebug()
{
return self::VERBOSITY_DEBUG <= $this->verbosity;
}
/**
* {@inheritdoc}
*/

View File

@ -35,6 +35,35 @@ class OutputTest extends \PHPUnit_Framework_TestCase
$output = new TestOutput();
$output->setVerbosity(Output::VERBOSITY_QUIET);
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '->setVerbosity() sets the verbosity');
$this->assertTrue($output->isQuiet());
$this->assertFalse($output->isVerbose());
$this->assertFalse($output->isVeryVerbose());
$this->assertFalse($output->isDebug());
$output->setVerbosity(Output::VERBOSITY_NORMAL);
$this->assertFalse($output->isQuiet());
$this->assertFalse($output->isVerbose());
$this->assertFalse($output->isVeryVerbose());
$this->assertFalse($output->isDebug());
$output->setVerbosity(Output::VERBOSITY_VERBOSE);
$this->assertFalse($output->isQuiet());
$this->assertTrue($output->isVerbose());
$this->assertFalse($output->isVeryVerbose());
$this->assertFalse($output->isDebug());
$output->setVerbosity(Output::VERBOSITY_VERY_VERBOSE);
$this->assertFalse($output->isQuiet());
$this->assertTrue($output->isVerbose());
$this->assertTrue($output->isVeryVerbose());
$this->assertFalse($output->isDebug());
$output->setVerbosity(Output::VERBOSITY_DEBUG);
$this->assertFalse($output->isQuiet());
$this->assertTrue($output->isVerbose());
$this->assertTrue($output->isVeryVerbose());
$this->assertTrue($output->isDebug());
}
public function testWriteWithVerbosityQuiet()