mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
StyleCI Patch
This commit is contained in:
@@ -298,26 +298,24 @@ function ($version) use ($resolvedPhpVersion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get PHP executable path for a given PHP Version
|
* Get PHP executable path for a given PHP Version.
|
||||||
*
|
|
||||||
* @param string|null $phpVersion
|
|
||||||
* @param boolean $skipCache
|
|
||||||
*
|
*
|
||||||
|
* @param string|null $phpVersion
|
||||||
|
* @param bool $skipCache
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function whichPhp($phpVersion = null, $skipCache = false)
|
public function whichPhp($phpVersion = null, $skipCache = false)
|
||||||
{
|
{
|
||||||
if(! $phpVersion){
|
if (! $phpVersion) {
|
||||||
return BREW_PREFIX.'/bin/php';
|
return BREW_PREFIX.'/bin/php';
|
||||||
}
|
}
|
||||||
|
|
||||||
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
|
$versionInteger = preg_replace('~[^\d]~', '', $phpVersion);
|
||||||
$symlinkedValetPhpPath = BREW_PREFIX. "/bin/valetphp{$versionInteger}";
|
$symlinkedValetPhpPath = BREW_PREFIX."/bin/valetphp{$versionInteger}";
|
||||||
|
|
||||||
// If the symlinked Valet PHP path exists, then we can use that
|
// If the symlinked Valet PHP path exists, then we can use that
|
||||||
if (!$skipCache && $this->files->isLink($symlinkedValetPhpPath)) {
|
if (! $skipCache && $this->files->isLink($symlinkedValetPhpPath)) {
|
||||||
$phpExecutablePath = $this->files->readLink($symlinkedValetPhpPath);
|
$phpExecutablePath = $this->files->readLink($symlinkedValetPhpPath);
|
||||||
|
|
||||||
// Still make sure that the version of the executable exists
|
// Still make sure that the version of the executable exists
|
||||||
@@ -335,12 +333,10 @@ public function whichPhp($phpVersion = null, $skipCache = false)
|
|||||||
return $phpExecutablePath ?: BREW_PREFIX.'/bin/php';
|
return $phpExecutablePath ?: BREW_PREFIX.'/bin/php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract PHP executable path from PHP Version
|
* Extract PHP executable path from PHP Version.
|
||||||
*
|
*
|
||||||
* @param string $phpVersion
|
* @param string $phpVersion
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPhpExecutablePath($phpVersion)
|
public function getPhpExecutablePath($phpVersion)
|
||||||
|
|||||||
@@ -562,13 +562,13 @@
|
|||||||
})->descriptions('List all sites using isolated versions of PHP.');
|
})->descriptions('List all sites using isolated versions of PHP.');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PHP executable path for a site
|
* Get the PHP executable path for a site.
|
||||||
*/
|
*/
|
||||||
$app->command('which-php [site] [--skip-cache]', function ($site, $skipCache) {
|
$app->command('which-php [site] [--skip-cache]', function ($site, $skipCache) {
|
||||||
$host = Site::host($site ?: getcwd()).'.'.Configuration::read()['tld'];
|
$host = Site::host($site ?: getcwd()).'.'.Configuration::read()['tld'];
|
||||||
$phpVersion = Site::customPhpVersion($host);
|
$phpVersion = Site::customPhpVersion($host);
|
||||||
|
|
||||||
if(! $phpVersion){
|
if (! $phpVersion) {
|
||||||
$path = getcwd().'/.valetphprc';
|
$path = getcwd().'/.valetphprc';
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
$phpVersion = trim(file_get_contents($path));
|
$phpVersion = trim(file_get_contents($path));
|
||||||
@@ -584,16 +584,16 @@
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy PHP commands with isolated site's PHP executable
|
* Proxy PHP commands with isolated site's PHP executable.
|
||||||
*/
|
*/
|
||||||
$app->command('php [command]', function ($command) {
|
$app->command('php [command]', function ($command) {
|
||||||
warning('It looks like you are running `cli/valet.php` directly; please use the `valet` script in the project root instead.');
|
warning('It looks like you are running `cli/valet.php` directly; please use the `valet` script in the project root instead.');
|
||||||
})->descriptions("Proxy PHP commands with isolated site's PHP executable", [
|
})->descriptions("Proxy PHP commands with isolated site's PHP executable", [
|
||||||
'command' => "Command to run with isolated site's PHP executable",
|
'command' => "Command to run with isolated site's PHP executable",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy Composer commands with isolated site's PHP executable
|
* Proxy Composer commands with isolated site's PHP executable.
|
||||||
*/
|
*/
|
||||||
$app->command('composer [command]', function ($command) {
|
$app->command('composer [command]', function ($command) {
|
||||||
warning('It looks like you are running `cli/valet.php` directly; please use the `valet` script in the project root instead.');
|
warning('It looks like you are running `cli/valet.php` directly; please use the `valet` script in the project root instead.');
|
||||||
|
|||||||
@@ -400,44 +400,44 @@ public function test_it_can_get_php_binary_path_from_php_version_and_create_syml
|
|||||||
// When there is no symlinked Valet PHP exists
|
// When there is no symlinked Valet PHP exists
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
Mockery::mock(CommandLine::class),
|
Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$files->shouldReceive('isLink')->once()->with(BREW_PREFIX."/bin/valetphp74")->andReturn(false);
|
$files->shouldReceive('isLink')->once()->with(BREW_PREFIX.'/bin/valetphp74')->andReturn(false);
|
||||||
$files->shouldReceive('symlinkAsUser')->once()->withArgs([BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php", BREW_PREFIX."/bin/valetphp74"]);
|
$files->shouldReceive('symlinkAsUser')->once()->withArgs([BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php', BREW_PREFIX.'/bin/valetphp74']);
|
||||||
$brewMock->shouldReceive('getPhpExecutablePath')->once()->with('php@7.4')->andReturn(BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php");
|
$brewMock->shouldReceive('getPhpExecutablePath')->once()->with('php@7.4')->andReturn(BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php');
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php", $brewMock->whichPhp('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php', $brewMock->whichPhp('php@7.4'));
|
||||||
|
|
||||||
// When there is a symlinked Valet PHP exists
|
// When there is a symlinked Valet PHP exists
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
Mockery::mock(CommandLine::class),
|
Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$brewMock->shouldNotHaveReceived('getPhpExecutablePath');
|
$brewMock->shouldNotHaveReceived('getPhpExecutablePath');
|
||||||
$files->shouldReceive('isLink')->once()->with(BREW_PREFIX."/bin/valetphp81")->andReturn(true);
|
$files->shouldReceive('isLink')->once()->with(BREW_PREFIX.'/bin/valetphp81')->andReturn(true);
|
||||||
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX."/bin/valetphp81")->andReturn(BREW_PREFIX."/Cellar/php@8.1/8.1.5/bin/php");
|
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/valetphp81')->andReturn(BREW_PREFIX.'/Cellar/php@8.1/8.1.5/bin/php');
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX."/Cellar/php@8.1/8.1.5/bin/php")->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/Cellar/php@8.1/8.1.5/bin/php')->andReturn(true);
|
||||||
$files->shouldNotHaveReceived('symlinkAsUser');
|
$files->shouldNotHaveReceived('symlinkAsUser');
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@8.1/8.1.5/bin/php", $brewMock->whichPhp('php@8.1'));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@8.1/8.1.5/bin/php', $brewMock->whichPhp('php@8.1'));
|
||||||
|
|
||||||
// Check with $skipCache enabled
|
// Check with $skipCache enabled
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
Mockery::mock(CommandLine::class),
|
Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$brewMock->shouldReceive('getPhpExecutablePath')->once()->with('php@7.4')->andReturn(BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php");
|
$brewMock->shouldReceive('getPhpExecutablePath')->once()->with('php@7.4')->andReturn(BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php');
|
||||||
$files->shouldReceive('symlinkAsUser')->once()->withArgs([BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php", BREW_PREFIX."/bin/valetphp74"]);
|
$files->shouldReceive('symlinkAsUser')->once()->withArgs([BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php', BREW_PREFIX.'/bin/valetphp74']);
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php", $brewMock->whichPhp('php@7.4', true));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php', $brewMock->whichPhp('php@7.4', true));
|
||||||
|
|
||||||
// When no PHP Version is provided
|
// When no PHP Version is provided
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
Mockery::mock(CommandLine::class),
|
Mockery::mock(CommandLine::class),
|
||||||
Mockery::mock(Filesystem::class)
|
Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX.'/bin/php', $brewMock->whichPhp(null));
|
$this->assertEquals(BREW_PREFIX.'/bin/php', $brewMock->whichPhp(null));
|
||||||
@@ -445,67 +445,67 @@ public function test_it_can_get_php_binary_path_from_php_version_and_create_syml
|
|||||||
|
|
||||||
public function test_it_can_get_php_binary_path_from_php_version()
|
public function test_it_can_get_php_binary_path_from_php_version()
|
||||||
{
|
{
|
||||||
// When brew info has `linked_keg` paramerter
|
// When brew info has `linked_keg` parameter
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
$cli = Mockery::mock(CommandLine::class),
|
$cli = Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew --cellar php@7.4")->andReturn(BREW_PREFIX."/Cellar/php@7.4");
|
$cli->shouldReceive('runAsUser')->once()->with('brew --cellar php@7.4')->andReturn(BREW_PREFIX.'/Cellar/php@7.4');
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew info --json php@7.4")->andReturn('[{"linked_keg":"7.4.6","installed":[{"version":"7.4.5"}]}]');
|
$cli->shouldReceive('runAsUser')->once()->with('brew info --json php@7.4')->andReturn('[{"linked_keg":"7.4.6","installed":[{"version":"7.4.5"}]}]');
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php")->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php')->andReturn(true);
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@7.4/7.4.6/bin/php", $brewMock->getPhpExecutablePath('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@7.4/7.4.6/bin/php', $brewMock->getPhpExecutablePath('php@7.4'));
|
||||||
|
|
||||||
// When brew info doesn't have `linked_keg`
|
// When brew info doesn't have `linked_keg`
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
$cli = Mockery::mock(CommandLine::class),
|
$cli = Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew --cellar php@8.0")->andReturn(BREW_PREFIX."/Cellar/php@8.0");
|
$cli->shouldReceive('runAsUser')->once()->with('brew --cellar php@8.0')->andReturn(BREW_PREFIX.'/Cellar/php@8.0');
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew info --json php@8.0")->andReturn('[{"installed":[{"version":"8.0.5"}]}]');
|
$cli->shouldReceive('runAsUser')->once()->with('brew info --json php@8.0')->andReturn('[{"installed":[{"version":"8.0.5"}]}]');
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX."/Cellar/php@8.0/8.0.5/bin/php")->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/Cellar/php@8.0/8.0.5/bin/php')->andReturn(true);
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@8.0/8.0.5/bin/php", $brewMock->getPhpExecutablePath('php@8.0'));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@8.0/8.0.5/bin/php', $brewMock->getPhpExecutablePath('php@8.0'));
|
||||||
|
|
||||||
// When brew info has a version that was manually installed
|
// When brew info has a version that was manually installed
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
$cli = Mockery::mock(CommandLine::class),
|
$cli = Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew --cellar php@8.1")->andReturn(BREW_PREFIX."/Cellar/php@8.1");
|
$cli->shouldReceive('runAsUser')->once()->with('brew --cellar php@8.1')->andReturn(BREW_PREFIX.'/Cellar/php@8.1');
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew info --json php@8.1")
|
$cli->shouldReceive('runAsUser')->once()->with('brew info --json php@8.1')
|
||||||
->andReturn('[{"installed":[{"version":"8.1.1", "installed_as_dependency":true}, {"version":"8.1.2", "installed_as_dependency":false}]}]');
|
->andReturn('[{"installed":[{"version":"8.1.1", "installed_as_dependency":true}, {"version":"8.1.2", "installed_as_dependency":false}]}]');
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX."/Cellar/php@8.1/8.1.2/bin/php")->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/Cellar/php@8.1/8.1.2/bin/php')->andReturn(true);
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@8.1/8.1.2/bin/php", $brewMock->getPhpExecutablePath('php@8.1'));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@8.1/8.1.2/bin/php', $brewMock->getPhpExecutablePath('php@8.1'));
|
||||||
|
|
||||||
// When brew info has no version that was installed manually, it should pick the last PHP version
|
// When brew info has no version that was installed manually, it should pick the last PHP version
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
$cli = Mockery::mock(CommandLine::class),
|
$cli = Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew --cellar php@7.4")->andReturn(BREW_PREFIX."/Cellar/php@7.4");
|
$cli->shouldReceive('runAsUser')->once()->with('brew --cellar php@7.4')->andReturn(BREW_PREFIX.'/Cellar/php@7.4');
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew info --json php@7.4")
|
$cli->shouldReceive('runAsUser')->once()->with('brew info --json php@7.4')
|
||||||
->andReturn('[{"installed":[{"version":"7.4.1", "installed_as_dependency":false}, {"version":"7.4.3", "installed_as_dependency":false}]}]');
|
->andReturn('[{"installed":[{"version":"7.4.1", "installed_as_dependency":false}, {"version":"7.4.3", "installed_as_dependency":false}]}]');
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX."/Cellar/php@7.4/7.4.3/bin/php")->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/Cellar/php@7.4/7.4.3/bin/php')->andReturn(true);
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/Cellar/php@7.4/7.4.3/bin/php", $brewMock->getPhpExecutablePath('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/Cellar/php@7.4/7.4.3/bin/php', $brewMock->getPhpExecutablePath('php@7.4'));
|
||||||
|
|
||||||
// When user has installed directly though `shivammathur/homebrew-php`
|
// When user has installed directly though `shivammathur/homebrew-php`
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
$cli = Mockery::mock(CommandLine::class),
|
$cli = Mockery::mock(CommandLine::class),
|
||||||
$files = Mockery::mock(Filesystem::class)
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew --cellar php@7.4")->andReturn(BREW_PREFIX."/Cellar/php@7.4");
|
$cli->shouldReceive('runAsUser')->once()->with('brew --cellar php@7.4')->andReturn(BREW_PREFIX.'/Cellar/php@7.4');
|
||||||
$cli->shouldReceive('runAsUser')->once()->with("brew info --json php@7.4")->andReturn(false);
|
$cli->shouldReceive('runAsUser')->once()->with('brew info --json php@7.4')->andReturn(false);
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX."/opt/php@7.4/bin/php")->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@7.4/bin/php')->andReturn(true);
|
||||||
|
|
||||||
$this->assertEquals(BREW_PREFIX."/opt/php@7.4/bin/php", $brewMock->getPhpExecutablePath('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/opt/php@7.4/bin/php', $brewMock->getPhpExecutablePath('php@7.4'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user