From 6a4cb74392c5db75704b05f4f1994490fcba245e Mon Sep 17 00:00:00 2001 From: soilSpoon Date: Sat, 14 Nov 2020 21:42:13 +0900 Subject: [PATCH] Modify php binary path to be based on brew prefix --- cli/Valet/Brew.php | 4 ++-- cli/includes/helpers.php | 2 ++ tests/BrewTest.php | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cli/Valet/Brew.php b/cli/Valet/Brew.php index 5a4ef31..e16c47a 100644 --- a/cli/Valet/Brew.php +++ b/cli/Valet/Brew.php @@ -202,7 +202,7 @@ function stopService($services) */ function hasLinkedPhp() { - return $this->files->isLink('/usr/local/bin/php'); + return $this->files->isLink(PHP_BINARY_PATH); } /** @@ -216,7 +216,7 @@ function getParsedLinkedPhp() throw new DomainException("Homebrew PHP appears not to be linked."); } - $resolvedPath = $this->files->readLink('/usr/local/bin/php'); + $resolvedPath = $this->files->readLink(PHP_BINARY_PATH); /** * Typical homebrew path resolutions are like: diff --git a/cli/includes/helpers.php b/cli/includes/helpers.php index 8c91b21..8ddb664 100644 --- a/cli/includes/helpers.php +++ b/cli/includes/helpers.php @@ -16,6 +16,8 @@ define('VALET_LEGACY_HOME_PATH', $_SERVER['HOME'].'/.valet'); +define('PHP_BINARY_PATH', (new CommandLine())->runAsUser('echo $(brew --prefix)/bin/php')); + /** * Output the given text to the console. * diff --git a/tests/BrewTest.php b/tests/BrewTest.php index b179524..8823586 100644 --- a/tests/BrewTest.php +++ b/tests/BrewTest.php @@ -238,27 +238,27 @@ public function test_linked_php_returns_linked_php_formula_name() }; $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/7.4.0/test'); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/7.4.0/test'); $this->assertSame('php@7.4', $getBrewMock($files)->linkedPhp()); $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/7.3.0/test'); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/7.3.0/test'); $this->assertSame('php@7.3', $getBrewMock($files)->linkedPhp()); $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php@7.2/7.2.13/test'); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php@7.2/7.2.13/test'); $this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp()); $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/7.2.9_2/test'); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/7.2.9_2/test'); $this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp()); $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php72/7.2.9_2/test'); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php72/7.2.9_2/test'); $this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp()); $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php56/test'); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php56/test'); $this->assertSame('php@5.6', $getBrewMock($files)->linkedPhp()); } @@ -277,7 +277,7 @@ public function test_linked_php_throws_exception_if_no_php_link() public function test_has_linked_php_returns_true_if_php_link_exists() { $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('isLink')->twice()->with('/usr/local/bin/php')->andReturn(false, true); + $files->shouldReceive('isLink')->twice()->with(PHP_BINARY_PATH)->andReturn(false, true); swap(Filesystem::class, $files); $brew = resolve(Brew::class); @@ -292,8 +292,8 @@ public function test_has_linked_php_returns_true_if_php_link_exists() public function test_linked_php_throws_exception_if_unsupported_php_version_is_linked() { $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('isLink')->once()->with('/usr/local/bin/php')->andReturn(true); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn('/test/path/php/5.4.14/test'); + $files->shouldReceive('isLink')->once()->with(PHP_BINARY_PATH)->andReturn(true); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn('/test/path/php/5.4.14/test'); swap(Filesystem::class, $files); resolve(Brew::class)->linkedPhp(); } @@ -449,7 +449,7 @@ public function test_get_parsed_linked_php_will_return_matches_for_linked_php($p }; $files = Mockery::mock(Filesystem::class); - $files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn($path); + $files->shouldReceive('readLink')->once()->with(PHP_BINARY_PATH)->andReturn($path); $this->assertSame($matches, $getBrewMock($files)->getParsedLinkedPhp()); }