Skip to content

Update testing.rst #6447

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

Closed
wants to merge 1 commit into from
Closed

Update testing.rst #6447

wants to merge 1 commit into from

Conversation

miguelvilata
Copy link
Contributor

Hello, I'm working with some test in a Symfony 2.3 application. Reading the docs, they say that "If your requests are not insulated, you can also access the Container and the Kernel", but I can access kernel and container even in an insulated $client doing this:

    $client = $this->createClient();
    $client->insulate(true);
    $crawler = $client->request('GET', '/');

    $container = $client->getContainer();
    $kernel = $client->getKernel();
    var_dump($kernel->getBundles());

Hello, I'm working with some test in a Symfony 2.3 application. Reading the docs, they say that "If your requests are not insulated, you can also access the Container and the Kernel", but I can access kernel and container even in an insulated $client doing this:

        $client = $this->createClient();
        $client->insulate(true);
        $crawler = $client->request('GET', '/');

        $container = $client->getContainer();
        $kernel = $client->getKernel();
        var_dump($kernel->getBundles());
@xabbuh
Copy link
Member

xabbuh commented Apr 9, 2016

Well, the thing is that the kernel and the container used in the insulated process is not the same that you get access to with getKernel()/getContainer() thus you cannot use these methods to check or access the tests process' state.

@miguelvilata
Copy link
Contributor Author

Ok, I understand.

Perhaps we can clarify this point. In this moment, the "if your request are not insulated, you can also access the Container and the Kernel" phrase, sounds to me as if I couldn't access the kernel/container from and insulated client. Possibly we can explain that the kernel/container retrieved in this context is different.

Thanks.

@xabbuh
Copy link
Member

xabbuh commented Apr 10, 2016

@miguelvilata Sounds like a good idea. Can you make that change?

@miguelvilata
Copy link
Contributor Author

Of course, I'll try. Give some time to make a proposal.

@xabbuh
Copy link
Member

xabbuh commented May 21, 2016

@miguelvilata Do you have some idea on how to make things more clear? :)

@miguelvilata
Copy link
Contributor Author

miguelvilata commented May 23, 2016

Sorry for the delay.

What do you think about replace
"If your requests are not insulated, you can also access the Container and the Kernel"
for
"You can also access the special Container and Kernel that are built for passing the test"

ping: @xabbuh

@miguelvilata
Copy link
Contributor Author

Can I do something more to improve this contribution?

@xabbuh
Copy link
Member

xabbuh commented Jun 28, 2016

Thinking about this again I would keep the existing sentence as is, but add something like "for insulated requests the returned instances are not the same that were used in the request" in parentheses after it. What do you think?

@weaverryan
Copy link
Member

There's also some duplication - the next section talks about getting the container and it also has a comment about insulation (https://github.com/miguelvilata/symfony-docs/blob/5dafbb105f9ad71afa336ce65acfbea2f9bf1f15/book/testing.rst#accessing-the-container).

I think we should:

  • Remove showing how to get the kernel/container here
  • In the next section, add a comment in the code (and remove the 2 sentences after it)
// will be the same container used in your test, unless you're using $client->insulate()
// or using real HTTP requests to test your app
$container = $client->getContainer();

@javiereguiluz
Copy link
Member

@miguelvilata thanks for proposing this improvement. As you know, we recently revamped the Symfony Docs. For that reason, this PR can no longer be merged. I've recreated your work in #6834 and added the suggestions made by Ryan. Thank you all for the discussion!

@xabbuh
Copy link
Member

xabbuh commented Aug 3, 2016

Thanks @miguelvilata for your work on this.

@xabbuh xabbuh closed this Aug 3, 2016
weaverryan added a commit that referenced this pull request Aug 20, 2016
…luz)

This PR was merged into the 2.7 branch.

Discussion
----------

Refactored how to get the container in a test

This finishes #6447.

Commits
-------

b2c0d38 Refactore how to get the container in a test
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