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

[FrameworkBundle] Allow fetching private services from test clients #26499

Merged
merged 1 commit into from Mar 16, 2018

Conversation

Projects
None yet
7 participants
@nicolas-grekas
Member

nicolas-grekas commented Mar 12, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25814
License MIT
Doc PR -

With this PR, $client->getContainer() returns a special container that gives access to private services as if they were public.

Tests derived from WebTestCase and KernelTestCase can access this special container by using the new static::$container property.

*/
public function compile()
{
return $this->publicContainer->isCompiled();

This comment has been minimized.

@jakzal

jakzal Mar 12, 2018

Member

Typo? $this->publicContainer->compile();

@jakzal

This comment has been minimized.

Member

jakzal commented Mar 12, 2018

Looks promising! The only issue I see is that it currently requires the Client, while a common use case is to extend the KernelTestCase and fetch the container from kernel.

Edit: I guess in such scenario we can still do $container->get('test.service_container')->get('my_private_service')

@ogizanagi

This comment has been minimized.

Member

ogizanagi commented Mar 12, 2018

In my experience, this would be useful for any KernelTestCase, not only WebTestCase. So should the service be public and a getter provided in KernelTestCase?

@nicolas-grekas

This comment has been minimized.

Member

nicolas-grekas commented Mar 12, 2018

In my experience, this would be useful for any KernelTestCase

OK, what about the new patch?

@ogizanagi

This comment has been minimized.

Member

ogizanagi commented Mar 12, 2018

Better :)

@nicolas-grekas

This comment has been minimized.

Member

nicolas-grekas commented Mar 13, 2018

PR ready. Unused private services are still removed. This is a requirement because not all private services are valid. Since they are removed, this is not an issue but a feature. Keeping a reference to all private services would be a BC break (as experienced on the test suite before handling this.)

@nicolas-grekas nicolas-grekas merged commit a840809 into symfony:master Mar 16, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

nicolas-grekas added a commit that referenced this pull request Mar 16, 2018

feature #26499 [FrameworkBundle] Allow fetching private services from…
… test clients (nicolas-grekas)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[FrameworkBundle] Allow fetching private services from test clients

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25814
| License       | MIT
| Doc PR        | -

With this PR, `$client->getContainer()` returns a special container that gives access to private services as if they were public.

Tests derived from `WebTestCase` and `KernelTestCase` can access this special container by using the new `static::$container` property.

Commits
-------

a840809 [FrameworkBundle] Allow fetching private services from test clients

@nicolas-grekas nicolas-grekas deleted the nicolas-grekas:test-container branch Mar 16, 2018

@kniziol

This comment has been minimized.

kniziol commented Mar 19, 2018

@nicolas-grekas It will be available in 3.4 version?

@nicolas-grekas

This comment has been minimized.

Member

nicolas-grekas commented Mar 19, 2018

that's a new feature, so for 4.1

@umpirsky

This comment has been minimized.

Contributor

umpirsky commented Mar 20, 2018

So, actual code that's being tested will still use regular container that cannot access private services, right?

@nicolas-grekas

This comment has been minimized.

Member

nicolas-grekas commented Mar 20, 2018

@umpirski right.

curry684 added a commit to snc/SncRedisBundle that referenced this pull request Apr 10, 2018

Add workaround for testing private services
Since symfony/symfony#26499 will not be part
of Symfony 3.4 regrettably.

@fabpot fabpot referenced this pull request May 7, 2018

Merged

Release v4.1.0-BETA1 #27181

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