mirror of
https://github.com/laravel/valet.git
synced 2026-02-07 17:10:05 +01:00
Add type hints and return type hints to Brew
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use DomainException;
|
use DomainException;
|
||||||
use PhpFpm;
|
use PhpFpm;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class Brew
|
class Brew
|
||||||
{
|
{
|
||||||
@@ -12,18 +13,9 @@ class Brew
|
|||||||
'php@8.2',
|
'php@8.2',
|
||||||
'php@8.1',
|
'php@8.1',
|
||||||
'php@8.0',
|
'php@8.0',
|
||||||
'php@7.4',
|
|
||||||
'php@7.3',
|
|
||||||
'php@7.2',
|
|
||||||
'php@7.1',
|
|
||||||
'php@7.0',
|
|
||||||
'php73',
|
|
||||||
'php72',
|
|
||||||
'php71',
|
|
||||||
'php70',
|
|
||||||
];
|
];
|
||||||
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
|
const BREW_DISABLE_AUTO_CLEANUP = 'HOMEBREW_NO_INSTALL_CLEANUP=1';
|
||||||
const LATEST_PHP_VERSION = 'php@8.1';
|
const LATEST_PHP_VERSION = 'php@8.2';
|
||||||
|
|
||||||
public $cli;
|
public $cli;
|
||||||
public $files;
|
public $files;
|
||||||
@@ -47,7 +39,7 @@ public function __construct(CommandLine $cli, Filesystem $files)
|
|||||||
* @param string $formula
|
* @param string $formula
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function installed($formula)
|
public function installed(string $formula): bool
|
||||||
{
|
{
|
||||||
$result = $this->cli->runAsUser("brew info $formula --json");
|
$result = $this->cli->runAsUser("brew info $formula --json");
|
||||||
|
|
||||||
@@ -66,7 +58,7 @@ public function installed($formula)
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasInstalledPhp()
|
public function hasInstalledPhp(): bool
|
||||||
{
|
{
|
||||||
$installed = $this->installedPhpFormulae()->first(function ($formula) {
|
$installed = $this->installedPhpFormulae()->first(function ($formula) {
|
||||||
return $this->supportedPhpVersions()->contains($formula);
|
return $this->supportedPhpVersions()->contains($formula);
|
||||||
@@ -78,14 +70,19 @@ public function hasInstalledPhp()
|
|||||||
/**
|
/**
|
||||||
* Get a list of supported PHP versions.
|
* Get a list of supported PHP versions.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Support\Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function supportedPhpVersions()
|
public function supportedPhpVersions(): Collection
|
||||||
{
|
{
|
||||||
return collect(static::SUPPORTED_PHP_VERSIONS);
|
return collect(static::SUPPORTED_PHP_VERSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function installedPhpFormulae()
|
/**
|
||||||
|
* Get a list of installed PHP formulae.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function installedPhpFormulae(): Collection
|
||||||
{
|
{
|
||||||
return collect(
|
return collect(
|
||||||
explode(PHP_EOL, $this->cli->runAsUser('brew list --formula | grep php'))
|
explode(PHP_EOL, $this->cli->runAsUser('brew list --formula | grep php'))
|
||||||
@@ -94,8 +91,10 @@ public function installedPhpFormulae()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the aliased formula version from Homebrew.
|
* Get the aliased formula version from Homebrew.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function determineAliasedVersion($formula)
|
public function determineAliasedVersion($formula): string
|
||||||
{
|
{
|
||||||
$details = json_decode($this->cli->runAsUser("brew info $formula --json"));
|
$details = json_decode($this->cli->runAsUser("brew info $formula --json"));
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ public function determineAliasedVersion($formula)
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasInstalledNginx()
|
public function hasInstalledNginx(): bool
|
||||||
{
|
{
|
||||||
return $this->installed('nginx')
|
return $this->installed('nginx')
|
||||||
|| $this->installed('nginx-full');
|
|| $this->installed('nginx-full');
|
||||||
@@ -122,7 +121,7 @@ public function hasInstalledNginx()
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function nginxServiceName()
|
public function nginxServiceName(): string
|
||||||
{
|
{
|
||||||
return $this->installed('nginx-full') ? 'nginx-full' : 'nginx';
|
return $this->installed('nginx-full') ? 'nginx-full' : 'nginx';
|
||||||
}
|
}
|
||||||
@@ -135,7 +134,7 @@ public function nginxServiceName()
|
|||||||
* @param array $taps
|
* @param array $taps
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function ensureInstalled($formula, $options = [], $taps = [])
|
public function ensureInstalled(string $formula, array $options = [], array $taps = []): void
|
||||||
{
|
{
|
||||||
if (! $this->installed($formula)) {
|
if (! $this->installed($formula)) {
|
||||||
$this->installOrFail($formula, $options, $taps);
|
$this->installOrFail($formula, $options, $taps);
|
||||||
@@ -150,7 +149,7 @@ public function ensureInstalled($formula, $options = [], $taps = [])
|
|||||||
* @param array $taps
|
* @param array $taps
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function installOrFail($formula, $options = [], $taps = [])
|
public function installOrFail(string $formula, array $options = [], array $taps = []): void
|
||||||
{
|
{
|
||||||
info("Installing {$formula}...");
|
info("Installing {$formula}...");
|
||||||
|
|
||||||
@@ -176,7 +175,7 @@ public function installOrFail($formula, $options = [], $taps = [])
|
|||||||
* @param dynamic[string] $formula
|
* @param dynamic[string] $formula
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function tap($formulas)
|
public function tap($formulas): void
|
||||||
{
|
{
|
||||||
$formulas = is_array($formulas) ? $formulas : func_get_args();
|
$formulas = is_array($formulas) ? $formulas : func_get_args();
|
||||||
|
|
||||||
@@ -188,9 +187,10 @@ public function tap($formulas)
|
|||||||
/**
|
/**
|
||||||
* Restart the given Homebrew services.
|
* Restart the given Homebrew services.
|
||||||
*
|
*
|
||||||
* @param
|
* @param dynamic[string] $services
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function restartService($services)
|
public function restartService($services): void
|
||||||
{
|
{
|
||||||
$services = is_array($services) ? $services : func_get_args();
|
$services = is_array($services) ? $services : func_get_args();
|
||||||
|
|
||||||
@@ -211,9 +211,10 @@ public function restartService($services)
|
|||||||
/**
|
/**
|
||||||
* Stop the given Homebrew services.
|
* Stop the given Homebrew services.
|
||||||
*
|
*
|
||||||
* @param
|
* @param dynamic[string] $services
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public function stopService($services)
|
public function stopService($services): void
|
||||||
{
|
{
|
||||||
$services = is_array($services) ? $services : func_get_args();
|
$services = is_array($services) ? $services : func_get_args();
|
||||||
|
|
||||||
@@ -248,7 +249,7 @@ public function stopService($services)
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function hasLinkedPhp()
|
public function hasLinkedPhp(): bool
|
||||||
{
|
{
|
||||||
return $this->files->isLink(BREW_PREFIX.'/bin/php');
|
return $this->files->isLink(BREW_PREFIX.'/bin/php');
|
||||||
}
|
}
|
||||||
@@ -256,9 +257,9 @@ public function hasLinkedPhp()
|
|||||||
/**
|
/**
|
||||||
* Get the linked php parsed.
|
* Get the linked php parsed.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getParsedLinkedPhp()
|
public function getParsedLinkedPhp(): array
|
||||||
{
|
{
|
||||||
if (! $this->hasLinkedPhp()) {
|
if (! $this->hasLinkedPhp()) {
|
||||||
throw new DomainException('Homebrew PHP appears not to be linked. Please run [valet use php@X.Y]');
|
throw new DomainException('Homebrew PHP appears not to be linked. Please run [valet use php@X.Y]');
|
||||||
@@ -276,7 +277,7 @@ public function getParsedLinkedPhp()
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLinkedPhpFormula()
|
public function getLinkedPhpFormula(): string
|
||||||
{
|
{
|
||||||
$matches = $this->getParsedLinkedPhp();
|
$matches = $this->getParsedLinkedPhp();
|
||||||
|
|
||||||
@@ -288,7 +289,7 @@ public function getLinkedPhpFormula()
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function linkedPhp()
|
public function linkedPhp(): string
|
||||||
{
|
{
|
||||||
$matches = $this->getParsedLinkedPhp();
|
$matches = $this->getParsedLinkedPhp();
|
||||||
$resolvedPhpVersion = $matches[3] ?: $matches[2];
|
$resolvedPhpVersion = $matches[3] ?: $matches[2];
|
||||||
@@ -304,10 +305,10 @@ function ($version) use ($resolvedPhpVersion) {
|
|||||||
/**
|
/**
|
||||||
* Extract PHP executable path from PHP Version.
|
* Extract PHP executable path from PHP Version.
|
||||||
*
|
*
|
||||||
* @param string $phpVersion For example, "php@8.1"
|
* @param string|null $phpVersion For example, "php@8.1"
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPhpExecutablePath($phpVersion = null)
|
public function getPhpExecutablePath(?string $phpVersion = null): string
|
||||||
{
|
{
|
||||||
if (! $phpVersion) {
|
if (! $phpVersion) {
|
||||||
return BREW_PREFIX.'/bin/php';
|
return BREW_PREFIX.'/bin/php';
|
||||||
@@ -345,7 +346,7 @@ public function getPhpExecutablePath($phpVersion = null)
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function restartLinkedPhp()
|
public function restartLinkedPhp(): void
|
||||||
{
|
{
|
||||||
$this->restartService($this->getLinkedPhpFormula());
|
$this->restartService($this->getLinkedPhpFormula());
|
||||||
}
|
}
|
||||||
@@ -355,7 +356,7 @@ public function restartLinkedPhp()
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createSudoersEntry()
|
public function createSudoersEntry(): void
|
||||||
{
|
{
|
||||||
$this->files->ensureDirExists('/etc/sudoers.d');
|
$this->files->ensureDirExists('/etc/sudoers.d');
|
||||||
|
|
||||||
@@ -368,7 +369,7 @@ public function createSudoersEntry()
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function removeSudoersEntry()
|
public function removeSudoersEntry(): void
|
||||||
{
|
{
|
||||||
$this->cli->quietly('rm /etc/sudoers.d/brew');
|
$this->cli->quietly('rm /etc/sudoers.d/brew');
|
||||||
}
|
}
|
||||||
@@ -376,11 +377,11 @@ public function removeSudoersEntry()
|
|||||||
/**
|
/**
|
||||||
* Link passed formula.
|
* Link passed formula.
|
||||||
*
|
*
|
||||||
* @param $formula
|
* @param string $formula
|
||||||
* @param bool $force
|
* @param bool $force
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function link($formula, $force = false)
|
public function link(string $formula, bool $force = false): string
|
||||||
{
|
{
|
||||||
return $this->cli->runAsUser(
|
return $this->cli->runAsUser(
|
||||||
sprintf('brew link %s%s', $formula, $force ? ' --force' : ''),
|
sprintf('brew link %s%s', $formula, $force ? ' --force' : ''),
|
||||||
@@ -395,10 +396,10 @@ function ($exitCode, $errorOutput) use ($formula) {
|
|||||||
/**
|
/**
|
||||||
* Unlink passed formula.
|
* Unlink passed formula.
|
||||||
*
|
*
|
||||||
* @param $formula
|
* @param string $formula
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function unlink($formula)
|
public function unlink(string $formula): string
|
||||||
{
|
{
|
||||||
return $this->cli->runAsUser(
|
return $this->cli->runAsUser(
|
||||||
sprintf('brew unlink %s', $formula),
|
sprintf('brew unlink %s', $formula),
|
||||||
@@ -413,9 +414,9 @@ function ($exitCode, $errorOutput) use ($formula) {
|
|||||||
/**
|
/**
|
||||||
* Get all the currently running brew services.
|
* Get all the currently running brew services.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Support\Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getAllRunningServices()
|
public function getAllRunningServices(): Collection
|
||||||
{
|
{
|
||||||
return $this->getRunningServicesAsRoot()
|
return $this->getRunningServicesAsRoot()
|
||||||
->concat($this->getRunningServicesAsUser())
|
->concat($this->getRunningServicesAsUser())
|
||||||
@@ -426,9 +427,9 @@ public function getAllRunningServices()
|
|||||||
* Get the currently running brew services as root.
|
* Get the currently running brew services as root.
|
||||||
* i.e. /Library/LaunchDaemons (started at boot).
|
* i.e. /Library/LaunchDaemons (started at boot).
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Support\Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getRunningServicesAsRoot()
|
public function getRunningServicesAsRoot(): Collection
|
||||||
{
|
{
|
||||||
return $this->getRunningServices();
|
return $this->getRunningServices();
|
||||||
}
|
}
|
||||||
@@ -439,7 +440,7 @@ public function getRunningServicesAsRoot()
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Support\Collection
|
* @return \Illuminate\Support\Collection
|
||||||
*/
|
*/
|
||||||
public function getRunningServicesAsUser()
|
public function getRunningServicesAsUser(): Collection
|
||||||
{
|
{
|
||||||
return $this->getRunningServices(true);
|
return $this->getRunningServices(true);
|
||||||
}
|
}
|
||||||
@@ -448,9 +449,9 @@ public function getRunningServicesAsUser()
|
|||||||
* Get the currently running brew services.
|
* Get the currently running brew services.
|
||||||
*
|
*
|
||||||
* @param bool $asUser
|
* @param bool $asUser
|
||||||
* @return \Illuminate\Support\Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getRunningServices($asUser = false)
|
public function getRunningServices(bool $asUser = false): Collection
|
||||||
{
|
{
|
||||||
$command = 'brew services list | grep started | awk \'{ print $1; }\'';
|
$command = 'brew services list | grep started | awk \'{ print $1; }\'';
|
||||||
$onError = function ($exitCode, $errorOutput) {
|
$onError = function ($exitCode, $errorOutput) {
|
||||||
@@ -470,7 +471,7 @@ public function getRunningServices($asUser = false)
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function uninstallAllPhpVersions()
|
public function uninstallAllPhpVersions(): string
|
||||||
{
|
{
|
||||||
$this->supportedPhpVersions()->each(function ($formula) {
|
$this->supportedPhpVersions()->each(function ($formula) {
|
||||||
$this->uninstallFormula($formula);
|
$this->uninstallFormula($formula);
|
||||||
@@ -485,7 +486,7 @@ public function uninstallAllPhpVersions()
|
|||||||
* @param string $formula
|
* @param string $formula
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function uninstallFormula($formula)
|
public function uninstallFormula(string $formula): void
|
||||||
{
|
{
|
||||||
$this->cli->runAsUser(static::BREW_DISABLE_AUTO_CLEANUP.' brew uninstall --force '.$formula);
|
$this->cli->runAsUser(static::BREW_DISABLE_AUTO_CLEANUP.' brew uninstall --force '.$formula);
|
||||||
$this->cli->run('rm -rf '.BREW_PREFIX.'/Cellar/'.$formula);
|
$this->cli->run('rm -rf '.BREW_PREFIX.'/Cellar/'.$formula);
|
||||||
@@ -496,7 +497,7 @@ public function uninstallFormula($formula)
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function cleanupBrew()
|
public function cleanupBrew(): string
|
||||||
{
|
{
|
||||||
return $this->cli->runAsUser(
|
return $this->cli->runAsUser(
|
||||||
'brew cleanup && brew services cleanup',
|
'brew cleanup && brew services cleanup',
|
||||||
@@ -512,7 +513,7 @@ function ($exitCode, $errorOutput) {
|
|||||||
* @param string $resolvedPath
|
* @param string $resolvedPath
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function parsePhpPath($resolvedPath)
|
public function parsePhpPath(string $resolvedPath): array
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Typical homebrew path resolutions are like:
|
* Typical homebrew path resolutions are like:
|
||||||
@@ -533,7 +534,7 @@ public function parsePhpPath($resolvedPath)
|
|||||||
* @param string $versionB
|
* @param string $versionB
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function arePhpVersionsEqual($versionA, $versionB)
|
public function arePhpVersionsEqual(string $versionA, string $versionB): bool
|
||||||
{
|
{
|
||||||
$versionANormalized = preg_replace('/[^\d]/', '', $versionA);
|
$versionANormalized = preg_replace('/[^\d]/', '', $versionA);
|
||||||
$versionBNormalized = preg_replace('/[^\d]/', '', $versionB);
|
$versionBNormalized = preg_replace('/[^\d]/', '', $versionB);
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ public function test_brew_can_be_resolved_from_container()
|
|||||||
public function test_installed_returns_true_when_given_formula_is_installed()
|
public function test_installed_returns_true_when_given_formula_is_installed()
|
||||||
{
|
{
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')
|
$cli->shouldReceive('runAsUser')->once()->with('brew info php@8.2 --json')
|
||||||
->andReturn('[{"name":"php@7.4","full_name":"php@7.4","aliases":[],"versioned_formulae":[],"versions":{"stable":"7.4.5"},"installed":[{"version":"7.4.5"}]}]');
|
->andReturn('[{"name":"php@8.2","full_name":"php@8.2","aliases":[],"versioned_formulae":[],"versions":{"stable":"8.2.5"},"installed":[{"version":"8.2.5"}]}]');
|
||||||
swap(CommandLine::class, $cli);
|
swap(CommandLine::class, $cli);
|
||||||
$this->assertTrue(resolve(Brew::class)->installed('php@7.4'));
|
$this->assertTrue(resolve(Brew::class)->installed('php@8.2'));
|
||||||
|
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
$cli->shouldReceive('runAsUser')->once()->with('brew info php --json')
|
$cli->shouldReceive('runAsUser')->once()->with('brew info php --json')
|
||||||
@@ -49,14 +49,14 @@ public function test_installed_returns_true_when_given_formula_is_installed()
|
|||||||
public function test_installed_returns_false_when_given_formula_is_not_installed()
|
public function test_installed_returns_false_when_given_formula_is_not_installed()
|
||||||
{
|
{
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')->andReturn('');
|
$cli->shouldReceive('runAsUser')->once()->with('brew info php@8.2 --json')->andReturn('');
|
||||||
swap(CommandLine::class, $cli);
|
swap(CommandLine::class, $cli);
|
||||||
$this->assertFalse(resolve(Brew::class)->installed('php@7.4'));
|
$this->assertFalse(resolve(Brew::class)->installed('php@8.2'));
|
||||||
|
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
$cli->shouldReceive('runAsUser')->once()->with('brew info php@7.4 --json')->andReturn('Error: No formula found');
|
$cli->shouldReceive('runAsUser')->once()->with('brew info php@8.2 --json')->andReturn('Error: No formula found');
|
||||||
swap(CommandLine::class, $cli);
|
swap(CommandLine::class, $cli);
|
||||||
$this->assertFalse(resolve(Brew::class)->installed('php@7.4'));
|
$this->assertFalse(resolve(Brew::class)->installed('php@8.2'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_has_installed_php_indicates_if_php_is_installed_via_brew()
|
public function test_has_installed_php_indicates_if_php_is_installed_via_brew()
|
||||||
@@ -78,27 +78,23 @@ public function test_has_installed_php_indicates_if_php_is_installed_via_brew()
|
|||||||
$this->assertTrue($brew->hasInstalledPhp());
|
$this->assertTrue($brew->hasInstalledPhp());
|
||||||
|
|
||||||
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
||||||
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.4']));
|
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@8.2']));
|
||||||
$this->assertTrue($brew->hasInstalledPhp());
|
$this->assertTrue($brew->hasInstalledPhp());
|
||||||
|
|
||||||
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
||||||
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.3']));
|
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@8.2']));
|
||||||
$this->assertTrue($brew->hasInstalledPhp());
|
$this->assertTrue($brew->hasInstalledPhp());
|
||||||
|
|
||||||
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
||||||
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php73']));
|
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@8.2', 'php82']));
|
||||||
$this->assertTrue($brew->hasInstalledPhp());
|
$this->assertTrue($brew->hasInstalledPhp());
|
||||||
|
|
||||||
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
||||||
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.2', 'php72']));
|
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php81', 'php@8.1']));
|
||||||
$this->assertTrue($brew->hasInstalledPhp());
|
$this->assertTrue($brew->hasInstalledPhp());
|
||||||
|
|
||||||
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
||||||
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php71', 'php@7.1']));
|
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@8.0']));
|
||||||
$this->assertTrue($brew->hasInstalledPhp());
|
|
||||||
|
|
||||||
$brew = Mockery::mock(Brew::class.'[installedPhpFormulae]', [new CommandLine, new Filesystem]);
|
|
||||||
$brew->shouldReceive('installedPhpFormulae')->andReturn(collect(['php@7.0']));
|
|
||||||
$this->assertTrue($brew->hasInstalledPhp());
|
$this->assertTrue($brew->hasInstalledPhp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,11 +102,11 @@ public function test_tap_taps_the_given_homebrew_repository()
|
|||||||
{
|
{
|
||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
$prefix = Brew::BREW_DISABLE_AUTO_CLEANUP;
|
$prefix = Brew::BREW_DISABLE_AUTO_CLEANUP;
|
||||||
|
$cli->shouldReceive('passthru')->once()->with($prefix.' sudo -u "'.user().'" brew tap php@8.2');
|
||||||
|
$cli->shouldReceive('passthru')->once()->with($prefix.' sudo -u "'.user().'" brew tap php@8.1');
|
||||||
$cli->shouldReceive('passthru')->once()->with($prefix.' sudo -u "'.user().'" brew tap php@8.0');
|
$cli->shouldReceive('passthru')->once()->with($prefix.' sudo -u "'.user().'" brew tap php@8.0');
|
||||||
$cli->shouldReceive('passthru')->once()->with($prefix.' sudo -u "'.user().'" brew tap php@7.1');
|
|
||||||
$cli->shouldReceive('passthru')->once()->with($prefix.' sudo -u "'.user().'" brew tap php@7.0');
|
|
||||||
swap(CommandLine::class, $cli);
|
swap(CommandLine::class, $cli);
|
||||||
resolve(Brew::class)->tap('php@8.0', 'php@7.1', 'php@7.0');
|
resolve(Brew::class)->tap('php@8.2', 'php@8.1', 'php@8.0');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_restart_restarts_the_service_using_homebrew_services()
|
public function test_restart_restarts_the_service_using_homebrew_services()
|
||||||
@@ -147,24 +143,24 @@ public function test_linked_php_returns_linked_php_formula_name()
|
|||||||
};
|
};
|
||||||
|
|
||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/7.4.0/test');
|
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/8.0.0/test');
|
||||||
$this->assertSame('php@7.4', $getBrewMock($files)->linkedPhp());
|
$this->assertSame('php@8.0', $getBrewMock($files)->linkedPhp());
|
||||||
|
|
||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/7.3.0/test');
|
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/8.1.0/test');
|
||||||
$this->assertSame('php@7.3', $getBrewMock($files)->linkedPhp());
|
$this->assertSame('php@8.1', $getBrewMock($files)->linkedPhp());
|
||||||
|
|
||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php@7.2/7.2.13/test');
|
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php@8.2/8.2.13/test');
|
||||||
$this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp());
|
$this->assertSame('php@8.2', $getBrewMock($files)->linkedPhp());
|
||||||
|
|
||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/7.2.9_2/test');
|
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php/8.2.9_2/test');
|
||||||
$this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp());
|
$this->assertSame('php@8.2', $getBrewMock($files)->linkedPhp());
|
||||||
|
|
||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php72/7.2.9_2/test');
|
$files->shouldReceive('readLink')->once()->with(BREW_PREFIX.'/bin/php')->andReturn('/test/path/php81/8.1.9_2/test');
|
||||||
$this->assertSame('php@7.2', $getBrewMock($files)->linkedPhp());
|
$this->assertSame('php@8.1', $getBrewMock($files)->linkedPhp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_linked_php_throws_exception_if_no_php_link()
|
public function test_linked_php_throws_exception_if_no_php_link()
|
||||||
@@ -401,8 +397,8 @@ public function test_get_linked_php_formula_will_return_linked_php_directory($pa
|
|||||||
public function test_restart_linked_php_will_pass_through_linked_php_formula_to_restart_service()
|
public function test_restart_linked_php_will_pass_through_linked_php_formula_to_restart_service()
|
||||||
{
|
{
|
||||||
$brewMock = Mockery::mock(Brew::class)->makePartial();
|
$brewMock = Mockery::mock(Brew::class)->makePartial();
|
||||||
$brewMock->shouldReceive('getLinkedPhpFormula')->once()->andReturn('php@7.2-test');
|
$brewMock->shouldReceive('getLinkedPhpFormula')->once()->andReturn('php@8.2-test');
|
||||||
$brewMock->shouldReceive('restartService')->once()->with('php@7.2-test');
|
$brewMock->shouldReceive('restartService')->once()->with('php@8.2-test');
|
||||||
$brewMock->restartLinkedPhp();
|
$brewMock->restartLinkedPhp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,9 +410,9 @@ public function test_it_can_get_php_binary_path_from_php_version()
|
|||||||
$files = Mockery::mock(Filesystem::class),
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@7.4/bin/php')->andReturn(true);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@8.2/bin/php')->andReturn(true);
|
||||||
$files->shouldNotReceive('exists')->with(BREW_PREFIX.'/opt/php@74/bin/php');
|
$files->shouldNotReceive('exists')->with(BREW_PREFIX.'/opt/php@82/bin/php');
|
||||||
$this->assertEquals(BREW_PREFIX.'/opt/php@7.4/bin/php', $brewMock->getPhpExecutablePath('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/opt/php@8.2/bin/php', $brewMock->getPhpExecutablePath('php@8.2'));
|
||||||
|
|
||||||
// Check the `/opt/homebrew/opt/php71/bin/php` location for older installations
|
// Check the `/opt/homebrew/opt/php71/bin/php` location for older installations
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
@@ -424,9 +420,9 @@ public function test_it_can_get_php_binary_path_from_php_version()
|
|||||||
$files = Mockery::mock(Filesystem::class),
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@7.4/bin/php')->andReturn(false);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@8.2/bin/php')->andReturn(false);
|
||||||
$files->shouldReceive('exists')->with(BREW_PREFIX.'/opt/php74/bin/php')->andReturn(true);
|
$files->shouldReceive('exists')->with(BREW_PREFIX.'/opt/php82/bin/php')->andReturn(true);
|
||||||
$this->assertEquals(BREW_PREFIX.'/opt/php74/bin/php', $brewMock->getPhpExecutablePath('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/opt/php82/bin/php', $brewMock->getPhpExecutablePath('php@8.2'));
|
||||||
|
|
||||||
// When the default PHP is the version we are looking for
|
// When the default PHP is the version we are looking for
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
@@ -434,11 +430,11 @@ public function test_it_can_get_php_binary_path_from_php_version()
|
|||||||
$files = Mockery::mock(Filesystem::class),
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@7.4/bin/php')->andReturn(false);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@8.2/bin/php')->andReturn(false);
|
||||||
$files->shouldReceive('exists')->with(BREW_PREFIX.'/opt/php74/bin/php')->andReturn(false);
|
$files->shouldReceive('exists')->with(BREW_PREFIX.'/opt/php82/bin/php')->andReturn(false);
|
||||||
$files->shouldReceive('isLink')->with(BREW_PREFIX.'/opt/php')->andReturn(true);
|
$files->shouldReceive('isLink')->with(BREW_PREFIX.'/opt/php')->andReturn(true);
|
||||||
$files->shouldReceive('readLink')->with(BREW_PREFIX.'/opt/php')->andReturn('../Cellar/php@7.4/7.4.13/bin/php');
|
$files->shouldReceive('readLink')->with(BREW_PREFIX.'/opt/php')->andReturn('../Cellar/php@8.2/8.2.13/bin/php');
|
||||||
$this->assertEquals(BREW_PREFIX.'/opt/php/bin/php', $brewMock->getPhpExecutablePath('php@7.4'));
|
$this->assertEquals(BREW_PREFIX.'/opt/php/bin/php', $brewMock->getPhpExecutablePath('php@8.2'));
|
||||||
|
|
||||||
// When the default PHP is not the version we are looking for
|
// When the default PHP is not the version we are looking for
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
@@ -446,11 +442,11 @@ public function test_it_can_get_php_binary_path_from_php_version()
|
|||||||
$files = Mockery::mock(Filesystem::class),
|
$files = Mockery::mock(Filesystem::class),
|
||||||
])->makePartial();
|
])->makePartial();
|
||||||
|
|
||||||
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@7.4/bin/php')->andReturn(false);
|
$files->shouldReceive('exists')->once()->with(BREW_PREFIX.'/opt/php@8.2/bin/php')->andReturn(false);
|
||||||
$files->shouldReceive('exists')->with(BREW_PREFIX.'/opt/php74/bin/php')->andReturn(false);
|
$files->shouldReceive('exists')->with(BREW_PREFIX.'/opt/php82/bin/php')->andReturn(false);
|
||||||
$files->shouldReceive('isLink')->with(BREW_PREFIX.'/opt/php')->andReturn(true);
|
$files->shouldReceive('isLink')->with(BREW_PREFIX.'/opt/php')->andReturn(true);
|
||||||
$files->shouldReceive('readLink')->with(BREW_PREFIX.'/opt/php')->andReturn('../Cellar/php@8.1/8.1.13/bin/php');
|
$files->shouldReceive('readLink')->with(BREW_PREFIX.'/opt/php')->andReturn('../Cellar/php@8.1/8.1.13/bin/php');
|
||||||
$this->assertEquals(BREW_PREFIX.'/bin/php', $brewMock->getPhpExecutablePath('php@7.4')); // Could not find a version, so retuned the default binary
|
$this->assertEquals(BREW_PREFIX.'/bin/php', $brewMock->getPhpExecutablePath('php@8.2')); // Could not find a version, so retuned the default binary
|
||||||
|
|
||||||
// When no PHP Version is provided
|
// When no PHP Version is provided
|
||||||
$brewMock = Mockery::mock(Brew::class, [
|
$brewMock = Mockery::mock(Brew::class, [
|
||||||
@@ -463,12 +459,12 @@ public function test_it_can_get_php_binary_path_from_php_version()
|
|||||||
|
|
||||||
public function test_it_can_compare_two_php_versions()
|
public function test_it_can_compare_two_php_versions()
|
||||||
{
|
{
|
||||||
$this->assertTrue(resolve(Brew::class)->arePhpVersionsEqual('php71', 'php@7.1'));
|
$this->assertTrue(resolve(Brew::class)->arePhpVersionsEqual('php81', 'php@8.1'));
|
||||||
$this->assertTrue(resolve(Brew::class)->arePhpVersionsEqual('php71', 'php@71'));
|
$this->assertTrue(resolve(Brew::class)->arePhpVersionsEqual('php81', 'php@81'));
|
||||||
$this->assertTrue(resolve(Brew::class)->arePhpVersionsEqual('php71', '71'));
|
$this->assertTrue(resolve(Brew::class)->arePhpVersionsEqual('php81', '81'));
|
||||||
|
|
||||||
$this->assertFalse(resolve(Brew::class)->arePhpVersionsEqual('php71', 'php@70'));
|
$this->assertFalse(resolve(Brew::class)->arePhpVersionsEqual('php81', 'php@80'));
|
||||||
$this->assertFalse(resolve(Brew::class)->arePhpVersionsEqual('php71', '72'));
|
$this->assertFalse(resolve(Brew::class)->arePhpVersionsEqual('php81', '82'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -480,59 +476,59 @@ public function supportedPhpLinkPathProvider()
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'/test/path/php/7.4.0/test', // linked path
|
'/test/path/php/8.2.0/test', // linked path
|
||||||
[ // matches
|
[ // matches
|
||||||
'path/php/7.4.0/test',
|
'path/php/8.2.0/test',
|
||||||
'php',
|
'php',
|
||||||
'',
|
'',
|
||||||
'7.4',
|
'8.2',
|
||||||
'.0',
|
'.0',
|
||||||
],
|
],
|
||||||
'php', // expected link formula
|
'php', // expected link formula
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'/test/path/php@7.4/7.4.13/test',
|
'/test/path/php@8.2/8.2.13/test',
|
||||||
[
|
[
|
||||||
'path/php@7.4/7.4.13/test',
|
'path/php@8.2/8.2.13/test',
|
||||||
'php',
|
'php',
|
||||||
'@7.4',
|
'@8.2',
|
||||||
'7.4',
|
'8.2',
|
||||||
'.13',
|
'.13',
|
||||||
],
|
],
|
||||||
'php@7.4',
|
'php@8.2',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'/test/path/php/7.4.9_2/test',
|
'/test/path/php/8.2.9_2/test',
|
||||||
[
|
[
|
||||||
'path/php/7.4.9_2/test',
|
'path/php/8.2.9_2/test',
|
||||||
'php',
|
'php',
|
||||||
'',
|
'',
|
||||||
'7.4',
|
'8.2',
|
||||||
'.9_2',
|
'.9_2',
|
||||||
],
|
],
|
||||||
'php',
|
'php',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'/test/path/php74/7.4.9_2/test',
|
'/test/path/php82/8.2.9_2/test',
|
||||||
[
|
[
|
||||||
'path/php74/7.4.9_2/test',
|
'path/php82/8.2.9_2/test',
|
||||||
'php',
|
'php',
|
||||||
'74',
|
'82',
|
||||||
'7.4',
|
'8.2',
|
||||||
'.9_2',
|
'.9_2',
|
||||||
],
|
],
|
||||||
'php74',
|
'php82',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'/test/path/php71/test',
|
'/test/path/php81/test',
|
||||||
[
|
[
|
||||||
'path/php71/test',
|
'path/php81/test',
|
||||||
'php',
|
'php',
|
||||||
'71',
|
'81',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
],
|
],
|
||||||
'php71',
|
'php81',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user