Skip to content

Commit 225a9fc

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

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

tests/Unit/AbstractTerminableCommandTest.php

Lines changed: 26 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,20 @@ protected function commandBody(InputInterface $input, OutputInterface $output):
138134
$this->assertSame(143, $exitCode);
139135
}
140136

137+
/**
138+
* @dataProvider signalProvider
139+
*/
140+
public function testGetSubscribedSignals(int $signal): void
141+
{
142+
$stubCommand = $this->createStubTerminableCommand();
143+
144+
if (! interface_exists(SignalableCommandInterface::class) || ! $stubCommand instanceof SignalableCommandInterface) {
145+
$this->markTestSkipped('This test requires the Symfony 7.3+ implementation');
146+
}
147+
148+
$this->assertContains($signal, $stubCommand->getSubscribedSignals(), 'Signal not subscribed to');
149+
}
150+
141151
/**
142152
* @return array{0: int}[]
143153
*/
@@ -148,4 +158,14 @@ public function signalProvider(): array
148158
[SIGTERM],
149159
];
150160
}
161+
162+
private function createStubTerminableCommand(): AbstractTerminableCommand
163+
{
164+
return new class ('dummy:command') extends AbstractTerminableCommand {
165+
protected function commandBody(InputInterface $input, OutputInterface $output): int
166+
{
167+
return 0;
168+
}
169+
};
170+
}
151171
}

0 commit comments

Comments
 (0)