Skip to content

Commit 121e557

Browse files
committed
Correct plugin file in bootstrap when scaffolding plugin test
1 parent 40b98b5 commit 121e557

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Scaffold_Command.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,29 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
869869
$wp_versions_to_test[] = 'latest';
870870
$wp_versions_to_test[] = 'trunk';
871871

872+
$main_file = '';
873+
874+
if ( 'plugin' === $type ) {
875+
$all_plugins = get_plugins();
876+
877+
if ( ! empty( $all_plugins ) ) {
878+
$filtered = array_filter(
879+
array_keys( $all_plugins ),
880+
static function ( $item ) use ( $slug ) {
881+
return ( false !== strpos( $item, "{$slug}/" ) );
882+
}
883+
);
884+
885+
if ( ! empty( $filtered ) ) {
886+
$main_file = basename( reset( $filtered ) );
887+
}
888+
}
889+
}
890+
872891
$template_data = [
873-
"{$type}_slug" => $slug,
874-
"{$type}_package" => $package,
892+
"{$type}_slug" => $slug,
893+
"{$type}_package" => $package,
894+
"{$type}_main_file" => $main_file,
875895
];
876896

877897
$force = Utils\get_flag_value( $assoc_args, 'force' );

templates/plugin-bootstrap.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require_once "{$_tests_dir}/includes/functions.php";
2929
* Manually load the plugin being tested.
3030
*/
3131
function _manually_load_plugin() {
32-
require dirname( dirname( __FILE__ ) ) . '/{{plugin_slug}}.php';
32+
require dirname( dirname( __FILE__ ) ) . '/{{plugin_main_file}}';
3333
}
3434

3535
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

0 commit comments

Comments
 (0)