-
Notifications
You must be signed in to change notification settings - Fork 131
Clear out and remove /tests
directory
#1804
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
Changes from 16 commits
1eeeb61
2d62b91
3a724c8
8679cba
e3f3b3e
ca4f56a
f829057
2fa9d60
7098a50
fcaa10e
9f563d5
70de425
2a647be
6df3ca2
b002bff
a4b05d2
6421043
c29d670
6d26270
a985976
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,3 +7,6 @@ | |||||
|
||||||
// Require the suggested plugin. | ||||||
require_once __DIR__ . '/../../optimization-detective/load.php'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other places where
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this manual loading of Optimization Detective is done for Embed Optimizer but not for Image Prioritizer because the latter has Optimization Detective as an explicit dependency, whereas the former it is a recommended dependency. The test bootstrap logic automatically loads any explicit dependencies. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are the relevant instances (updated):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, the lines in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
// Load the test helpers. | ||||||
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
/** | ||
* Test Bootstrap for Image Prioritizer. | ||
* | ||
* @package image-prioritizer | ||
*/ | ||
|
||
// Load the test helpers. | ||
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
/** | ||
* Test Bootstrap for Optimiztaion Detective. | ||
* | ||
* @package optimization-detective | ||
*/ | ||
|
||
// Load the test helpers. | ||
require_once TESTS_REPO_ROOT_DIR . '/plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php'; |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,18 +5,18 @@ | |||||||||||||
* @package performance-lab | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
define( 'TESTS_PLUGIN_DIR', dirname( __DIR__ ) ); | ||||||||||||||
define( 'TESTS_REPO_ROOT_DIR', dirname( __DIR__, 2 ) ); | ||||||||||||||
|
||||||||||||||
// Determine correct location for plugins directory to use. | ||||||||||||||
if ( false !== getenv( 'WP_PLUGIN_DIR' ) ) { | ||||||||||||||
define( 'WP_PLUGIN_DIR', getenv( 'WP_PLUGIN_DIR' ) ); | ||||||||||||||
} else { | ||||||||||||||
define( 'WP_PLUGIN_DIR', dirname( TESTS_PLUGIN_DIR ) ); | ||||||||||||||
define( 'WP_PLUGIN_DIR', dirname( TESTS_REPO_ROOT_DIR ) ); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Load Composer dependencies if applicable. | ||||||||||||||
if ( file_exists( TESTS_PLUGIN_DIR . '/vendor/autoload.php' ) ) { | ||||||||||||||
require_once TESTS_PLUGIN_DIR . '/vendor/autoload.php'; | ||||||||||||||
if ( file_exists( TESTS_REPO_ROOT_DIR . '/vendor/autoload.php' ) ) { | ||||||||||||||
require_once TESTS_REPO_ROOT_DIR . '/vendor/autoload.php'; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Detect where to load the WordPress tests environment from. | ||||||||||||||
|
@@ -26,8 +26,8 @@ | |||||||||||||
$_test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; | ||||||||||||||
} elseif ( false !== getenv( 'WP_PHPUNIT__DIR' ) ) { | ||||||||||||||
$_test_root = getenv( 'WP_PHPUNIT__DIR' ); | ||||||||||||||
} elseif ( file_exists( TESTS_PLUGIN_DIR . '/../../../../tests/phpunit/includes/functions.php' ) ) { | ||||||||||||||
$_test_root = TESTS_PLUGIN_DIR . '/../../../../tests/phpunit'; | ||||||||||||||
} elseif ( file_exists( TESTS_REPO_ROOT_DIR . '/../../../../tests/phpunit/includes/functions.php' ) ) { | ||||||||||||||
$_test_root = TESTS_REPO_ROOT_DIR . '/../../../../tests/phpunit'; | ||||||||||||||
} else { // Fallback. | ||||||||||||||
$_test_root = '/tmp/wordpress-tests-lib'; | ||||||||||||||
} | ||||||||||||||
|
@@ -47,7 +47,7 @@ | |||||||||||||
if ( | ||||||||||||||
'--testsuite' === $arg && | ||||||||||||||
isset( $_SERVER['argv'][ $index + 1 ] ) && | ||||||||||||||
file_exists( TESTS_PLUGIN_DIR . '/plugins/' . $_SERVER['argv'][ $index + 1 ] ) | ||||||||||||||
file_exists( TESTS_REPO_ROOT_DIR . '/plugins/' . $_SERVER['argv'][ $index + 1 ] ) | ||||||||||||||
) { | ||||||||||||||
$plugin_name = $_SERVER['argv'][ $index + 1 ]; | ||||||||||||||
} | ||||||||||||||
|
@@ -58,13 +58,15 @@ | |||||||||||||
$plugin_name = 'performance-lab'; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
define( 'TESTS_PLUGIN_DIR', TESTS_REPO_ROOT_DIR . "/plugins/$plugin_name" ); | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Load plugin bootstrap and any dependencies. | ||||||||||||||
* | ||||||||||||||
* @param string $plugin_name Plugin slug to load. | ||||||||||||||
*/ | ||||||||||||||
$load_plugin = static function ( string $plugin_name ) use ( &$load_plugin ): void { | ||||||||||||||
$plugin_test_path = TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name; | ||||||||||||||
$plugin_test_path = TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above:
Suggested change
Alternatively, we could get rid of this variable entirely, since it's only referencing the constant as-is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, we can't do this. This function also needs to load plugin dependencies. I thought this at first myself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which function do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure when the It doesn't make sense to me to use this approach, especially given the complexity you're describing. There is a special global to control which plugins should be active. For example: $GLOBALS['wp_tests_options'] = array(
'active_plugins' => array( basename( TESTS_PLUGIN_DIR ) . '/load.php' ),
); Can we not use that approach? If the problem is that we're loading plugins from a custom subdirectory, I wonder whether we could maybe override Overall, it certainly makes more sense to me to tie into WordPress's built-in plugin loading mechanism instead of trying to manually require files here (which BTW There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current approach seems to have been working well, but what you propose seems good. Maybe do it another PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, that would be a separate enhancement. |
||||||||||||||
if ( file_exists( $plugin_test_path . '/' . $plugin_name . '.php' ) ) { | ||||||||||||||
$plugin_file = $plugin_test_path . '/' . $plugin_name . '.php'; | ||||||||||||||
} elseif ( file_exists( $plugin_test_path . '/load.php' ) ) { | ||||||||||||||
|
@@ -102,9 +104,9 @@ static function () use ( $load_plugin, $plugin_name ): void { | |||||||||||||
tests_add_filter( | ||||||||||||||
'plugins_loaded', | ||||||||||||||
static function () use ( $plugin_name ): void { | ||||||||||||||
require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php'; | ||||||||||||||
require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php'; | ||||||||||||||
require_once TESTS_PLUGIN_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php'; | ||||||||||||||
require_once TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name . '/includes/admin/load.php'; | ||||||||||||||
require_once TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name . '/includes/admin/server-timing.php'; | ||||||||||||||
require_once TESTS_REPO_ROOT_DIR . '/plugins/' . $plugin_name . '/includes/admin/plugins.php'; | ||||||||||||||
Comment on lines
+107
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we can't do this. See #1804 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? These files don't require any dependencies. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plugin dependencies (i.e. Image Prioritizer depending on Optimization Detective) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand. Specific files are being loaded here that only matter for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right. At least these should be wrapped in a condition so they only are loaded if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, but that already it the case. This logic is wrapped in: if ( 'performance-lab' === $plugin_name ) { |
||||||||||||||
}, | ||||||||||||||
1 | ||||||||||||||
); | ||||||||||||||
|
@@ -127,8 +129,5 @@ static function ( bool $passthrough ): bool { | |||||||||||||
} | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
// Require helper classes. | ||||||||||||||
require_once __DIR__ . '/class-optimization-detective-test-helpers.php'; | ||||||||||||||
|
||||||||||||||
// Start up the WP testing environment. | ||||||||||||||
require $_test_root . '/includes/bootstrap.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding this specific change, should this also be reverted to the original
__DIR__
pattern?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to consistently use
TESTS_PLUGIN_DIR
in those cases. This way all path strings after the constant are relative to the same root.