diff --git a/cli/Valet/Brew.php b/cli/Valet/Brew.php index 2acf68b..4a06605 100644 --- a/cli/Valet/Brew.php +++ b/cli/Valet/Brew.php @@ -8,6 +8,7 @@ class Brew { + // This is the array of PHP versions that Valet will attempt to install/configure when requested const SUPPORTED_PHP_VERSIONS = [ 'php', 'php@8.2', @@ -19,9 +20,22 @@ class Brew 'php@7.1', ]; - const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1'; + // Update this LATEST and the following LIMITED array when PHP versions are released or retired + // We specify a numbered version here even though Homebrew links its generic 'php' alias to it + const LATEST_PHP_VERSION = 'php@8.2'; - const LATEST_PHP_VERSION = 'php@8.1'; + // These are the PHP versions that should be installed via the shivammathur/php tap because + // Homebrew officially no longer bottles them or they're marked disabled in their formula + // Cue: Homebrew reports "php@7.4 has been disabled because it is a versioned formula" + const LIMITED_PHP_VERSIONS = [ + 'php@8.0', + 'php@7.4', + 'php@7.3', + 'php@7.2', + 'php@7.1', + ]; + + const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1'; public function __construct(public CommandLine $cli, public Filesystem $files) { @@ -72,6 +86,14 @@ public function supportedPhpVersions(): Collection return collect(static::SUPPORTED_PHP_VERSIONS); } + /** + * Get a list of disabled/limited PHP versions. + */ + public function limitedPhpVersions(): Collection + { + return collect(static::LIMITED_PHP_VERSIONS); + } + /** * Get a list of installed PHP formulae. */ @@ -135,7 +157,9 @@ public function installOrFail(string $formula, array $options = [], array $taps } output('['.$formula.'] is not installed, installing it now via Brew... 🍻'); - if ($formula !== 'php' && starts_with($formula, 'php') && preg_replace('/[^\d]/', '', $formula) < '73') { + + if ($this->limitedPhpVersions()->contains($formula)) { + $formula = 'shivammathur/php/' . $formula; warning('Note: older PHP versions may take 10+ minutes to compile from source. Please wait ...'); } diff --git a/tests/BrewTest.php b/tests/BrewTest.php index 16012bb..f2cbee1 100644 --- a/tests/BrewTest.php +++ b/tests/BrewTest.php @@ -203,6 +203,22 @@ public function test_linked_php_throws_exception_if_unsupported_php_version_is_l resolve(Brew::class)->linkedPhp(); } + public function test_outdated_php_versions_use_the_alternate_tap() + { + $brewMock = Mockery::mock(Brew::class, [ + $cli = Mockery::mock(CommandLine::class), + Mockery::mock(Filesystem::class), + ])->makePartial(); + + $brewMock->shouldReceive('limitedPhpVersions')->andReturn(collect([ + 'php@7.0', + ])); + + $cli->shouldReceive('runAsUser')->once()->with(Brew::BREW_DISABLE_AUTO_CLEANUP.' brew install shivammathur/php/php@7.0', Mockery::type('Closure')); + + $brewMock->installOrFail('php@7.0'); + } + public function test_install_or_fail_will_install_brew_formulae() { $cli = Mockery::mock(CommandLine::class);