Skip to content

[Mercure] fix service definition example in testing section #20040

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

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Jul 10, 2024

Tried to follow the example and noticed that this was wrong

@carsonbot carsonbot added this to the 5.4 milestone Jul 10, 2024
@dbu
Copy link
Contributor Author

dbu commented Jul 10, 2024

note: the mercure bundle then wraps this in a Symfony\Component\Mercure\Debug\TraceableHub class. to make the service accessible in tests (i wrote a class that records all updates to make assertions in my tests) i needed to do:

services:
    App\Tests\Functional\Stub\HubStub:
        public: true

    mercure.hub.default:
        alias: App\Tests\Functional\Stub\HubStub

should i add this instead of the simple syntax fix?


furthermore, config/packages/mercure.yaml configures public_url: '%env(MERCURE_PUBLIC_URL)%' and when i replace the hub in tests, the container fails to build with an error about unused environment variable:

Symfony\Component\DependencyInjection\Exception\EnvParameterException: Environment variables "MERCURE_PUBLIC_URL" are never used. Please, check your container's configuration.

my workaround for that was to add a parameter in services_test.yaml:

parameters:
    make_container_happy: '%env(MERCURE_PUBLIC_URL)%'

i assume this is a common issue. i don't know if there is a better solution, but ideally the guide would be complete to produce a working result without having to figure out these things. should i add this or something else?

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good catch

@carsonbot carsonbot changed the title fix service definition example in testing section [Mercure] fix service definition example in testing section Jul 10, 2024
@javiereguiluz
Copy link
Member

Thanks David.

@javiereguiluz javiereguiluz merged commit 3dc8ba5 into symfony:5.4 Jul 10, 2024
3 checks passed
@dbu dbu deleted the patch-2 branch July 10, 2024 19:26
@dbu
Copy link
Contributor Author

dbu commented Jul 10, 2024

@xabbuh thanks. what do you think about expanding the section a bit, as the env variable check broke tests for me and one can not access the stub service like this?

@xabbuh
Copy link
Member

xabbuh commented Jul 19, 2024

@dbu I am not completely if I understand what you have in mind. Can you give an example?

@dbu
Copy link
Contributor Author

dbu commented Jul 19, 2024

i tried to explain in #20040 (comment) : when i follow the documentation, flex configures an env variable MERCURE_PUBLIC_URL for me, and when i overwrite the hub default service, i get that error Environment variables "MERCURE_PUBLIC_URL" are never used. Please, check your container's configuration.

and the other thing would be to explain how to configure the service to actually be able to access it in my test to see what it received, because the service is being decorated. (though that maybe would better be a link as its not about the mercure component but about working with services in general)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants