Skip to content

Commit 2e47a6e

Browse files
committed
Add Console::hasCommand method
1 parent 35d3d8a commit 2e47a6e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Console.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ public function removeCommands(array $names) : static
233233
return $this;
234234
}
235235

236+
/**
237+
* Tells if it has a command.
238+
*
239+
* @param string $name Command name
240+
*
241+
* @return bool
242+
*/
243+
public function hasCommand(string $name) : bool
244+
{
245+
return $this->getCommand($name) !== null;
246+
}
247+
236248
/**
237249
* Run the Console.
238250
*/

tests/ConsoleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ public function testRemoveCommands() : void
165165
self::assertNull($this->console->getCommand('help'));
166166
}
167167

168+
public function testHasCommand() : void
169+
{
170+
self::assertTrue($this->console->hasCommand('about'));
171+
$this->console->removeCommand('about');
172+
self::assertFalse($this->console->hasCommand('about'));
173+
}
174+
168175
public function testCommandString() : void
169176
{
170177
$this->console->addCommands([

0 commit comments

Comments
 (0)