1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 08:10:07 +01:00
Files
laravel-valet/tests/NginxTest.php
Chris Brown 58e4645fe2 Change valet domain command to valet tld
Fixes #144
".test" or ".dev" is really a TLD, not a "domain" in the conventional sense.
Changing the command to `valet tld` more accurately reflects the purpose of the command (to set or get the configured TLD served by Valet)

The use of `valet domain` is currently preserved as an alias for `valet tld`, but will be removed at a later date.
2017-10-17 15:47:39 -04:00

91 lines
3.0 KiB
PHP

<?php
use Valet\Site;
use Valet\Nginx;
use Valet\Filesystem;
use Valet\Configuration;
use Illuminate\Container\Container;
class NginxTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
{
Mockery::close();
}
public function test_install_nginx_configuration_places_nginx_base_configuration_in_proper_location()
{
$files = Mockery::mock(Filesystem::class.'[putAsUser]');
$files->shouldReceive('putAsUser')->andReturnUsing(function ($path, $contents) {
$this->assertSame('/usr/local/etc/nginx/nginx.conf', $path);
$this->assertTrue(strpos($contents, 'include '.VALET_HOME_PATH.'/Nginx/*') !== false);
})->once();
swap(Filesystem::class, $files);
$nginx = resolve(Nginx::class);
$nginx->installConfiguration();
}
public function test_install_caddy_directories_creates_location_for_site_specific_configuration()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isDir')->with(VALET_HOME_PATH.'/Nginx')->andReturn(false);
$files->shouldReceive('mkdirAsUser')->with(VALET_HOME_PATH.'/Nginx')->once();
$files->shouldReceive('putAsUser')->with(VALET_HOME_PATH.'/Nginx/.keep', "\n")->once();
swap(Filesystem::class, $files);
swap(Configuration::class, Mockery::spy(Configuration::class));
swap(Site::class, Mockery::spy(Site::class));
$nginx = resolve(Nginx::class);
$nginx->installNginxDirectory();
}
public function test_nginx_directory_is_never_created_if_it_already_exists()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isDir')->with(VALET_HOME_PATH.'/Nginx')->andReturn(true);
$files->shouldReceive('mkdirAsUser')->never();
$files->shouldReceive('putAsUser')->with(VALET_HOME_PATH.'/Nginx/.keep', "\n")->once();
swap(Filesystem::class, $files);
swap(Configuration::class, Mockery::spy(Configuration::class));
swap(Site::class, Mockery::spy(Site::class));
$nginx = resolve(Nginx::class);
$nginx->installNginxDirectory();
}
public function test_install_nginx_directories_rewrites_secure_nginx_files()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('isDir')->with(VALET_HOME_PATH.'/Nginx')->andReturn(false);
$files->shouldReceive('mkdirAsUser')->with(VALET_HOME_PATH.'/Nginx')->once();
$files->shouldReceive('putAsUser')->with(VALET_HOME_PATH.'/Nginx/.keep', "\n")->once();
swap(Filesystem::class, $files);
swap(Configuration::class, $config = Mockery::spy(Configuration::class, ['read' => ['tld' => 'test']]));
swap(Site::class, $site = Mockery::spy(Site::class));
$nginx = resolve(Nginx::class);
$nginx->installNginxDirectory();
$site->shouldHaveReceived('resecureForNewTld', ['test', 'test']);
}
}