Skip to content

Unexpected PHP behavior #10223

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 6 commits into from
Closed

Unexpected PHP behavior #10223

wants to merge 6 commits into from

Conversation

sylfabre
Copy link
Contributor

Following up on symfony/symfony#28259

class namespace when the annotated test is run. Because of a PHP unexpected
behavior (see https://bugs.php.net/bug.php?id=64346), a test may pass when
run alone but fail when run in a tests suite if the tested class is used
before these time and dns functions are defined. Configuring the mocked
Copy link
Member

Choose a reason for hiding this comment

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

About this:

Configuring the mocked namespaces in the phpunit.xml file may solve this issue too.

Could you please explain this in more detail? What should we add in the phpunit.xml file? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javiereguiluz I've added the example provided by nicolas-grekas on symfony/symfony#28259

Do you think it's enough?

@nicolas-grekas
Copy link
Member

Thanks for the PR. I don't think we should blame PHP at all here, so let's forget about mentioning any bug report. What about:

Under the hood, a PHPUnit listener injects the mocked functions in the tested
classes' namespace. In order to work as expected, the listener has to run before
the tested class ever runs. By default, the mocked functions are created when the
annotation are found and the corresponding tests are run. Depending on how your
tests are constructed, this might be too late. In this case, you will need to declare
the namespaces of the tested classes in your phpunit.xml.dist:

  • provide an inline example doing so (no link to the source)

@sylfabre
Copy link
Contributor Author

@nicolas-grekas done

Copy link
Contributor

@ndench ndench left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks!

tests are constructed, this might be too late. In this case, you will need to declare
the namespaces of the tested classes in your phpunit.xml.dist

````
Copy link
Contributor

Choose a reason for hiding this comment

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

.. code-block:: xml should probably be used here instead of 4 backticks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@xabbuh xabbuh added this to the 3.4 milestone Nov 30, 2018
@xabbuh
Copy link
Member

xabbuh commented Nov 30, 2018

Thank you @sylfabre.

xabbuh added a commit that referenced this pull request Nov 30, 2018
This PR was submitted for the 4.1 branch but it was squashed and merged into the 3.4 branch instead (closes #10223).

Discussion
----------

Unexpected PHP behavior

Following up on symfony/symfony#28259

Commits
-------

a320038 Unexpected PHP behavior
@xabbuh xabbuh closed this Nov 30, 2018
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