Skip to content

[Turbo] TurboStreamListenRenderer service doesn't register correctly when Mercure Hub is mocked #2775

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
milankaranovic opened this issue May 26, 2025 · 1 comment
Labels
Bug Bug Fix Status: Waiting Feedback Needs feedback from the author Turbo

Comments

@milankaranovic
Copy link

Hey everyone! 👋🏻

I updated symfony/ux-turbo from v2.23.0 to 2.25.2 and my tests (WebTestCase) started failing with this error

ErrorException: An exception has been thrown during the rendering of a template 
("Too few arguments to function Symfony\UX\Turbo\Bridge\Mercure\TurboStreamListenRenderer::__construct(), 
3 passed in /app/var/cache/test/ContainerO3ffV3d/getTurbo_Mercure_Default_RendererService.php
 on line 31 and exactly 4 expected") in "foo.html.twig" at line 31.

On line 31 is turbo_stream_listen.

Additionally, I havemercure.hub.default mocked according to these instructions https://symfony.com/doc/current/mercure.html#testing

I see that this PR #2447 has been merged in v2.24.0, and a lot of things related to turbo_stream_listen has changed, including RegisterMercureHubsPass. It loops through mercure.hub tags, so I ended up with this solution

# config/services_test.yaml
services:
    mercure.hub.default:
        class: Tests\Services\MockMercureHub
        tags:
            - 'mercure.hub'

Reporting this because I'm not sure if this is a bug or if the documentation has to be updated.

@milankaranovic milankaranovic added the Bug Bug Fix label May 26, 2025
@carsonbot carsonbot added Turbo Status: Needs Review Needs to be reviewed labels May 26, 2025
@Kocal
Copy link
Member

Kocal commented Jun 11, 2025

Hi,

I tried to reproduce your issue but without success.

If I create a Hub stub like this:

<?php

declare(strict_types=1);

namespace App\Mercure;

use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Jwt\TokenFactoryInterface;
use Symfony\Component\Mercure\Jwt\TokenProviderInterface;
use Symfony\Component\Mercure\Update;

final readonly class HubStub implements HubInterface
{
    public function __construct(
        private string $publicUrl,
    ) {
    }

    public function getUrl(): string
    {
        // TODO: Implement getUrl() method.
    }

    public function getPublicUrl(): string
    {
        return $this->publicUrl;
    }

    public function getProvider(): TokenProviderInterface
    {
        // TODO: Implement getProvider() method.
    }

    public function getFactory(): ?TokenFactoryInterface
    {
        // TODO: Implement getFactory() method.
    }

    public function publish(Update $update): string
    {
        return 'id';
    }
}

and register-it in my configuration like this:

# config/services_test.yaml
services:
    mercure.hub.default:
        class: App\Mercure\HubStub
        arguments:
            - '%env(MERCURE_PUBLIC_URL)%'

Running a PHPUnit KernelTestCase with dump(self::getContainer()->get(HubInterface::class)) correctly shows me my App\Mercure\HubStub instance.

Maybe do you have a reproducer?

@Kocal Kocal added Status: Waiting Feedback Needs feedback from the author and removed Status: Needs Review Needs to be reviewed labels Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Waiting Feedback Needs feedback from the author Turbo
Projects
None yet
Development

No branches or pull requests

3 participants