Skip to content

Commit

Permalink
[Console] Added more semantic commands to detect verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx authored and fabpot committed Aug 9, 2013
1 parent 5cbfe30 commit 0fa3a74
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/CHANGELOG.md
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Console/Output/Output.php
Expand Up @@ -98,6 +98,26 @@ public function getVerbosity()
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}
*/
Expand Down
29 changes: 29 additions & 0 deletions src/Symfony/Component/Console/Tests/Output/OutputTest.php
Expand Up @@ -35,6 +35,35 @@ public function testSetGetVerbosity()
$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()
Expand Down

0 comments on commit 0fa3a74

Please sign in to comment.