Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad08041

Browse files
Jan Pintrnicolas-grekas
Jan Pintr
authored andcommitted
[Scheduler] Fixscheduler.task tag arguments optionality
1 parentb4e3bca commitad08041

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 =newDefinition(RunCommandMessage::class, [$commandName.($tagAttributes['arguments'] ?"{$tagAttributes['arguments']}" :'')]);
63+
$message =newDefinition(RunCommandMessage::class, [$commandName.(($tagAttributes['arguments'] ??null) ?"{$tagAttributes['arguments']}" :'')]);
6464
}else {
6565
$message =newDefinition(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+
namespaceSymfony\Component\Console\Tests\DependencyInjection;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Console\Attribute\AsCommand;
16+
useSymfony\Component\DependencyInjection\ContainerBuilder;
17+
useSymfony\Component\DependencyInjection\Definition;
18+
useSymfony\Component\Scheduler\DependencyInjection\AddScheduleMessengerPass;
19+
20+
class AddScheduleMessengerPassTestextends TestCase
21+
{
22+
/**
23+
* @dataProvider processSchedulerTaskCommandProvider
24+
*/
25+
publicfunctiontestProcessSchedulerTaskCommand(array$arguments,string$exceptedCommand)
26+
{
27+
$container =newContainerBuilder();
28+
29+
$definition =newDefinition(SchedulableCommand::class);
30+
$definition->addTag('console.command');
31+
$definition->addTag('scheduler.task',$arguments);
32+
$container->setDefinition(SchedulableCommand::class,$definition);
33+
34+
(newAddScheduleMessengerPass())->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+
publicstaticfunctionprocessSchedulerTaskCommandProvider():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+
publicfunction__invoke():void
62+
{
63+
}
64+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp