From b2878a6d1ad2af6fbbfa74fad052ee64a6ef8ad2 Mon Sep 17 00:00:00 2001 From: Adam Lavin Date: Wed, 23 Nov 2016 21:52:56 +0000 Subject: [PATCH] Update brew list to use runAsUser instead of directly sudoing --- cli/Valet/Brew.php | 2 +- tests/BrewTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/Valet/Brew.php b/cli/Valet/Brew.php index da14ebc..2f4ccab 100644 --- a/cli/Valet/Brew.php +++ b/cli/Valet/Brew.php @@ -30,7 +30,7 @@ function __construct(CommandLine $cli, Filesystem $files) */ function installed($formula) { - return in_array($formula, explode(PHP_EOL, $this->cli->run('sudo -u '.user().' brew list | grep '.$formula))); + return in_array($formula, explode(PHP_EOL, $this->cli->runAsUser('brew list | grep '.$formula))); } /** diff --git a/tests/BrewTest.php b/tests/BrewTest.php index 5cc2446..e2fc34f 100644 --- a/tests/BrewTest.php +++ b/tests/BrewTest.php @@ -30,12 +30,12 @@ public function test_brew_can_be_resolved_from_container() public function test_installed_returns_true_when_given_formula_is_installed() { $cli = Mockery::mock(CommandLine::class); - $cli->shouldReceive('run')->once()->with('sudo -u '.user().' brew list | grep php70')->andReturn('php70'); + $cli->shouldReceive('runAsUser')->once()->with('brew list | grep php70')->andReturn('php70'); swap(CommandLine::class, $cli); $this->assertTrue(resolve(Brew::class)->installed('php70')); $cli = Mockery::mock(CommandLine::class); - $cli->shouldReceive('run')->once()->with('sudo -u '.user().' brew list | grep php70')->andReturn('php70-mcrypt + $cli->shouldReceive('runAsUser')->once()->with('brew list | grep php70')->andReturn('php70-mcrypt php70'); swap(CommandLine::class, $cli); $this->assertTrue(resolve(Brew::class)->installed('php70')); @@ -45,17 +45,17 @@ public function test_installed_returns_true_when_given_formula_is_installed() public function test_installed_returns_false_when_given_formula_is_not_installed() { $cli = Mockery::mock(CommandLine::class); - $cli->shouldReceive('run')->once()->with('sudo -u '.user().' brew list | grep php70')->andReturn(''); + $cli->shouldReceive('runAsUser')->once()->with('brew list | grep php70')->andReturn(''); swap(CommandLine::class, $cli); $this->assertFalse(resolve(Brew::class)->installed('php70')); $cli = Mockery::mock(CommandLine::class); - $cli->shouldReceive('run')->once()->with('sudo -u '.user().' brew list | grep php70')->andReturn('php70-mcrypt'); + $cli->shouldReceive('runAsUser')->once()->with('brew list | grep php70')->andReturn('php70-mcrypt'); swap(CommandLine::class, $cli); $this->assertFalse(resolve(Brew::class)->installed('php70')); $cli = Mockery::mock(CommandLine::class); - $cli->shouldReceive('run')->once()->with('sudo -u '.user().' brew list | grep php70')->andReturn('php70-mcrypt + $cli->shouldReceive('runAsUser')->once()->with('brew list | grep php70')->andReturn('php70-mcrypt php70-something-else php7'); swap(CommandLine::class, $cli);