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

Merge pull request #891 from drbyte/dnsmasq-gc

Cleanup old tld refs when switching tld or uninstalling
This commit is contained in:
Matt Stauffer
2020-01-07 11:35:55 -05:00
committed by GitHub
2 changed files with 9 additions and 11 deletions

View File

@@ -2,12 +2,9 @@
namespace Valet;
use Exception;
use Symfony\Component\Process\Process;
class DnsMasq
{
var $brew, $cli, $files;
var $brew, $cli, $files, $configuration;
var $dnsmasqMasterConfigFile = '/usr/local/etc/dnsmasq.conf';
var $dnsmasqSystemConfDir = '/usr/local/etc/dnsmasq.d';
@@ -15,17 +12,13 @@ class DnsMasq
/**
* Create a new DnsMasq instance.
*
* @param Brew $brew
* @param CommandLine $cli
* @param Filesystem $files
* @return void
*/
function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
function __construct(Brew $brew, CommandLine $cli, Filesystem $files, Configuration $configuration)
{
$this->cli = $cli;
$this->brew = $brew;
$this->files = $files;
$this->configuration = $configuration;
}
/**
@@ -61,6 +54,8 @@ function uninstall()
$this->brew->stopService('dnsmasq');
$this->brew->uninstallFormula('dnsmasq');
$this->cli->run('rm -rf /usr/local/etc/dnsmasq.d/dnsmasq-valet.conf');
$tld = $this->configuration->read()['tld'];
$this->files->unlink($this->resolverPath.'/'.$tld);
}
/**
@@ -145,6 +140,7 @@ function createTldResolver($tld)
function updateTld($oldTld, $newTld)
{
$this->files->unlink($this->resolverPath.'/'.$oldTld);
$this->files->unlink($this->dnsmasqUserConfigDir() . 'tld-' . $oldTld . '.conf');
$this->install($newTld);
}

View File

@@ -4,6 +4,7 @@
use Valet\DnsMasq;
use Valet\Filesystem;
use Valet\CommandLine;
use Valet\Configuration;
use function Valet\user;
use function Valet\resolve;
use function Valet\swap;
@@ -60,7 +61,8 @@ public function test_update_tld_removes_old_resolver_and_reinstalls()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('quietly')->with('rm /etc/resolver/old');
$dnsMasq = Mockery::mock(DnsMasq::class.'[install]', [resolve(Brew::class), $cli, new Filesystem]);
swap(Configuration::class, $config = Mockery::spy(Configuration::class, ['read' => ['tld' => 'test']]));
$dnsMasq = Mockery::mock(DnsMasq::class.'[install]', [resolve(Brew::class), $cli, new Filesystem, $config]);
$dnsMasq->shouldReceive('install')->with('new');
$dnsMasq->updateTld('old', 'new');
}