Skip to content

Commit d8da935

Browse files
committed
minor #20817 [Console] improved code coverage of Command class (ShinDarth)
This PR was squashed before being merged into the 2.7 branch (closes #20817). Discussion ---------- [Console] improved code coverage of Command class | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT This PR increases the code coverage of the Command class from ``86.82%`` to ``96.90%``. Commits ------- d393113 [Console] improved code coverage of Command class
2 parents 0beb41e + 84705c4 commit d8da935

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

Tests/Command/CommandTest.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public function testSetApplication()
5454
$command = new \TestCommand();
5555
$command->setApplication($application);
5656
$this->assertEquals($application, $command->getApplication(), '->setApplication() sets the current application');
57+
$this->assertEquals($application->getHelperSet(), $command->getHelperSet());
58+
}
59+
60+
public function testSetApplicationNull()
61+
{
62+
$command = new \TestCommand();
63+
$command->setApplication(null);
64+
$this->assertNull($command->getHelperSet());
5765
}
5866

5967
public function testSetGetDefinition()
@@ -156,6 +164,13 @@ public function testGetSetAliases()
156164
$this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases');
157165
}
158166

167+
public function testSetAliasesNull()
168+
{
169+
$command = new \TestCommand();
170+
$this->setExpectedException('InvalidArgumentException');
171+
$command->setAliases(null);
172+
}
173+
159174
public function testGetSynopsis()
160175
{
161176
$command = new \TestCommand();
@@ -164,6 +179,15 @@ public function testGetSynopsis()
164179
$this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
165180
}
166181

182+
public function testAddGetUsages()
183+
{
184+
$command = new \TestCommand();
185+
$command->addUsage('foo1');
186+
$command->addUsage('foo2');
187+
$this->assertContains('namespace:name foo1', $command->getUsages());
188+
$this->assertContains('namespace:name foo2', $command->getUsages());
189+
}
190+
167191
public function testGetHelper()
168192
{
169193
$application = new Application();
@@ -275,8 +299,8 @@ public function testRunReturnsIntegerExitCode()
275299

276300
$command = $this->getMockBuilder('TestCommand')->setMethods(array('execute'))->getMock();
277301
$command->expects($this->once())
278-
->method('execute')
279-
->will($this->returnValue('2.3'));
302+
->method('execute')
303+
->will($this->returnValue('2.3'));
280304
$exitCode = $command->run(new StringInput(''), new NullOutput());
281305
$this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)');
282306
}
@@ -297,6 +321,17 @@ public function testRunReturnsAlwaysInteger()
297321
$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
298322
}
299323

324+
public function testRunWithProcessTitle()
325+
{
326+
$command = new \TestCommand();
327+
$command->setApplication(new Application());
328+
$command->setProcessTitle('foo');
329+
$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
330+
if (function_exists('cli_set_process_title')) {
331+
$this->assertEquals('foo', cli_get_process_title());
332+
}
333+
}
334+
300335
public function testSetCode()
301336
{
302337
$command = new \TestCommand();

0 commit comments

Comments
 (0)