Skip to content

Commit bcca8a1

Browse files
committed
Cover new method with unit test
1 parent d03db8f commit bcca8a1

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

tests/Unit/AbstractTerminableCommandTest.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Prophecy\Argument;
1010
use Prophecy\PhpUnit\ProphecyTrait;
1111
use Symfony\Bridge\PhpUnit\ClockMock;
12+
use Symfony\Component\Console\Command\SignalableCommandInterface;
1213
use Symfony\Component\Console\Input\ArrayInput;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
@@ -117,12 +118,7 @@ protected function commandBody(InputInterface $input, OutputInterface $output):
117118
*/
118119
public function testReceiveSignalBeforeCommandBody(int $signal): void
119120
{
120-
$stubCommand = new class ('dummy:command') extends AbstractTerminableCommand {
121-
protected function commandBody(InputInterface $input, OutputInterface $output): int
122-
{
123-
return 0;
124-
}
125-
};
121+
$stubCommand = $this->createStubTerminableCommand();
126122

127123
$output = $this->prophesize(OutputInterface::class);
128124
$output->writeln(Argument::containingString('Starting'), OutputInterface::VERBOSITY_VERBOSE)
@@ -138,6 +134,17 @@ protected function commandBody(InputInterface $input, OutputInterface $output):
138134
$this->assertSame(143, $exitCode);
139135
}
140136

137+
public function testGetSubscribedSignals(int $signal): void
138+
{
139+
$stubCommand = $this->createStubTerminableCommand();
140+
141+
if (! class_exists(SignalableCommandInterface::class) || ! $stubCommand instanceof SignalableCommandInterface) {
142+
$this->markTestSkipped('This test requires the Symfony 7.3+ implementation');
143+
}
144+
145+
$this->assertContains($signal, $stubCommand->getSubscribedSignals(), 'Signal not subscribed to');
146+
}
147+
141148
/**
142149
* @return array{0: int}[]
143150
*/
@@ -148,4 +155,14 @@ public function signalProvider(): array
148155
[SIGTERM],
149156
];
150157
}
158+
159+
private function createStubTerminableCommand(): AbstractTerminableCommand
160+
{
161+
return new class ('dummy:command') extends AbstractTerminableCommand {
162+
protected function commandBody(InputInterface $input, OutputInterface $output): int
163+
{
164+
return 0;
165+
}
166+
};
167+
}
151168
}

0 commit comments

Comments
 (0)