Skip to content

Commit be4761b

Browse files
committed
add getter for command
1 parent 68031cb commit be4761b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Commands.php

+8
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ public function setDescription($description)
9595
{
9696
$this->description = $description;
9797
}
98+
99+
/**
100+
* @return Command
101+
*/
102+
public function getCommand()
103+
{
104+
return $this->command;
105+
}
98106
}

tests/Commands/ParseTest.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPUnit\Framework\TestCase;
66
use tflori\Commands\Command;
77
use tflori\Commands\Commands;
8-
use tflori\Getopt\Getopt;
98
use tflori\Getopt\Option;
109

1110
class ParseTest extends TestCase
@@ -66,4 +65,15 @@ public function testAddsOptionsFromCommand()
6665
self::assertSame(1, $commands->getOption('a'));
6766
self::assertSame(1, $commands->getOption('b'));
6867
}
68+
69+
public function testStoresTheCalledCommand()
70+
{
71+
$commands = new Commands();
72+
$command = new Command('help', 'Show the help for command', 'var_dump');
73+
$commands->addCommand($command);
74+
75+
$commands->parse('help');
76+
77+
self::assertSame($command, $commands->getCommand());
78+
}
6979
}

0 commit comments

Comments
 (0)