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

add more tests for new methods and bits of clean up

This commit is contained in:
James Barnard
2019-01-19 23:31:57 +00:00
committed by Matt Stauffer
parent 25c4fab2b4
commit 6158e5129b
5 changed files with 121 additions and 27 deletions

View File

@@ -2,7 +2,6 @@
namespace Valet;
use Exception;
use DomainException;
class Brew
@@ -292,33 +291,32 @@ function ($exitCode, $errorOutput) use ($formula) {
* Search for a formula and return found, optional grep to filter results
*
* @param $formula
* @param null $grep
*
* @return string
* @return \Illuminate\Support\Collection
*/
function search($formula, $grep = null) {
return str_replace(PHP_EOL, '', $this->cli->runAsUser(
sprintf('brew search %s%s', $formula, $grep ? ' | grep ' . $grep : ''),
function search($formula) {
return collect(explode(PHP_EOL, $this->cli->runAsUser(
sprintf('brew search %s', $formula),
function ($exitCode, $errorOutput) use ($formula) {
output($errorOutput);
throw new DomainException('Brew was unable to find [' . $formula . '].');
}
));
)))->filter(function ($formulaFound) {
// Filter out empty and search category headers
return $formulaFound && !in_array($formulaFound, ['==> Formulae', '==> Casks']);
});
}
/**
* Get the currently running brew services
*
* @param null $grep
* @return \Illuminate\Support\Collection
*/
function getRunningServices($grep = null)
function getRunningServices()
{
$grep = 'started' . ($grep ? '.*' . $grep : '');
return collect(array_filter(explode(PHP_EOL, $this->cli->runAsUser(
sprintf('brew services list | grep %s | awk \'{ print $1; }\'', $grep),
'brew services list | grep started | awk \'{ print $1; }\'',
function ($exitCode, $errorOutput) {
output($errorOutput);

View File

@@ -2,9 +2,7 @@
namespace Valet;
use Exception;
use DomainException;
use Symfony\Component\Process\Process;
class PhpFpm
{
@@ -127,19 +125,32 @@ function fpmConfigPath()
function stopRunning()
{
$this->brew->stopService(
$this->brew->getRunningServices('php')->all()
$this->brew->getRunningServices()
->filter(function ($service) {
return substr($service, 0, 3) === 'php';
})
->all()
);
}
/**
* Use a specific version of php
*
* @param $version
*/
function useVersion($version)
{
// Ensure we have php{version}
// Ensure we have php prefixed
if (substr($version, 0, 3) !== 'php') {
$version = 'php' . $version;
}
info(sprintf('Finding brew formula for: %s', $version));
$foundVersion = $this->brew->search($version, 'php');
$foundVersion = $this->brew->search($version)
->filter(function ($service) {
return $this->brew->supportedPhpVersions()->contains($service);
})
->first();
info(sprintf('Found brew formula: %s', $foundVersion));
if (!$this->brew->supportedPhpVersions()->contains($foundVersion)) {

View File

@@ -277,9 +277,9 @@
})->descriptions('Add sudoers files for Brew and Valet to make Valet commands run without passwords');
/**
* Allow the user to use another version of php
* Allow the user to change the version of php valet uses
*/
$app->command('use phpVersion', function ($phpVersion = null) {
$app->command('use phpVersion', function ($phpVersion) {
PhpFpm::stopRunning();
PhpFpm::useVersion($phpVersion);
@@ -287,7 +287,7 @@
Nginx::restart();
info(sprintf('Valet is now using %s.', $phpVersion));
})->descriptions('Change the version of php used by valet', [
'phpVersion' => 'The PHP version you want to use, e.g php72',
'phpVersion' => 'The PHP version you want to use, e.g php@7.2',
]);
}