Skip to content

Commit 188c9ea

Browse files
committed
Distinguish ServiceCallMessage arguments in scheduler
1 parent b6ae3aa commit 188c9ea

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Messenger/DummyTask.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#[AsCronTask(expression: '0 * * * *', timezone: 'Europe/Berlin', arguments: ['2'], schedule: 'dummy_task', method: 'method2')]
1010
#[AsPeriodicTask(frequency: 5, arguments: [3], schedule: 'dummy_task')]
1111
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', jitter: 60, arguments: ['4'], schedule: 'dummy_task', method: 'method4')]
12+
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', arguments: ['9'], schedule: 'dummy_task', method: 'method5')]
13+
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', arguments: ['9b'], schedule: 'dummy_task', method: 'method5')]
14+
#[AsPeriodicTask(frequency: '1 day', from: '2023-10-25 09:59:00Z', arguments: ['named' => '9'], schedule: 'dummy_task', method: 'method5')]
1215
class DummyTask
1316
{
1417
public static array $calls = [];

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SchedulerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function testAutoconfiguredScheduler()
8484
$this->assertCount(779, $calls['__invoke']);
8585
$this->assertSame([['2']], $calls['method2']);
8686
$this->assertSame([['4']], $calls['method4']);
87+
$this->assertSame([['9'], ['9b'], ['named' => '9']], $calls['method5']);
8788
$this->assertSame([['5', 6], ['7', 8]], $calls['attributesOnMethod']);
8889
}
8990

src/Symfony/Component/Scheduler/Messenger/ServiceCallMessage.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public function getArguments(): array
4242

4343
public function __toString(): string
4444
{
45-
return "@$this->serviceId".('__invoke' !== $this->method ? "::$this->method" : '');
45+
return "@$this->serviceId".('__invoke' !== $this->method ? "::$this->method" : '').$this->getSerializedArguments();
46+
}
47+
48+
private function getSerializedArguments(): string
49+
{
50+
$arguments = [];
51+
foreach ($this->arguments as $key => $value) {
52+
$value = var_export($value, true);
53+
$arguments[] = is_string($key) ? "$key: $value" : $value;
54+
}
55+
56+
return '('.implode(',', $arguments).')';
4657
}
4758
}

0 commit comments

Comments
 (0)