Skip to content

[Client] Can't access the profiler in functional tests #20282

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
nplhse opened this issue Oct 23, 2016 · 4 comments
Closed

[Client] Can't access the profiler in functional tests #20282

nplhse opened this issue Oct 23, 2016 · 4 comments

Comments

@nplhse
Copy link

nplhse commented Oct 23, 2016

I'm currently setting up some functional tests with symfony 3.1.5 and keep on running into an issue when trying to evaluate if an email has been submitted successfully.

I've enabled the profiler in my config_test.yml like this:

framework:
    profiler:
        enabled: true
        collect: false

Within my test I request the Swiftmailer via the Profiler like this:

$this->client->enableProfiler();

// Note: The following function is my abstraction of the submission of the recover email form
$this->requestRecoveryMail($email); 

$mailCollector = $this->client->getProfile()->getCollector('swiftmailer');

But I keep on getting the Error: Call to a member function getCollector() on boolean error. I think that I've located the problem and found out that $this->client->getProfile() always returns false.

As far as I know this comes from line 85 in the Symfony Profiler where the value of the X-Debug-Token is always null.

I'm really not sure if this is an actual bug, or just my stupidity but during my research on this topic i found this Post on a very similar issue on stackoverflow. But in my case I wasn't even able to find the X-Debug-token header within the request.

(Note: The actual code of this test can be found here in this repository.)

@patrick-mcdougle
Copy link
Contributor

patrick-mcdougle commented Oct 24, 2016

I think your profiler is getting disabled because you're not collecting. See https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L383-L385. I think removing the collect: false line from your config might help.

@nplhse
Copy link
Author

nplhse commented Oct 24, 2016

Actually that helped, but I'm still having some trouble with this issue. Because as far as I understood the manual says that collect: falsejust implies that I need to trigger the execution of the Profiler manually via $client->enableProfiler(). Which is what I need, because I don`t want to profile every single request during the tests.

Also I've tried to figure out where this error actually came from and found out that the Profiler was actually executed the whole time and that the results always appear in the var/cache/test/profiler folder - including a correct X-Debug-Token header. But when the Profiler tries to load the Request via the loadProfileFromResponse() function it can't find the X-Debug-Tokenheader no more.

@nplhse
Copy link
Author

nplhse commented Nov 5, 2016

Finally I've figured out the source of error (and of cause it was my own fault):

In all the examples of sending emails in functional tests they always submit the email via a request and I'm doing this by submitting a form. And in this case I've just forgotten to set $client->followRedirects(false) prior to submitting to be able to access the correct Profiler data.

Therefore I'm closing this issue because it's not a bug - but a feature I misunderstood.

@javiereguiluz
Copy link
Member

@nplhse thanks to your comment I could fix a test that suffered the same problems. I've proposed to add some help in the Symfony Docs to prevent this error from happening to other developers: symfony/symfony-docs#7115 Thanks!

xabbuh added a commit to symfony/symfony-docs that referenced this issue Nov 28, 2016
…ls (javiereguiluz)

This PR was squashed before being merged into the 2.7 branch (closes #7115).

Discussion
----------

Better explain the most common problems when testing emails

Testing emails is simple but in the past I've suffered lots of problems related to this. In fact, a few minutes ago I fixed a long standing wrong test thanks to this comment about page redirections and collectors: symfony/symfony#20282 (comment)

I propose to create a new mini section to better explain the problems that you may face when testing emails.

Commits
-------

c2e0608 Better explain the most common problems when testing emails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants