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

Merge remote-tracking branch 'upstream/master' into feat/proxy-multiple-domains

This commit is contained in:
Robert Boes
2023-10-02 15:49:35 +02:00
36 changed files with 379 additions and 237 deletions

View File

@@ -5,6 +5,7 @@
use Valet\Brew;
use Valet\CommandLine;
use Valet\Filesystem;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;

View File

@@ -11,9 +11,11 @@
use Valet\Ngrok;
use Valet\PhpFpm;
use Valet\Site as RealSite;
use function Valet\swap;
use Valet\Valet;
use function Valet\resolve;
use function Valet\swap;
/**
* @requires PHP >= 8.0
*/
@@ -253,6 +255,70 @@ public function test_link_command_with_secure_flag_secures()
$this->assertStringContainsString('site has been secured', $tester->getDisplay());
}
public function test_link_command_with_isolate_flag_isolates()
{
[$app, $tester] = $this->appAndTester();
$cwd = getcwd();
$name = 'tighten';
$host = $name.'.test';
$customPhpVersion = '82';
$phpRcVersion = '8.2';
$fullPhpVersion = 'php@8.2';
$brewMock = Mockery::mock(Brew::class);
$nginxMock = Mockery::mock(Nginx::class);
$siteMock = Mockery::mock(RealSite::class);
$phpFpmMock = Mockery::mock(PhpFpm::class, [
$brewMock,
resolve(CommandLine::class),
resolve(Filesystem::class),
resolve(RealConfiguration::class),
$siteMock,
$nginxMock,
])->makePartial();
swap(Brew::class, $brewMock);
swap(Nginx::class, $nginxMock);
swap(PhpFpm::class, $phpFpmMock);
swap(RealSite::class, $siteMock);
$brewMock->shouldReceive('supportedPhpVersions')->andReturn(collect([
'php@8.2',
'php@8.1',
]));
$brewMock->shouldReceive('ensureInstalled')->with($fullPhpVersion, [], $phpFpmMock->taps);
$brewMock->shouldReceive('installed')->with($fullPhpVersion);
$brewMock->shouldReceive('determineAliasedVersion')->with($fullPhpVersion)->andReturn($fullPhpVersion);
$siteMock->shouldReceive('link')->with($cwd, $name)->once();
$siteMock->shouldReceive('getSiteUrl')->with($name)->andReturn($host);
$siteMock->shouldReceive('phpRcVersion')->with($name, $cwd)->andReturn($phpRcVersion);
$siteMock->shouldReceive('customPhpVersion')->with($host)->andReturn($customPhpVersion);
$siteMock->shouldReceive('isolate')->with($host, $fullPhpVersion);
$phpFpmMock->shouldReceive('stopIfUnused')->with($customPhpVersion)->once();
$phpFpmMock->shouldReceive('createConfigurationFiles')->with($fullPhpVersion)->once();
$phpFpmMock->shouldReceive('restart')->with($fullPhpVersion)->once();
$nginxMock->shouldReceive('restart')->once();
// These should only run when doing global PHP switches
$brewMock->shouldNotReceive('stopService');
$brewMock->shouldNotReceive('link');
$brewMock->shouldNotReceive('unlink');
$phpFpmMock->shouldNotReceive('stopRunning');
$phpFpmMock->shouldNotReceive('install');
$tester->run(['command' => 'link', 'name' => 'tighten', '--isolate' => true]);
$tester->assertCommandIsSuccessful();
$this->assertStringContainsString('is now using '.$fullPhpVersion, $tester->getDisplay());
}
public function test_links_command()
{
[$app, $tester] = $this->appAndTester();
@@ -776,7 +842,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()
@@ -809,6 +875,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();

View File

@@ -3,6 +3,7 @@
use Illuminate\Container\Container;
use Valet\CommandLine;
use Valet\Composer;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;

View File

@@ -4,10 +4,11 @@
use Valet\Brew;
use Valet\Configuration;
use Valet\Filesystem;
use Valet\Valet;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;
use Valet\Valet;
class ConfigurationTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase
{

View File

@@ -6,6 +6,7 @@
use Valet\Configuration;
use Valet\DnsMasq;
use Valet\Filesystem;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;

View File

@@ -0,0 +1,31 @@
<?php
use Valet\Drivers\Specific\StatamicV2ValetDriver;
class StatamicV2ValetDriverTest extends BaseDriverTestCase
{
public function test_it_serves_statamic_projects()
{
$driver = new StatamicV2ValetDriver();
$this->assertTrue($driver->serves($this->projectDir('statamicv2'), 'my-site', '/'));
}
public function test_it_doesnt_serve_non_statamic_projects()
{
$driver = new StatamicV2ValetDriver();
$this->assertFalse($driver->serves($this->projectDir('public-with-index-non-laravel'), 'my-site', '/'));
}
public function test_it_gets_front_controller()
{
$driver = new StatamicV2ValetDriver();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/about/';
$projectPath = $this->projectDir('statamicv2');
$this->assertEquals($projectPath.'/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/'));
}
}

View File

@@ -11,21 +11,38 @@ public function test_it_serves_statamic_projects()
$this->assertTrue($driver->serves($this->projectDir('statamic'), 'my-site', '/'));
}
public function test_it_doesnt_serve_non_statamic_projects()
public function test_it_doesnt_serve_non_statamic_projects_with_public_directory()
{
$driver = new StatamicValetDriver();
$this->assertFalse($driver->serves($this->projectDir('public-with-index-non-laravel'), 'my-site', '/'));
}
public function test_it_doesnt_serve_laravel_projects()
{
$driver = new StatamicValetDriver();
$this->assertFalse($driver->serves($this->projectDir('laravel'), 'my-site', '/'));
}
public function test_it_gets_front_controller()
{
$driver = new StatamicValetDriver();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/about/';
$projectPath = $this->projectDir('statamic');
$this->assertEquals($projectPath.'/public/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/'));
}
$projectPath = $this->projectDir('statamicv1');
$this->assertEquals($projectPath.'/index.php', $driver->frontControllerPath($projectPath, 'my-site', '/'));
public function test_it_serves_statically_cached_pages()
{
$driver = new StatamicValetDriver();
$projectPath = $this->projectDir('statamic');
$_SERVER['REQUEST_URI'] = '/test';
$this->assertEquals($projectPath.'/public/static/test_.html', $driver->frontControllerPath($projectPath, 'my-site', '/test'));
$_SERVER['REQUEST_URI'] = '/test?foo=bar&baz=qux';
$this->assertEquals($projectPath.'/public/static/test_foo=bar&baz=qux.html', $driver->frontControllerPath($projectPath, 'my-site', '/test'));
}
}

