1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-07 01:00:09 +01:00

update to unlink not the current version but the currently linked formula path (handles bug with latest version under php path)

This commit is contained in:
James Barnard
2019-01-21 22:33:32 +00:00
committed by Matt Stauffer
parent ece3a1ff2f
commit 0bf3078220
4 changed files with 131 additions and 5 deletions

View File

@@ -194,11 +194,11 @@ function hasLinkedPhp()
}
/**
* Determine which version of PHP is linked in Homebrew.
* Get the linked php parsed
*
* @return string
* @return mixed
*/
function linkedPhp()
function getParsedLinkedPhp()
{
if (! $this->hasLinkedPhp()) {
throw new DomainException("Homebrew PHP appears not to be linked.");
@@ -214,6 +214,32 @@ function linkedPhp()
* "../Cellar/php55/bin/php
*/
preg_match('~\w{3,}/(php)(@?\d\.?\d)?/(\d\.\d)?([_\d\.]*)?/?\w{3,}~', $resolvedPath, $matches);
return $matches;
}
/**
* Gets the currently linked formula
* E.g if under php, will be php, if under php@7.3 will be that
* Different to ->linkedPhp() in that this will just get the linked directory name (whether that is php, php55 or
* php@7.2)
*
* @return mixed
*/
function getLinkedPhpFormula()
{
$matches = $this->getParsedLinkedPhp();
return $matches[1] . $matches[2];
}
/**
* Determine which version of PHP is linked in Homebrew.
*
* @return string
*/
function linkedPhp()
{
$matches = $this->getParsedLinkedPhp();
$resolvedPhpVersion = $matches[3] ?: $matches[2];
return $this->supportedPhpVersions()->first(

View File

@@ -155,7 +155,7 @@ function useVersion($version)
// Unlink the current php if there is one
if ($this->brew->hasLinkedPhp()) {
$currentVersion = $this->brew->linkedPhp();
$currentVersion = $this->brew->getLinkedPhpFormula();
info(sprintf('Unlinking current version: %s', $currentVersion));
$this->brew->unlink($currentVersion);
}

View File

@@ -371,4 +371,104 @@ public function test_getRunningServices_will_pass_to_brew_services_list_and_retu
'service3',
], array_values($result->all()));
}
/**
* @dataProvider supportedPhpLinkPathProvider
*
* @param $path
* @param $matches
*/
public function test_get_parsed_linked_php_will_return_matches_for_linked_php($path, $matches)
{
$getBrewMock = function ($filesystem) {
$brewMock = Mockery::mock(Brew::class, [new CommandLine, $filesystem])->makePartial();
$brewMock->shouldReceive('hasLinkedPhp')->once()->andReturn(true);
return $brewMock;
};
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('readLink')->once()->with('/usr/local/bin/php')->andReturn($path);
$this->assertSame($matches, $getBrewMock($files)->getParsedLinkedPhp());
}
/**
* @dataProvider supportedPhpLinkPathProvider
*
* @param $path
* @param $matches
* @param $expectedLinkFormula
*/
public function test_get_linked_php_formula_will_return_linked_php_directory($path, $matches, $expectedLinkFormula)
{
$brewMock = Mockery::mock(Brew::class)->makePartial();
$brewMock->shouldReceive('getParsedLinkedPhp')->andReturn($matches);
$this->assertSame($expectedLinkFormula, $brewMock->getLinkedPhpFormula());
}
/**
* Provider of php links and their expected split matches
*
* @return array
*/
public function supportedPhpLinkPathProvider()
{
return [
[
'/test/path/php/7.3.0/test', // linked path
[ // matches
'path/php/7.3.0/test',
'php',
'',
'7.3',
'.0',
],
'php', // expected link formula
],
[
'/test/path/php@7.2/7.2.13/test',
[
'path/php@7.2/7.2.13/test',
'php',
'@7.2',
'7.2',
'.13',
],
'php@7.2'
],
[
'/test/path/php/7.2.9_2/test',
[
'path/php/7.2.9_2/test',
'php',
'',
'7.2',
'.9_2',
],
'php',
],
[
'/test/path/php72/7.2.9_2/test',
[
'path/php72/7.2.9_2/test',
'php',
'72',
'7.2',
'.9_2',
],
'php72',
],
[
'/test/path/php56/test',
[
'path/php56/test',
'php',
'56',
'',
'',
],
'php56',
],
];
}
}

View File

@@ -118,7 +118,7 @@ public function test_use_version_if_already_linked_php_will_unlink_before_instal
'php@5.6',
]));
$brewMock->shouldReceive('hasLinkedPhp')->andReturn(true);
$brewMock->shouldReceive('linkedPhp')->andReturn('php@7.1');
$brewMock->shouldReceive('getLinkedPhpFormula')->andReturn('php@7.1');
$brewMock->shouldReceive('unlink')->with('php@7.1');
$brewMock->shouldReceive('ensureInstalled')->with('php@7.2');
$brewMock->shouldReceive('link')->withArgs(['php@7.2', true]);