Skip to content

Commit

Permalink
Allow for non-symlink installs within the monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj committed Jan 14, 2025
1 parent d9f6f06 commit d1a3fa1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions projects/packages/test-environment/src/class-test-environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ class Test_Environment {
*/
public static function init() {
if ( ! defined( 'WORDBLESS_RUNNING' ) ) {
// Look for wordbless in tools/php-test-env first
// Try the simple path first (works for symlinked/development case)
$test_env_vendor = dirname( __DIR__, 4 ) . '/tools/php-test-env/vendor/autoload.php';
if ( ! file_exists( $test_env_vendor ) ) {
// If simple path fails, search for monorepo root
$dir = __DIR__;
$prev_dir = null;
while ( $dir !== $prev_dir ) {
if ( file_exists( $dir . '/tools/php-test-env' ) ) {
break;
}
$prev_dir = $dir;
$dir = dirname( $dir );
}

if ( ! file_exists( $dir . '/tools/php-test-env' ) ) {
throw new \RuntimeException( 'Could not locate monorepo root directory' );
}

$test_env_vendor = $dir . '/tools/php-test-env/vendor/autoload.php';
}

if ( file_exists( $test_env_vendor ) ) {
require_once $test_env_vendor;
} else {
// Fallback to local vendor if test-env isn't available
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
}

try {
Expand Down

0 comments on commit d1a3fa1

Please sign in to comment.