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

Env: No way to skip setting WP_ENVIRONMENT_TYPE #41083

Closed
dd32 opened this issue May 16, 2022 · 0 comments · Fixed by #41084
Closed

Env: No way to skip setting WP_ENVIRONMENT_TYPE #41083

dd32 opened this issue May 16, 2022 · 0 comments · Fixed by #41084
Assignees
Labels
[Tool] Env /packages/env

Comments

@dd32
Copy link
Member

dd32 commented May 16, 2022

Description

When using wp-env, it's not possible to NOT set the WP_ENVIRONMENT_TYPE constant at all.

This is problematic when wp-env is being used as part of unit testing, which may require changing the environment type dynamically.

One can arbitrarily set the constant value through a config mapping, but one cannot remove it.

This is problematic for unit testing, as the value of the constant (valid or not) is used as-is within WordPress (See wp_get_environment_type() - which is another thing to discuss)

Step-by-step reproduction instructions

  1. Create a .wp-env.json file similar to the below
  2. See that the Constant is still defined (see below)
{
	"config": {
		"WP_ENVIRONMENT_TYPE": false
	}
}

(Note, I've also tried '""' and null)

Still defined:

$ grep TYPE `npm run wp-env install-path 2>/dev/null | tail -n1`/tests-WordPress/*config*.php
/Users/user/.wp-env/9ddecbd0abdc3019693b13c896f02591/tests-WordPress/phpunit-wp-config.php:define( 'WP_ENVIRONMENT_TYPE', false );
/Users/user/.wp-env/9ddecbd0abdc3019693b13c896f02591/tests-WordPress/wp-config.php:define( 'WP_ENVIRONMENT_TYPE', false );

Screenshots, screen recording, code snippet

No response

Environment info

WP-env version:
@wordpress/[email protected]

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

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@dd32 dd32 added the [Tool] Env /packages/env label May 16, 2022
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label May 16, 2022
dd32 added a commit to dd32/gutenberg that referenced this issue May 24, 2022
noahtallen pushed a commit that referenced this issue May 24, 2022
… null. (#41084)

* Env: Allow skipping setting a configuration value by specifying it as null. Fixes #41083

* Env: Add a changelog entry for skipping a constant.

* Env: Document how to override wp-config defaults, and how to prevent them being defined entirely.
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] Env /packages/env
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants