WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 14 months ago

Last modified 7 months ago

#39734 closed enhancement (fixed)

Add ability to define file path of "wp-tests-config.php"

Reported by: clarinetlord Owned by: johnbillion
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch has-dev-note
Focuses: Cc:

Description

There are several reasons why someone might want to define the location of wp-tests-config.php themselves instead of tests/phpunit/includes/bootstrap.php only checking in two distinct locations. Personally, I would like to define the location outside the project root so I can check the file into my project repositories and keep the develop core as a clean dependency directory. I suggest that the bootstrap check for a constant in the phpunit.xml.dist file, since this file can be copied and modified outside the project to be used by phpunit.

Attachments (3)

Added_optional_constant_to_define_wp_tests_config_php_path.patch (742 bytes) - added by clarinetlord 2 years ago.
Add_optional_constant_to_preset_tests_config_file.patch (2.4 KB) - added by clarinetlord 2 years ago.
39734.patch (1.4 KB) - added by johnbillion 14 months ago.

Download all attachments as: .zip

Change History (16)

#1 @johnbillion
2 years ago

  • Keywords needs-patch good-first-bug added
  • Version trunk deleted

Thanks for the ticket, @clarinetlord. This is a sensible request. It would be nice if it could work in the same way as the bootstrap attribute on the phpunit element in phpunit.xml, but I'm not sure if that's possible. Otherwise, a constant makes sense.

#2 @johnbillion
2 years ago

  • Keywords good-first-bug removed

#3 @clarinetlord
2 years ago

  • Keywords has-patch added; needs-patch removed

Thanks @johnbillion, I think a PHP constant is the best option I can see here. There may be a way to add custom XML attributes to the phpunit.xml file, but it's probably more trouble than it's worth. As a constant, there's also the option to define it other places besides phpunit.xml. Here's a simple patch to bootstrap.php to add this feature.

#4 @johnbillion
2 years ago

Thanks for the patch. I think the WP_CONFIG_FILE_PATH constant should take precedence over the default location of wp-tests-config.php in case someone wants to do a particularly crazy setup where wp-tests-config.php is in place but they want to override it with WP_CONFIG_FILE_PATH.

#5 @clarinetlord
2 years ago

That's a good idea. Here's a modified patch that wraps the entire file location check with a check for the existence of that constant first. It seemed cleanest to also set the constant in the default procedure, so it's always defined no matter what. I replaced future variable references with the constant.

#6 follow-up: @johnbillion
2 years ago

  • Milestone changed from Awaiting Review to Future Release
  • Owner set to johnbillion
  • Status changed from new to reviewing

#7 in reply to: ↑ 6 @clarinetlord
17 months ago

Replying to johnbillion:

Hey @johnbillion, any chance we could get this into 5.0?

#8 @kasparsd
14 months ago

It would be great to get this in for 5.0 especially since #43558 was already merged.

PHPUnit also supports defining environment variables but constants appear to be the WordPress way of doing it.

#9 @johnbillion
14 months ago

  • Milestone changed from Future Release to 5.0

@johnbillion
14 months ago

#10 @johnbillion
14 months ago

39734.patch simplifies the patch a little and changes the constant name to WP_TESTS_CONFIG_FILE_PATH.

#11 @johnbillion
14 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 43369:

Build/Test Tools: Introduce support for a WP_TESTS_CONFIG_FILE_PATH constant to override the test suite config file location.

This can be used in phpunit.xml:

<php>
	<const name="WP_TESTS_CONFIG_FILE_PATH" value="/path/to/wp-tests-config.php" />
</php>

Props clarinetlord

Fixes #39734

#12 @jorbin
11 months ago

  • Milestone changed from 5.0 to 5.1
Note: See TracTickets for help on using tickets.