Skip to content

Commit a4a3302

Browse files
[Console] Improve code coverage
1 parent 194dcf3 commit a4a3302

23 files changed

+446
-5
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ public function getSynopsis($short = false)
572572
* Add a command usage example.
573573
*
574574
* @param string $usage The usage, it'll be prefixed with the command name
575+
*
576+
* @return Command
575577
*/
576578
public function addUsage($usage)
577579
{

src/Symfony/Component/Console/Helper/TableStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TableStyle
4242
public function setPaddingChar($paddingChar)
4343
{
4444
if (!$paddingChar) {
45-
throw new LogicException('The padding char must not be empty');
45+
throw new LogicException('The padding char must not be empty.');
4646
}
4747

4848
$this->paddingChar = $paddingChar;

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ public function testGetSetAliases()
156156
$this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases');
157157
}
158158

159+
/**
160+
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
161+
* @expectedExceptionMessage $aliases must be an array or an instance of \Traversable
162+
*/
163+
public function testSetAliasesThrowsInvalidArgumentException()
164+
{
165+
$command = new \TestCommand();
166+
167+
$command->setAliases('foo');
168+
}
169+
170+
public function testAddUsage()
171+
{
172+
$command = new \TestCommand();
173+
174+
$command
175+
->addUsage('foo')
176+
->addUsage('bar');
177+
178+
$this->assertSame(array('namespace:name foo', 'namespace:name bar'), $command->getUsages());
179+
}
180+
159181
public function testGetSynopsis()
160182
{
161183
$command = new \TestCommand();

src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public function testDescribeInputDefinition(InputDefinition $definition, $expect
3838
$this->assertDescription($expectedDescription, $definition);
3939
}
4040

41+
/**
42+
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
43+
* @expectedExceptionMessage Object of type "stdClass" is not describable.
44+
*/
45+
public function testDescribeCommandInvalidObjects()
46+
{
47+
$this->assertDescription(null, new \stdClass());
48+
}
49+
4150
/** @dataProvider getDescribeCommandTestData */
4251
public function testDescribeCommand(Command $command, $expectedDescription)
4352
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Style\SymfonyStyle;
6+
7+
// ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output = new SymfonyStyle($input, $output);
10+
$output->section('Lorem ipsum dolor sit amet');
11+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Exception\RuntimeException;
4+
use Symfony\Component\Console\Input\InputInterface;
5+
use Symfony\Component\Console\Output\OutputInterface;
6+
use Symfony\Component\Console\Style\SymfonyStyle;
7+
8+
// ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment
9+
return function (InputInterface $input, OutputInterface $output) {
10+
$output = new SymfonyStyle($input, $output);
11+
12+
try {
13+
$output->progressFinish();
14+
} catch (RuntimeException $e) {
15+
$output->writeln('OK');
16+
17+
return;
18+
}
19+
20+
$output->writeln('KO');
21+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
Lorem ipsum dolor sit amet
3+
--------------------------
4+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0/10 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0%
2+
4/10 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░] 40%
3+
10/10 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0/10 [>---------------------------] 0%
2+
4/10 [===========>----------------] 40%
3+
10/10 [============================] 100%
4+

0 commit comments

Comments
 (0)