Skip to content

[Scheduler] Fix #[AsCronTask] not passing arguments to command #60741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 7.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add autoconfiguredSchedulerCommand test
  • Loading branch information
Jan Pintr committed Jun 9, 2025
commit 19306999336557c3eb4096558170752d68f70263
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Scheduler\Attribute\AsCronTask;

#[AsCronTask(expression: '* * * * *', schedule: 'dummy_command')]
#[AsCronTask(expression: '0 * * * *', arguments: 'test', schedule: 'dummy_command')]
#[AsCommand(name: 'test:dummy-command')]
class DummyCommand extends Command
{
public static array $calls = [];

public function configure()
{
$this->addArgument('dummy-argument', InputArgument::OPTIONAL);
}

public function execute(InputInterface $input, ?OutputInterface $output = null): int
{
self::$calls[__FUNCTION__][] = $input->getArgument('dummy-argument');

return Command::SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyCommand;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummySchedule;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTask;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
Expand Down Expand Up @@ -88,6 +89,29 @@ public function testAutoconfiguredScheduler()
$this->assertSame([['5', 6], ['7', 8]], $calls['attributesOnMethod']);
}

public function testAutoconfiguredSchedulerCommand()
{
$container = self::getContainer();
$container->set('clock', $clock = new MockClock('2023-10-26T08:59:59Z'));

$this->assertTrue($container->get('receivers')->has('scheduler_dummy_command'));
$this->assertInstanceOf(SchedulerTransport::class, $cron = $container->get('receivers')->get('scheduler_dummy_command'));
$bus = $container->get(MessageBusInterface::class);

$getCalls = static function (float $sleep) use ($clock, $cron, $bus) {
DummyCommand::$calls = [];
$clock->sleep($sleep);
foreach ($cron->get() as $message) {
$bus->dispatch($message->with(new ReceivedStamp('scheduler_dummy_command')));
}

return DummyCommand::$calls;
};

$this->assertSame([], $getCalls(0));
$this->assertSame(['execute' => [0 => null, 1 => 'test']], $getCalls(1));
}

public function testSchedulerWithCustomTransport()
{
$container = self::getContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ services:
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTaskWithCustomReceiver:
autoconfigure: true

Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyCommand:
autoconfigure: true

clock:
synthetic: true

Expand Down
Loading
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