Skip to content
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

Using wp_mocks together with WordPress core Unit tests #49

Open
sudar opened this issue Dec 30, 2015 · 4 comments
Open

Using wp_mocks together with WordPress core Unit tests #49

sudar opened this issue Dec 30, 2015 · 4 comments
Assignees
Labels
Documentation Updates to documentation Help Wanted

Comments

@sudar
Copy link
Contributor

sudar commented Dec 30, 2015

I know that wp_mock and WordPress core Unit tests work differently and it may not even be possible to have them run together.

I use both and like both. But there are certain tests for which I would prefer wp_mock and certain tests for which I would prefer WordPress core Unit tests. But unfortunately right now there is no way to configure both of them for a single plugin. You have to pick one and stick with it even if you can group all the 'mock' tests using a separate testsuite or phpunit group and invoke the separately from phpunit.

What I am suggesting is to have a way to setup both of them together for a plugin and invoke the appropriate framework and their tests using either phpunit's group or testsuite feature.

I know that there was some recent discussion about it and I am interested in knowing everyone's thoughts on it.

@blobaugh
Copy link

Seconded! Any implementation plans on this?

@ericmann ericmann self-assigned this May 27, 2017
@ericmann ericmann added the Documentation Updates to documentation label May 27, 2017
@davetbo
Copy link

davetbo commented Jun 13, 2017

If this means that I can use \WP_Mock with the unit testing scaffold that is set up by the wp-cli command line tools, then I'm interested as well!

@ssnepenthe
Copy link

This would be amazing but how would you even approach it?

If memory serves, once WordPress has been loaded by the core test suite, WP_Mock cannot mock core functions because they will have already been defined.

I looked into this a while back (albeit briefly) and the best I could come up with was to configure tests to run in separate processes and disable the preserve global state setting.

That effectively means you have to reload the bootstrap for every single test, however, which is far from ideal.

For now I have settled on configuring two test suites when I want to use both - each gets their own bootstrap file and I just have to be explicit about which I want to run when I call PHPUnit.

It's not pretty, but it does the trick...

@ericmann
Copy link
Collaborator

ericmann commented Sep 7, 2017

For now I have settled on configuring two test suites when I want to use both - each gets their own bootstrap file and I just have to be explicit about which I want to run when I call PHPUnit.

That's the way to make it work, unfortunately. The alternative is to run all tests using process isolation, but that causes some problems with the core test suite (it introduces a few race conditions with the database).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Updates to documentation Help Wanted
Projects
None yet
Development

No branches or pull requests

7 participants