Skip to content

Commit 0fa3a74

Browse files
lyrixxfabpot
authored andcommitted
[Console] Added more semantic commands to detect verbosity
1 parent 5cbfe30 commit 0fa3a74

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2.4.0
55
-----
66

7+
* added convevient method to detect verbosity level
78
* [BC BREAK] made descriptors use output instead of returning a string
89

910
2.3.0

src/Symfony/Component/Console/Output/Output.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ public function getVerbosity()
9898
return $this->verbosity;
9999
}
100100

101+
public function isQuiet()
102+
{
103+
return self::VERBOSITY_QUIET === $this->verbosity;
104+
}
105+
106+
public function isVerbose()
107+
{
108+
return self::VERBOSITY_VERBOSE <= $this->verbosity;
109+
}
110+
111+
public function isVeryVerbose()
112+
{
113+
return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
114+
}
115+
116+
public function isDebug()
117+
{
118+
return self::VERBOSITY_DEBUG <= $this->verbosity;
119+
}
120+
101121
/**
102122
* {@inheritdoc}
103123
*/

src/Symfony/Component/Console/Tests/Output/OutputTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ public function testSetGetVerbosity()
3535
$output = new TestOutput();
3636
$output->setVerbosity(Output::VERBOSITY_QUIET);
3737
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '->setVerbosity() sets the verbosity');
38+
39+
$this->assertTrue($output->isQuiet());
40+
$this->assertFalse($output->isVerbose());
41+
$this->assertFalse($output->isVeryVerbose());
42+
$this->assertFalse($output->isDebug());
43+
44+
$output->setVerbosity(Output::VERBOSITY_NORMAL);
45+
$this->assertFalse($output->isQuiet());
46+
$this->assertFalse($output->isVerbose());
47+
$this->assertFalse($output->isVeryVerbose());
48+
$this->assertFalse($output->isDebug());
49+
50+
$output->setVerbosity(Output::VERBOSITY_VERBOSE);
51+
$this->assertFalse($output->isQuiet());
52+
$this->assertTrue($output->isVerbose());
53+
$this->assertFalse($output->isVeryVerbose());
54+
$this->assertFalse($output->isDebug());
55+
56+
$output->setVerbosity(Output::VERBOSITY_VERY_VERBOSE);
57+
$this->assertFalse($output->isQuiet());
58+
$this->assertTrue($output->isVerbose());
59+
$this->assertTrue($output->isVeryVerbose());
60+
$this->assertFalse($output->isDebug());
61+
62+
$output->setVerbosity(Output::VERBOSITY_DEBUG);
63+
$this->assertFalse($output->isQuiet());
64+
$this->assertTrue($output->isVerbose());
65+
$this->assertTrue($output->isVeryVerbose());
66+
$this->assertTrue($output->isDebug());
3867
}
3968

4069
public function testWriteWithVerbosityQuiet()

0 commit comments

Comments
 (0)