View File

@@ -30,6 +30,15 @@ public function test_it_prioritizes_non_basic_matches()
$this->assertNotEquals('Valet\Drivers\BasicValetDriver', get_class($assignedDriver));
}
public function test_it_prioritizes_statamic()
{
$assignedDriver = ValetDriver::assign($this->projectDir('statamic'), 'my-site', '/');
$this->assertEquals('Valet\Drivers\Specific\StatamicValetDriver', get_class($assignedDriver));
$assignedDriver = ValetDriver::assign($this->projectDir('laravel'), 'my-site', '/');
$this->assertEquals('Valet\Drivers\LaravelValetDriver', get_class($assignedDriver));
}
public function test_it_checks_composer_dependencies()
{
$driver = new BasicValetDriver;

View File

View File

@@ -4,8 +4,9 @@
use Valet\Configuration;
use Valet\Filesystem;
use Valet\Nginx;
use function Valet\resolve;
use Valet\Site;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;

View File

@@ -2,6 +2,7 @@
use Illuminate\Container\Container;
use Valet\Ngrok;
use function Valet\resolve;
use function Valet\user;

View File

@@ -7,8 +7,9 @@
use Valet\Filesystem;
use Valet\Nginx;
use Valet\PhpFpm;
use function Valet\resolve;
use Valet\Site;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;

View File

@@ -2,6 +2,7 @@
use Illuminate\Container\Container;
use Valet\Server;
use function Valet\user;
class ServerTest extends Yoast\PHPUnitPolyfills\TestCases\TestCase

View File

@@ -5,8 +5,9 @@
use Valet\CommandLine;
use Valet\Configuration;
use Valet\Filesystem;
use function Valet\resolve;
use Valet\Site;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;

View File

@@ -2,8 +2,9 @@
use Illuminate\Container\Container;
use Valet\CommandLine;
use function Valet\resolve;
use Valet\Status;
use function Valet\resolve;
use function Valet\swap;
use function Valet\user;