Skip to content

Commit 2681f69

Browse files
committed
try to pass WP path in CI correctly
1 parent b5b7565 commit 2681f69

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

.github/workflows/phpunit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ jobs:
102102
shell: bash
103103
run: tests/bin/install-wp-tests.sh wordpress_tests root '' 127.0.0.1:3306 ${{ matrix.wp_version }}
104104

105+
- name: Symlink plugin into WordPress installation
106+
run: ln -s "$GITHUB_WORKSPACE" /tmp/wordpress/wp-content/plugins/progress-planner
107+
105108
- name: Run unit tests - single site
106109
run: composer test
107110

tests/phpunit/test-class-wp-cli-task-command.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function setUp(): void {
4343
* @return array{output: string, code: int}
4444
*/
4545
private function run_wp_cli( $command ) {
46-
// Calculate WordPress root from plugin directory (wp-content/plugins/progress-planner).
47-
$wp_path = \dirname( PROGRESS_PLANNER_DIR, 3 );
46+
$wp_path = $this->get_wp_path();
4847

4948
$full_command = \sprintf( 'cd %s && wp %s 2>&1', \escapeshellarg( $wp_path ), $command );
5049

@@ -56,6 +55,31 @@ private function run_wp_cli( $command ) {
5655
];
5756
}
5857

58+
/**
59+
* Get the WordPress installation path.
60+
*
61+
* Handles both local environments (plugin in wp-content/plugins/) and CI
62+
* environments (plugin symlinked into WP installation).
63+
*
64+
* @return string Path to WordPress installation.
65+
*/
66+
private function get_wp_path() {
67+
// First, try the standard plugin location (3 directories up from plugin root).
68+
$standard_path = \dirname( PROGRESS_PLANNER_DIR, 3 );
69+
if ( \file_exists( $standard_path . '/wp-config.php' ) || \file_exists( $standard_path . '/wp-load.php' ) ) {
70+
return $standard_path;
71+
}
72+
73+
// In CI, WordPress is installed to /tmp/wordpress and the plugin is symlinked there.
74+
$ci_wp_path = '/tmp/wordpress';
75+
if ( \file_exists( $ci_wp_path . '/wp-load.php' ) ) {
76+
return $ci_wp_path;
77+
}
78+
79+
// Fallback to standard path.
80+
return $standard_path;
81+
}
82+
5983
/**
6084
* Clean up test task after tests.
6185
*

0 commit comments

Comments
 (0)