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

Integration tests aren't isolated #36

Open
jkudish opened this issue May 4, 2024 · 4 comments
Open

Integration tests aren't isolated #36

jkudish opened this issue May 4, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@jkudish
Copy link

jkudish commented May 4, 2024

Describe your bug

When running consecutive integration tests, much of the WordPress lifecycle seem to persist between the tests. I would expect each request to run independently.

Steps to Reproduce

Here's two example tests that demonstrate the issue:

test('action demo 1', function(){
	add_action('wp', function(){
		fputs(STDOUT, "wp action fired");
	});

	wp();
});

test('action demo 2', function(){
	// this will still have the action from the previous test
	// and emit the dump
	wp();
});

Expected behavior

The action was defined in the first test, and I would expect it to only fire in that test.

Screenshots, screen recording, code snippet

No response

Environment info

PHP 8.1
WordPress 6.4.2

Please confirm that you have searched existing issues in this repo.

Yes

@jkudish jkudish added the bug Something isn't working label May 4, 2024
@dingo-d
Copy link
Owner

dingo-d commented May 4, 2024

Pest v1 doesn't have process isolation, like regular phpunit does, so I kinda think that would be the 'culprit' here.

@jkudish
Copy link
Author

jkudish commented May 4, 2024

Pest v1 doesn't have process isolation, like regular phpunit does, so I kinda think that would be the 'culprit' here.

Gotcha, makes sense - any chance of working towards an upgrade to pest v2?

@dingo-d
Copy link
Owner

dingo-d commented May 4, 2024

Until WP core updates their unit test suites to be compatible with PHPUnit 10 there's not much I can do.

I've opened up a trac ticket about it, but that one will probably be closed in favor of one with much more detailed steps necessary to move it forward.

@jkudish
Copy link
Author

jkudish commented May 7, 2024

Hey @dingo-d nice thanks for the update. I'll follow along and hopefully we'll get PHPUnit 10 compatibility in WP soon 😄

In the mean time, in case anyone else encounters this, note that I worked around my specific issue by doing something like this with my tests (this is a simplified example).

beforeEach(function (){
	global $wp_actions;
	unset($wp_actions['my_action']);
});

test('my action fires', function (){
	do_action('my_action');
	expect(did_action('my_action'))->toBeTrue();
});

test('my action does not fire', function (){
	expect(did_action('my_action'))->toBeFalse();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants