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

Improve support for PHPUnit testing plugins in situ #11

Open
bobbingwide opened this issue Aug 22, 2016 · 2 comments
Open

Improve support for PHPUnit testing plugins in situ #11

bobbingwide opened this issue Aug 22, 2016 · 2 comments
Assignees

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Aug 22, 2016

The tests in wordpress-develop-tests assume that everything has been reset to zero.
It's a risky business running attempting to run these tests in a live database.
If you want to run your PHPUnit tests in situ, then you have to develop them in such a way that the system state can be restored to as close as it was when you started.

Rather than extending WP_UnitTestCase, which includes methods such as reset_post_types() which aren't particularly useful for plugin tests, we should develop a class called BW_UnitTestCase which plugins (and themes) will extend.

This class should contain helper methods to reduce the amount of code needed in the tests.
For instance, to test allow-reinstalls we need to confirm the following.

  • the plugin is activated
  • there isn't another routine that might adversely affect the results of the tests
  • and, that it does what it says it does.

For other plugins that need to create, update and delete data we need methods to reset the system to the required initial state. And a method to define this state in the first place.

The class will be loaded by oik-batch's bootstrap routine and will perform the reset logic if so required.

This issue requires more work than #9, which is one reason why it's a separate issue.

@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 30, 2016

With WordPress 4.7 code, running tests in situ is far worse than risky.

Without looking at the changes to the WordPress unit test code, I upgraded to 4.7 and ran some tests.
Before I realised something was very wrong I had managed to empty two of my most important development environments.

Whereas the call to _delete_all_posts() was only in bootstrap.php, which we didn't call when running in situ, the tearDownAfterClass() method of WP_UnitTestCase now calls _delete_all_data() and commits the transaction.

And this is the exact opposite of what we want, which is:

  • don't delete any existing data
  • and roll back any changes we might have made.

I'm sure I read a solution to this back in August, by the clever people at deliciousbrains.

@bobbingwide
Copy link
Owner Author

Since this is still open... it would be nice if we could actually run the tests in wordpress-develop-tests just like any other plugin, using in-situ testing method. If this is not possible, then we should document what is achievable. We’re trying to support running core tests whilst avoiding the possibility of accidentally destroying a DB simply because you ran PHPUnit from the wrong folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant