Skip to content

Commit ad08041

Browse files
Jan Pintrnicolas-grekas
authored andcommitted
[Scheduler] Fix scheduler.task tag arguments optionality
1 parent b4e3bca commit ad08041

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function process(ContainerBuilder $container): void
6060
$attribute = ($container->getReflectionClass($serviceDefinition->getClass())->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();
6161
$commandName = $attribute?->name ?? $serviceDefinition->getClass()::getDefaultName();
6262

63-
$message = new Definition(RunCommandMessage::class, [$commandName.($tagAttributes['arguments'] ? " {$tagAttributes['arguments']}" : '')]);
63+
$message = new Definition(RunCommandMessage::class, [$commandName.(($tagAttributes['arguments'] ?? null) ? " {$tagAttributes['arguments']}" : '')]);
6464
} else {
6565
$message = new Definition(ServiceCallMessage::class, [$serviceId, $tagAttributes['method'] ?? '__invoke', (array) ($tagAttributes['arguments'] ?? [])]);
6666
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Attribute\AsCommand;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Definition;
18+
use Symfony\Component\Scheduler\DependencyInjection\AddScheduleMessengerPass;
19+
20+
class AddScheduleMessengerPassTest extends TestCase
21+
{
22+
/**
23+
* @dataProvider processSchedulerTaskCommandProvider
24+
*/
25+
public function testProcessSchedulerTaskCommand(array $arguments, string $exceptedCommand)
26+
{
27+
$container = new ContainerBuilder();
28+
29+
$definition = new Definition(SchedulableCommand::class);
30+
$definition->addTag('console.command');
31+
$definition->addTag('scheduler.task', $arguments);
32+
$container->setDefinition(SchedulableCommand::class, $definition);
33+
34+
(new AddScheduleMessengerPass())->process($container);
35+
36+
$schedulerProvider = $container->getDefinition('scheduler.provider.default');
37+
$calls = $schedulerProvider->getMethodCalls();
38+
39+
$this->assertCount(1, $calls);
40+
$this->assertCount(2, $calls[0]);
41+
42+
$messageDefinition = $calls[0][1][0];
43+
$messageArguments = $messageDefinition->getArgument('$message');
44+
$command = $messageArguments->getArgument(0);
45+
46+
$this->assertSame($exceptedCommand, $command);
47+
}
48+
49+
public static function processSchedulerTaskCommandProvider(): iterable
50+
{
51+
yield 'no arguments' => [['trigger' => 'every', 'frequency' => '1 hour'], 'schedulable'];
52+
yield 'null arguments' => [['trigger' => 'every', 'frequency' => '1 hour', 'arguments' => null], 'schedulable'];
53+
yield 'empty arguments' => [['trigger' => 'every', 'frequency' => '1 hour', 'arguments' => ''], 'schedulable'];
54+
yield 'test argument' => [['trigger' => 'every', 'frequency' => '1 hour', 'arguments' => 'test'], 'schedulable test'];
55+
}
56+
}
57+
58+
#[AsCommand(name: 'schedulable')]
59+
class SchedulableCommand
60+
{
61+
public function __invoke(): void
62+
{
63+
}
64+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy