Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Retrieve plugin file to load from environment (#307)
Browse files Browse the repository at this point in the history
Props @pierlon.
  • Loading branch information
pierlon authored and kasparsd committed Oct 22, 2019
1 parent a40a292 commit e0205d7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sample-config/phpunit-plugin-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
}

global $_plugin_file;
$_plugin_file = getenv( 'PLUGIN_FILE' );

$_tests_dir = getenv( 'WP_TESTS_DIR' );

Expand All @@ -41,17 +42,21 @@
}
require_once $_tests_dir . '/includes/functions.php';

$_plugin_dir = getcwd();
foreach ( glob( $_plugin_dir . '/*.php' ) as $_plugin_file_candidate ) {
// @codingStandardsIgnoreStart
$_plugin_file_src = file_get_contents( $_plugin_file_candidate );
// @codingStandardsIgnoreEnd
if ( preg_match( '/Plugin\s*Name\s*:/', $_plugin_file_src ) ) {
$_plugin_file = $_plugin_file_candidate;
break;
// Fallback to searching for plugin file if its not supplied.
if ( empty( $_plugin_file ) ) {
$_plugin_dir = getcwd();
foreach ( glob( $_plugin_dir . '/*.php' ) as $_plugin_file_candidate ) {
// @codingStandardsIgnoreStart
$_plugin_file_src = file_get_contents( $_plugin_file_candidate );
// @codingStandardsIgnoreEnd
if ( preg_match( '/Plugin\s*Name\s*:/', $_plugin_file_src ) ) {
$_plugin_file = $_plugin_file_candidate;
break;
}
}
}
if ( ! isset( $_plugin_file ) ) {

if ( ! file_exists( $_plugin_file ) ) {
trigger_error( 'Unable to locate a file containing a plugin metadata block.', E_USER_ERROR );
}
unset( $_plugin_dir, $_plugin_file_candidate, $_plugin_file_src );
Expand Down

0 comments on commit e0205d7

Please sign in to comment.