Skip to content

Commit

Permalink
Merge pull request #1422 from drbyte/stopdnsmasq
Browse files Browse the repository at this point in the history
Add "valet stop dnsmasq" option
  • Loading branch information
mattstauffer authored Aug 27, 2023
2 parents 2af8aba + 269d157 commit 088667d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cli/Valet/DnsMasq.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function uninstall(): void
}
}

/**
* Stop the dnsmasq service.
*/
public function stop(): void
{
$this->brew->stopService(['dnsmasq']);
}

/**
* Tell Homebrew to restart dnsmasq.
*/
Expand Down
2 changes: 2 additions & 0 deletions cli/Valet/PhpFpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function restart(string $phpVersion = null): void
*/
public function stop(): void
{
info('Stopping phpfpm...');
call_user_func_array(
[$this->brew, 'stopService'],
Brew::SUPPORTED_PHP_VERSIONS
Expand All @@ -138,6 +139,7 @@ public function fpmConfigPath(string $phpVersion = null): string
*/
public function stopRunning(): void
{
info('Stopping phpfpm...');
$this->brew->stopService(
$this->brew->getAllRunningServices()
->filter(function ($service) {
Expand Down
14 changes: 12 additions & 2 deletions cli/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,13 @@ function (ConsoleCommandEvent $event) {
PhpFpm::stopRunning();
Nginx::stop();

return info('Valet services have been stopped.');
return info('Valet core services have been stopped. To also stop dnsmasq, run: valet stop dnsmasq');
case 'all':
PhpFpm::stopRunning();
Nginx::stop();
Dnsmasq::stop();

return info('All Valet services have been stopped.');
case 'nginx':
Nginx::stop();

Expand All @@ -515,10 +521,14 @@ function (ConsoleCommandEvent $event) {
PhpFpm::stopRunning();

return info('PHP has been stopped.');
case 'dnsmasq':
Dnsmasq::stop();

return info('dnsmasq has been stopped.');
}

return warning(sprintf('Invalid valet service name [%s]', $service));
})->descriptions('Stop the Valet services');
})->descriptions('Stop the core Valet services, or all services by specifying "all".');

/**
* Uninstall Valet entirely. Requires --force to actually remove; otherwise manual instructions are displayed.
Expand Down
17 changes: 16 additions & 1 deletion tests/CliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public function test_stop_command()
$tester->run(['command' => 'stop']);
$tester->assertCommandIsSuccessful();

$this->assertStringContainsString('Valet services have been stopped.', $tester->getDisplay());
$this->assertStringContainsString('Valet core services have been stopped.', $tester->getDisplay());
}

public function test_stop_command_stops_nginx()
Expand Down Expand Up @@ -792,6 +792,21 @@ public function test_stop_command_stops_php()
$this->assertStringContainsString('PHP has been stopped', $tester->getDisplay());
}

public function test_stop_all_command_stops_dnsmasq()
{
[$app, $tester] = $this->appAndTester();

$phpfpm = Mockery::mock(DnsMasq::class);
$phpfpm->shouldReceive('stop');

swap(DnsMasq::class, $phpfpm);

$tester->run(['command' => 'stop', 'service' => 'dnsmasq']);
$tester->assertCommandIsSuccessful();

$this->assertStringContainsString('dnsmasq has been stopped', $tester->getDisplay());
}

public function test_stop_command_handles_bad_services()
{
[$app, $tester] = $this->appAndTester();
Expand Down

0 comments on commit 088667d

Please sign in to comment.