Skip to content

Commit b457650

Browse files
committed
Resolve Symfony Finder in make-phar.php at runtime
`utils/scope-dependencies.php` prefixes symfony/finder along with the rest of the Composer tree, but `utils/make-phar.php` builds the Phar with that same Finder. Once prefixing has run, `Symfony\Component\Finder\Finder` no longer exists and the build dies before writing anything. Resolve the class name at runtime instead, so the build works whether or not the dependencies have been prefixed yet. Also drop `@require-mysql` from the isolation scenarios: they only need a WordPress installation, which the Behat suite can provide on SQLite too. Refs wp-cli/wp-cli#5920 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RHtjyXkZh8X16sBgmidSQi
1 parent 66464aa commit b457650

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎features/dependency-isolation.feature‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Feature: Bundled dependencies do not conflict with the site's own
1111
#
1212
# See https://github.com/wp-cli/wp-cli/issues/5920
1313

14-
@require-mysql
1514
Scenario: A site providing its own psr/log is not broken by the bundled one
1615
Given a WP installation
1716
# Stands in for a site that ships psr/log v3 through its own vendor
@@ -55,7 +54,6 @@ Feature: Bundled dependencies do not conflict with the site's own
5554
"""
5655
And the return code should be 0
5756

58-
@require-mysql
5957
Scenario: A site providing its own Symfony Console is not broken by the bundled one
6058
Given a WP installation
6159
And a wp-content/mu-plugins/site-console.php file:

‎utils/make-phar.php‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
require WP_CLI_VENDOR_DIR . '/autoload.php';
1919
require WP_CLI_ROOT . '/php/utils.php';
2020

21-
use Symfony\Component\Finder\Finder;
2221
use WP_CLI\Utils;
2322
use WP_CLI\Configurator;
2423

@@ -190,7 +189,21 @@ function get_composer_versions( $current_version ) {
190189
$phar->startBuffering();
191190

192191
// PHP files
193-
$finder = new Finder();
192+
/*
193+
* `utils/scope-dependencies.php` prefixes symfony/finder along with the rest
194+
* of the Composer tree, so the class this build script itself relies on moves
195+
* depending on whether prefixing has already run.
196+
*/
197+
$finder_class = class_exists( 'Symfony\\Component\\Finder\\Finder' )
198+
? 'Symfony\\Component\\Finder\\Finder'
199+
: 'WP_CLI\\Vendor\\Symfony\\Component\\Finder\\Finder';
200+
201+
if ( ! class_exists( $finder_class ) ) {
202+
fwrite( STDERR, 'Missing Symfony Finder; run `composer install` first.' . PHP_EOL );
203+
exit( 1 );
204+
}
205+
206+
$finder = new $finder_class();
194207
$finder
195208
->files()
196209
->ignoreVCS( true )
@@ -265,7 +278,7 @@ function get_composer_versions( $current_version ) {
265278
}
266279

267280
// other files
268-
$finder = new Finder();
281+
$finder = new $finder_class();
269282
$finder
270283
->files()
271284
->ignoreVCS( true )
@@ -280,7 +293,7 @@ function get_composer_versions( $current_version ) {
280293
if ( 'cli' !== BUILD ) {
281294
// Include base project files, because the autoloader will load them
282295
if ( WP_CLI_BASE_PATH !== WP_CLI_BUNDLE_ROOT && is_dir( WP_CLI_BASE_PATH . '/src' ) ) {
283-
$finder = new Finder();
296+
$finder = new $finder_class();
284297
$finder
285298
->files()
286299
->ignoreVCS( true )

0 commit comments

Comments
 (0)