Skip to content

Commit f9a0de9

Browse files
committed
Add feature test for update scaffolded plugin test bootstrap
1 parent 121e557 commit f9a0de9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

features/scaffold-plugin-tests.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,28 @@ Feature: Scaffold plugin unit tests
284284
"""
285285
bootstrap.php
286286
"""
287+
288+
Scenario: Scaffold plugin tests with custom main file
289+
Given a WP install
290+
And a wp-content/plugins/foo/bar.php file:
291+
"""
292+
<?php
293+
/**
294+
* Plugin Name: Foo
295+
* Plugin URI: https://example.com
296+
* Description: Foo desctiption
297+
* Author: John Doe
298+
* Author URI: https://example.com
299+
* Text Domain: foo
300+
* Domain Path: /languages
301+
* Version: 0.1.0
302+
*
303+
* @package Foo
304+
*/
305+
"""
306+
307+
When I run `wp scaffold plugin-tests foo`
308+
Then the wp-content/plugins/foo/tests/bootstrap.php file should contain:
309+
"""
310+
require dirname( dirname( __FILE__ ) ) . '/bar.php';
311+
"""

src/Scaffold_Command.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,13 @@ 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 = '';
872+
$main_file = "{$slug}.php";
873873

874874
if ( 'plugin' === $type ) {
875+
if ( ! function_exists( 'get_plugins' ) ) {
876+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
877+
}
878+
875879
$all_plugins = get_plugins();
876880

877881
if ( ! empty( $all_plugins ) ) {

0 commit comments

Comments
 (0)