Skip to content

Commit

Permalink
Correct plugin file in bootstrap when scaffolding plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Apr 26, 2024
1 parent 40b98b5 commit 121e557
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/Scaffold_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,29 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
$wp_versions_to_test[] = 'latest';
$wp_versions_to_test[] = 'trunk';

$main_file = '';

if ( 'plugin' === $type ) {
$all_plugins = get_plugins();

if ( ! empty( $all_plugins ) ) {
$filtered = array_filter(
array_keys( $all_plugins ),
static function ( $item ) use ( $slug ) {
return ( false !== strpos( $item, "{$slug}/" ) );
}
);

if ( ! empty( $filtered ) ) {
$main_file = basename( reset( $filtered ) );
}
}
}

$template_data = [
"{$type}_slug" => $slug,
"{$type}_package" => $package,
"{$type}_slug" => $slug,
"{$type}_package" => $package,
"{$type}_main_file" => $main_file,
];

$force = Utils\get_flag_value( $assoc_args, 'force' );
Expand Down
2 changes: 1 addition & 1 deletion templates/plugin-bootstrap.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require_once "{$_tests_dir}/includes/functions.php";
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/{{plugin_slug}}.php';
require dirname( dirname( __FILE__ ) ) . '/{{plugin_main_file}}';
}

tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
Expand Down

0 comments on commit 121e557

Please sign in to comment.