Skip to content

Add PHP binary discovery and selection for project creation - #1306

Draft
Soner (shyim) wants to merge 1 commit into
mainfrom
claude/shopware-cli-1303-xpjyu4
Draft

Add PHP binary discovery and selection for project creation#1306
Soner (shyim) wants to merge 1 commit into
mainfrom
claude/shopware-cli-1303-xpjyu4

Conversation

@shyim

Copy link
Copy Markdown
Member

What changed?

Added comprehensive PHP executable discovery and selection capabilities to the project creation workflow:

  1. New PHP discovery system (internal/system/php_discovery.go):

    • DiscoverPHPInstallations() finds all usable PHP executables on the machine from multiple sources: PHP_BINARY environment variable, PATH (including versioned names like php8.3), and platform-specific locations (Homebrew on macOS, system packages on Linux, XAMPP/Laragon on Windows)
    • Candidates are canonicalized, de-duplicated, and verified by executing them to obtain their version
    • Results are sorted with PHP_BINARY first, then by version (newest first)
    • Helper functions filter by version constraint, find by source, and select preferred installation
  2. Project creation PHP selection (cmd/project/project_create_php.go):

    • New --php-binary flag to explicitly select a PHP executable for project creation
    • Interactive selection prompt when multiple compatible PHP versions are available
    • Non-interactive fallback: prefers PHP_BINARY env var, then PATH default, then newest version
    • Clear error messages when no compatible PHP is found, with hints about available installations
  3. Config persistence (internal/shop/config.go):

    • Added PHPBinary field to project config, persisted as php_binary in .shopware-project.yml
    • Executor uses project's php_binary config (if set) for all PHP commands, falling back to PHP_BINARY env var or php from PATH
  4. Dependency validation updates (internal/system/setup.go):

    • CheckProjectDependencies() now accepts optional phpBinary parameter to check a specific PHP executable
    • Refactored version checking to support both ambient PHP and explicit binary paths
  5. Executor improvements (internal/executor/local.go):

    • LocalExecutor now respects project's selected PHP binary
    • When a specific PHP is selected, Composer runs through that PHP to ensure consistent dependency resolution

Why?

This enables developers to:

  • Work with projects requiring specific PHP versions without system-wide changes
  • Automatically discover and select compatible PHP installations
  • Persist their PHP choice in project config for team consistency
  • Use versioned PHP installations (e.g., from Homebrew) without manual path configuration

How was this tested?

  • Added comprehensive unit tests for PHP discovery (internal/system/php_discovery_test.go): candidate collection, deduplication, version probing, sorting, filtering
  • Added tests for project creation PHP selection (cmd/project/project_create_php_test.go): explicit flag handling, interactive/non-interactive fallbacks, constraint validation
  • Added tests for config round-trip and backward compatibility (internal/shop/config_test.go)
  • Added tests for executor PHP binary selection (internal/executor/executor_test.go)
  • Refactored GetInstalledPHPVersion() to use new GetPHPVersionOfBinary() with improved version parsing and timeout handling

Related issue or discussion

Enables proper PHP version management for multi-version development environments.

https://claude.ai/code/session_01Xd8qd8PT9pjFvBDrvMoJ1L

…project create

For local (non-Docker) project creation, discover the usable PHP
executables installed on the machine (PHP_BINARY, PATH including
versioned names, and platform locations such as Homebrew, versioned
system packages, and common Windows installs), let an interactive user
pick one that satisfies the chosen Shopware release's PHP constraint,
use that exact binary for dependency validation and the Composer
install, and persist its absolute path as php_binary in the generated
.shopware-project.yml.

- internal/system: new PHP discovery service (canonicalizes,
  de-duplicates, probes versions, ignores broken executables, sorts
  newest first while keeping PHP_BINARY first) plus helpers for
  filtering by constraint and picking the preferred candidate
- project create: new --php-binary flag for non-interactive selection
  (rejected together with --docker), interactive select prompt after
  the Shopware version is resolved, deterministic non-interactive
  fallback (compatible PHP_BINARY, then the compatible PATH default,
  otherwise a clear error listing compatible installations), and a
  rendered list of discovered installations when none satisfies the
  constraint
- shop config: optional root-level php_binary field, exposed through
  project config-schema; Docker projects never prompt for or write it
- executor: LocalExecutor routes console/PHP/Composer commands through
  the precedence php_binary > PHP_BINARY > php from PATH, so the
  persisted selection applies to later project commands too
- dependency validation can now check a specific PHP binary instead of
  only the ambient one

Existing projects without php_binary keep the exact previous behavior.

Fixes #1303

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xd8qd8PT9pjFvBDrvMoJ1L
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.64621% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.34%. Comparing base (1561f6d) to head (e8edcb7).

Files with missing lines Patch % Lines
cmd/project/project_create_php.go 64.61% 23 Missing ⚠️
internal/system/php_discovery.go 87.67% 18 Missing ⚠️
internal/system/setup.go 0.00% 14 Missing ⚠️
cmd/project/project_create_install.go 0.00% 9 Missing ⚠️
cmd/project/project_create_validate.go 33.33% 4 Missing ⚠️
cmd/project/project_create.go 60.00% 1 Missing and 1 partial ⚠️
internal/system/php.go 88.23% 2 Missing ⚠️
cmd/project/project_dev.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1306      +/-   ##
==========================================
+ Coverage   54.00%   54.34%   +0.33%     
==========================================
  Files         303      305       +2     
  Lines       23453    23697     +244     
==========================================
+ Hits        12666    12878     +212     
- Misses      10759    10790      +31     
- Partials       28       29       +1     
Flag Coverage Δ
go-test 54.34% <73.64%> (+0.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants