mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 16:40:05 +01:00
Merge pull request #1229 from electricpulp/master
Add PHP version to `valet links` output table
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
class Site
|
class Site
|
||||||
{
|
{
|
||||||
|
public $brew;
|
||||||
public $config;
|
public $config;
|
||||||
public $cli;
|
public $cli;
|
||||||
public $files;
|
public $files;
|
||||||
@@ -14,12 +15,14 @@ class Site
|
|||||||
/**
|
/**
|
||||||
* Create a new Site instance.
|
* Create a new Site instance.
|
||||||
*
|
*
|
||||||
|
* @param Brew $brew
|
||||||
* @param Configuration $config
|
* @param Configuration $config
|
||||||
* @param CommandLine $cli
|
* @param CommandLine $cli
|
||||||
* @param Filesystem $files
|
* @param Filesystem $files
|
||||||
*/
|
*/
|
||||||
public function __construct(Configuration $config, CommandLine $cli, Filesystem $files)
|
public function __construct(Brew $brew, Configuration $config, CommandLine $cli, Filesystem $files)
|
||||||
{
|
{
|
||||||
|
$this->brew = $brew;
|
||||||
$this->cli = $cli;
|
$this->cli = $cli;
|
||||||
$this->files = $files;
|
$this->files = $files;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
@@ -317,12 +320,14 @@ public function getSites($path, $certs)
|
|||||||
})->map(function ($path, $site) use ($certs, $config) {
|
})->map(function ($path, $site) use ($certs, $config) {
|
||||||
$secured = $certs->has($site);
|
$secured = $certs->has($site);
|
||||||
$url = ($secured ? 'https' : 'http').'://'.$site.'.'.$config['tld'];
|
$url = ($secured ? 'https' : 'http').'://'.$site.'.'.$config['tld'];
|
||||||
|
$phpVersion = $this->getPhpVersion($site.'.'.$config['tld']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'site' => $site,
|
'site' => $site,
|
||||||
'secured' => $secured ? ' X' : '',
|
'secured' => $secured ? ' X' : '',
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
|
'phpVersion' => $phpVersion,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -356,6 +361,23 @@ public function pruneLinks()
|
|||||||
$this->files->removeBrokenLinksAt($this->sitesPath());
|
$this->files->removeBrokenLinksAt($this->sitesPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the PHP version for the given site.
|
||||||
|
*
|
||||||
|
* @param string $url Site URL including the TLD
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPhpVersion($url)
|
||||||
|
{
|
||||||
|
$defaultPhpVersion = $this->brew->linkedPhp();
|
||||||
|
$phpVersion = PhpFpm::normalizePhpVersion($this->customPhpVersion($url));
|
||||||
|
if (empty($phpVersion)) {
|
||||||
|
$phpVersion = PhpFpm::normalizePhpVersion($defaultPhpVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $phpVersion;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resecure all currently secured sites with a fresh configuration.
|
* Resecure all currently secured sites with a fresh configuration.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -166,7 +166,7 @@
|
|||||||
$app->command('links', function () {
|
$app->command('links', function () {
|
||||||
$links = Site::links();
|
$links = Site::links();
|
||||||
|
|
||||||
table(['Site', 'SSL', 'URL', 'Path'], $links->all());
|
table(['Site', 'SSL', 'URL', 'Path', 'PHP Version'], $links->all());
|
||||||
})->descriptions('Display all of the registered Valet links');
|
})->descriptions('Display all of the registered Valet links');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -425,6 +425,8 @@ public function test_un_isolate_will_remove_isolation_for_a_site()
|
|||||||
public function test_isolate_will_throw_if_site_is_not_parked_or_linked()
|
public function test_isolate_will_throw_if_site_is_not_parked_or_linked()
|
||||||
{
|
{
|
||||||
$brewMock = Mockery::mock(Brew::class);
|
$brewMock = Mockery::mock(Brew::class);
|
||||||
|
$brewMock->shouldReceive('linkedPhp')->andReturn('php@7.4');
|
||||||
|
|
||||||
$configMock = Mockery::mock(Configuration::class);
|
$configMock = Mockery::mock(Configuration::class);
|
||||||
$configMock->shouldReceive('read')->andReturn(['tld' => 'jamble', 'paths' => []]);
|
$configMock->shouldReceive('read')->andReturn(['tld' => 'jamble', 'paths' => []]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
|
use Valet\Brew;
|
||||||
use Valet\CommandLine;
|
use Valet\CommandLine;
|
||||||
use Valet\Configuration;
|
use Valet\Configuration;
|
||||||
use Valet\Filesystem;
|
use Valet\Filesystem;
|
||||||
@@ -68,18 +69,25 @@ public function test_get_sites_will_return_if_secured()
|
|||||||
$files->shouldReceive('ensureDirExists')
|
$files->shouldReceive('ensureDirExists')
|
||||||
->once()
|
->once()
|
||||||
->with($dirPath, user());
|
->with($dirPath, user());
|
||||||
|
$files->shouldReceive('exists')->andReturn(false);
|
||||||
|
|
||||||
$config = Mockery::mock(Configuration::class);
|
$config = Mockery::mock(Configuration::class);
|
||||||
$config->shouldReceive('read')
|
$config->shouldReceive('read')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['tld' => 'local']);
|
->andReturn(['tld' => 'local']);
|
||||||
|
|
||||||
|
$brew = Mockery::mock(Brew::class);
|
||||||
|
$brew->shouldReceive('linkedPhp')->andReturn('php@8.1');
|
||||||
|
|
||||||
swap(Filesystem::class, $files);
|
swap(Filesystem::class, $files);
|
||||||
swap(Configuration::class, $config);
|
swap(Configuration::class, $config);
|
||||||
|
swap(Brew::class, $brew);
|
||||||
|
|
||||||
/** @var Site $site */
|
/** @var Site $site */
|
||||||
$site = resolve(Site::class);
|
$site = resolve(Site::class);
|
||||||
|
|
||||||
|
$phpVersion = $site->brew->linkedPhp();
|
||||||
|
|
||||||
$certs = Mockery::mock(\Illuminate\Support\Collection::class);
|
$certs = Mockery::mock(\Illuminate\Support\Collection::class);
|
||||||
$certs->shouldReceive('has')
|
$certs->shouldReceive('has')
|
||||||
->twice()
|
->twice()
|
||||||
@@ -96,12 +104,14 @@ public function test_get_sites_will_return_if_secured()
|
|||||||
'secured' => '',
|
'secured' => '',
|
||||||
'url' => 'http://sitetwo.local',
|
'url' => 'http://sitetwo.local',
|
||||||
'path' => $dirPath.'/sitetwo',
|
'path' => $dirPath.'/sitetwo',
|
||||||
|
'phpVersion' => $phpVersion,
|
||||||
], $sites->first());
|
], $sites->first());
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
'site' => 'sitethree',
|
'site' => 'sitethree',
|
||||||
'secured' => ' X',
|
'secured' => ' X',
|
||||||
'url' => 'https://sitethree.local',
|
'url' => 'https://sitethree.local',
|
||||||
'path' => $dirPath.'/sitethree',
|
'path' => $dirPath.'/sitethree',
|
||||||
|
'phpVersion' => $phpVersion,
|
||||||
], $sites->last());
|
], $sites->last());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,18 +135,25 @@ public function test_get_sites_will_work_with_non_symlinked_path()
|
|||||||
$files->shouldReceive('ensureDirExists')
|
$files->shouldReceive('ensureDirExists')
|
||||||
->once()
|
->once()
|
||||||
->with($dirPath, user());
|
->with($dirPath, user());
|
||||||
|
$files->shouldReceive('exists')->andReturn(false);
|
||||||
|
|
||||||
$config = Mockery::mock(Configuration::class);
|
$config = Mockery::mock(Configuration::class);
|
||||||
$config->shouldReceive('read')
|
$config->shouldReceive('read')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['tld' => 'local']);
|
->andReturn(['tld' => 'local']);
|
||||||
|
|
||||||
|
$brew = Mockery::mock(Brew::class);
|
||||||
|
$brew->shouldReceive('linkedPhp')->andReturn('php@8.1');
|
||||||
|
|
||||||
swap(Filesystem::class, $files);
|
swap(Filesystem::class, $files);
|
||||||
swap(Configuration::class, $config);
|
swap(Configuration::class, $config);
|
||||||
|
swap(Brew::class, $brew);
|
||||||
|
|
||||||
/** @var Site $site */
|
/** @var Site $site */
|
||||||
$site = resolve(Site::class);
|
$site = resolve(Site::class);
|
||||||
|
|
||||||
|
$phpVersion = $site->brew->linkedPhp();
|
||||||
|
|
||||||
$sites = $site->getSites($dirPath, collect());
|
$sites = $site->getSites($dirPath, collect());
|
||||||
$this->assertCount(1, $sites);
|
$this->assertCount(1, $sites);
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
@@ -144,6 +161,7 @@ public function test_get_sites_will_work_with_non_symlinked_path()
|
|||||||
'secured' => '',
|
'secured' => '',
|
||||||
'url' => 'http://sitetwo.local',
|
'url' => 'http://sitetwo.local',
|
||||||
'path' => $dirPath.'/sitetwo',
|
'path' => $dirPath.'/sitetwo',
|
||||||
|
'phpVersion' => $phpVersion,
|
||||||
], $sites->first());
|
], $sites->first());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,18 +180,25 @@ public function test_get_sites_will_not_return_if_path_is_not_directory()
|
|||||||
$files->shouldReceive('ensureDirExists')
|
$files->shouldReceive('ensureDirExists')
|
||||||
->once()
|
->once()
|
||||||
->with($dirPath, user());
|
->with($dirPath, user());
|
||||||
|
$files->shouldReceive('exists')->andReturn(false);
|
||||||
|
|
||||||
$config = Mockery::mock(Configuration::class);
|
$config = Mockery::mock(Configuration::class);
|
||||||
$config->shouldReceive('read')
|
$config->shouldReceive('read')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['tld' => 'local']);
|
->andReturn(['tld' => 'local']);
|
||||||
|
|
||||||
|
$brew = Mockery::mock(Brew::class);
|
||||||
|
$brew->shouldReceive('linkedPhp')->andReturn('php@8.1');
|
||||||
|
|
||||||
swap(Filesystem::class, $files);
|
swap(Filesystem::class, $files);
|
||||||
swap(Configuration::class, $config);
|
swap(Configuration::class, $config);
|
||||||
|
swap(Brew::class, $brew);
|
||||||
|
|
||||||
/** @var Site $site */
|
/** @var Site $site */
|
||||||
$site = resolve(Site::class);
|
$site = resolve(Site::class);
|
||||||
|
|
||||||
|
$phpVersion = $site->brew->linkedPhp();
|
||||||
|
|
||||||
$sites = $site->getSites($dirPath, collect());
|
$sites = $site->getSites($dirPath, collect());
|
||||||
$this->assertCount(1, $sites);
|
$this->assertCount(1, $sites);
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
@@ -181,6 +206,7 @@ public function test_get_sites_will_not_return_if_path_is_not_directory()
|
|||||||
'secured' => '',
|
'secured' => '',
|
||||||
'url' => 'http://siteone.local',
|
'url' => 'http://siteone.local',
|
||||||
'path' => $dirPath.'/siteone',
|
'path' => $dirPath.'/siteone',
|
||||||
|
'phpVersion' => $phpVersion,
|
||||||
], $sites->first());
|
], $sites->first());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,18 +230,25 @@ public function test_get_sites_will_work_with_symlinked_path()
|
|||||||
$files->shouldReceive('ensureDirExists')
|
$files->shouldReceive('ensureDirExists')
|
||||||
->once()
|
->once()
|
||||||
->with($dirPath, user());
|
->with($dirPath, user());
|
||||||
|
$files->shouldReceive('exists')->andReturn(false);
|
||||||
|
|
||||||
$config = Mockery::mock(Configuration::class);
|
$config = Mockery::mock(Configuration::class);
|
||||||
$config->shouldReceive('read')
|
$config->shouldReceive('read')
|
||||||
->once()
|
->once()
|
||||||
->andReturn(['tld' => 'local']);
|
->andReturn(['tld' => 'local']);
|
||||||
|
|
||||||
|
$brew = Mockery::mock(Brew::class);
|
||||||
|
$brew->shouldReceive('linkedPhp')->andReturn('php@8.1');
|
||||||
|
|
||||||
swap(Filesystem::class, $files);
|
swap(Filesystem::class, $files);
|
||||||
swap(Configuration::class, $config);
|
swap(Configuration::class, $config);
|
||||||
|
swap(Brew::class, $brew);
|
||||||
|
|
||||||
/** @var Site $site */
|
/** @var Site $site */
|
||||||
$site = resolve(Site::class);
|
$site = resolve(Site::class);
|
||||||
|
|
||||||
|
$phpVersion = $site->brew->linkedPhp();
|
||||||
|
|
||||||
$sites = $site->getSites($dirPath, collect());
|
$sites = $site->getSites($dirPath, collect());
|
||||||
$this->assertCount(1, $sites);
|
$this->assertCount(1, $sites);
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
@@ -223,6 +256,7 @@ public function test_get_sites_will_work_with_symlinked_path()
|
|||||||
'secured' => '',
|
'secured' => '',
|
||||||
'url' => 'http://siteone.local',
|
'url' => 'http://siteone.local',
|
||||||
'path' => $linkedPath,
|
'path' => $linkedPath,
|
||||||
|
'phpVersion' => $phpVersion,
|
||||||
], $sites->first());
|
], $sites->first());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,6 +568,7 @@ public function test_gets_site_url_from_directory()
|
|||||||
swap(Configuration::class, $config);
|
swap(Configuration::class, $config);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
resolve(Configuration::class),
|
resolve(Configuration::class),
|
||||||
resolve(CommandLine::class),
|
resolve(CommandLine::class),
|
||||||
resolve(Filesystem::class),
|
resolve(Filesystem::class),
|
||||||
@@ -585,6 +620,7 @@ public function test_it_throws_getting_nonexistent_site()
|
|||||||
swap(Configuration::class, $config);
|
swap(Configuration::class, $config);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
resolve(Configuration::class),
|
resolve(Configuration::class),
|
||||||
resolve(CommandLine::class),
|
resolve(CommandLine::class),
|
||||||
resolve(Filesystem::class),
|
resolve(Filesystem::class),
|
||||||
@@ -609,6 +645,7 @@ public function test_isolation_will_persist_when_adding_ssl_certificate()
|
|||||||
$config = Mockery::mock(Configuration::class);
|
$config = Mockery::mock(Configuration::class);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
$config,
|
$config,
|
||||||
Mockery::mock(CommandLine::class),
|
Mockery::mock(CommandLine::class),
|
||||||
$files,
|
$files,
|
||||||
@@ -641,6 +678,7 @@ public function test_isolation_will_persist_when_removing_ssl_certificate()
|
|||||||
$cli = Mockery::mock(CommandLine::class);
|
$cli = Mockery::mock(CommandLine::class);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
$config,
|
$config,
|
||||||
$cli,
|
$cli,
|
||||||
$files,
|
$files,
|
||||||
@@ -662,12 +700,40 @@ public function test_isolation_will_persist_when_removing_ssl_certificate()
|
|||||||
resolve(Site::class)->unsecure('site2.test');
|
resolve(Site::class)->unsecure('site2.test');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_php_version_returns_correct_version_for_site()
|
||||||
|
{
|
||||||
|
$files = Mockery::mock(Filesystem::class);
|
||||||
|
$files->shouldReceive('exists')->andReturn(false);
|
||||||
|
|
||||||
|
$brew = Mockery::mock(Brew::class);
|
||||||
|
$brew->shouldReceive('linkedPhp')->andReturn('php@8.1');
|
||||||
|
|
||||||
|
swap(Brew::class, $brew);
|
||||||
|
|
||||||
|
$site = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
|
Mockery::mock(Configuration::class),
|
||||||
|
Mockery::mock(CommandLine::class),
|
||||||
|
$files,
|
||||||
|
])->makePartial();
|
||||||
|
$site->shouldReceive('customPhpVersion')->with('site1.test')->andReturn('73')->once();
|
||||||
|
$site->shouldReceive('customPhpVersion')->with('site2.test')->andReturn(null)->once();
|
||||||
|
|
||||||
|
swap(Site::class, $site);
|
||||||
|
|
||||||
|
$phpVersion = $site->brew->linkedPhp();
|
||||||
|
|
||||||
|
$this->assertEquals('php@7.3', $site->getPhpVersion('site1.test'));
|
||||||
|
$this->assertEquals($phpVersion, $site->getPhpVersion('site2.test'));
|
||||||
|
}
|
||||||
|
|
||||||
public function test_can_install_nginx_site_config_for_specific_php_version()
|
public function test_can_install_nginx_site_config_for_specific_php_version()
|
||||||
{
|
{
|
||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
$config = Mockery::mock(Configuration::class);
|
$config = Mockery::mock(Configuration::class);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
$config,
|
$config,
|
||||||
resolve(CommandLine::class),
|
resolve(CommandLine::class),
|
||||||
$files,
|
$files,
|
||||||
@@ -719,6 +785,7 @@ public function test_it_removes_isolation()
|
|||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
resolve(Configuration::class),
|
resolve(Configuration::class),
|
||||||
resolve(CommandLine::class),
|
resolve(CommandLine::class),
|
||||||
$files,
|
$files,
|
||||||
@@ -744,6 +811,7 @@ public function test_retrieves_custom_php_version_from_nginx_config()
|
|||||||
$files = Mockery::mock(Filesystem::class);
|
$files = Mockery::mock(Filesystem::class);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
resolve(Configuration::class),
|
resolve(Configuration::class),
|
||||||
resolve(CommandLine::class),
|
resolve(CommandLine::class),
|
||||||
$files,
|
$files,
|
||||||
@@ -829,6 +897,7 @@ public function test_it_can_read_php_rc_version()
|
|||||||
swap(Filesystem::class, $files);
|
swap(Filesystem::class, $files);
|
||||||
|
|
||||||
$siteMock = Mockery::mock(Site::class, [
|
$siteMock = Mockery::mock(Site::class, [
|
||||||
|
resolve(Brew::class),
|
||||||
resolve(Configuration::class),
|
resolve(Configuration::class),
|
||||||
resolve(CommandLine::class),
|
resolve(CommandLine::class),
|
||||||
resolve(Filesystem::class),
|
resolve(Filesystem::class),
|
||||||
|
|||||||
Reference in New Issue
Block a user