1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 00:20:08 +01:00
Files
laravel-valet/tests/DnsMasqTest.php
Chris Brown 02ad7f44ff Dnsmasq allows use of a common config folder, much like nginx and php do.
This PR changes Valet's default config process to empower this feature, which makes installation less intrusive, and easier to identify and remove valet-specific customizations.

This will make for easier troubleshooting
... and easier customizing (such as dropping in a custom logging config, additional TLDs, alternate DNS resolvers, etc)

Also removes old dnsmasq configs used by prior Valet versions
2019-12-02 15:02:56 -05:00

77 lines
2.3 KiB
PHP

<?php
use Valet\Brew;
use Valet\DnsMasq;
use Valet\Filesystem;
use Valet\CommandLine;
use function Valet\user;
use function Valet\resolve;
use function Valet\swap;
use Illuminate\Container\Container;
class DnsMasqTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
{
exec('rm -rf '.__DIR__.'/output');
mkdir(__DIR__.'/output');
touch(__DIR__.'/output/.gitkeep');
Mockery::close();
}
public function test_install_installs_and_places_configuration_files_in_proper_locations()
{
$brew = Mockery::mock(Brew::class);
$brew->shouldReceive('ensureInstalled')->once()->with('dnsmasq');
$brew->shouldReceive('restartService')->once()->with('dnsmasq');
swap(Brew::class, $brew);
$dnsMasq = resolve(StubForCreatingCustomDnsMasqConfigFiles::class);
$dnsMasq->dnsmasqMasterConfigFile = __DIR__.'/output/dnsmasq.conf';
$dnsMasq->dnsmasqSystemConfDir = __DIR__.'/output/dnsmasq.d';
$dnsMasq->resolverPath = __DIR__.'/output/resolver';
file_put_contents($dnsMasq->dnsmasqMasterConfigFile, file_get_contents(__DIR__.'/files/dnsmasq.conf'));
$dnsMasq->install('test');
$this->assertSame('nameserver 127.0.0.1'.PHP_EOL, file_get_contents(__DIR__.'/output/resolver/test'));
$this->assertSame('address=/.test/127.0.0.1'.PHP_EOL.'listen-address=127.0.0.1'.PHP_EOL, file_get_contents(__DIR__.'/output/tld-test.conf'));
$this->assertSame('test-contents
' . PHP_EOL . 'conf-dir=/usr/local/etc/dnsmasq.d/,*.conf' . PHP_EOL,
file_get_contents($dnsMasq->dnsmasqMasterConfigFile)
);
}
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]);
$dnsMasq->shouldReceive('install')->with('new');
$dnsMasq->updateTld('old', 'new');
}
}
class StubForCreatingCustomDnsMasqConfigFiles extends DnsMasq
{
public function dnsmasqUserConfigDir()
{
return __DIR__.'/output/';
}
}