Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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
Mar 16, 2018

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas 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();
Copy link
Contributor

Choose a reason for hiding this comment

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

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

@jakzal
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Member Author

In my experience, this would be useful for any KernelTestCase

OK, what about the new patch?

@ogizanagi
Copy link
Contributor

Better :)

@nicolas-grekas nicolas-grekas force-pushed the test-container branch 4 times, most recently from 626b6ad to d5c7c60 Compare March 13, 2018 11:03
@nicolas-grekas
Copy link
Member Author

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
nicolas-grekas added a commit that referenced this pull request Mar 16, 2018
… 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 test-container branch March 16, 2018 09:52
@kniziol
Copy link

kniziol commented Mar 19, 2018

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

@nicolas-grekas
Copy link
Member Author

that's a new feature, so for 4.1

@umpirsky
Copy link
Contributor

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

@nicolas-grekas
Copy link
Member Author

@umpirski right.

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.

7 participants