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

Apply suggestions from code review

Co-authored-by: Matt Stauffer <mattstauffer@users.noreply.github.com>
This commit is contained in:
Nasir Uddin Nobin
2022-02-19 08:16:16 +06:00
committed by GitHub
parent 9a5d30bb69
commit 7a80a2e0ea
2 changed files with 20 additions and 20 deletions

View File

@@ -41,7 +41,7 @@ public function test_fpm_is_configured_with_the_correct_user_group_and_port()
$this->assertStringContainsString("\ngroup = staff", $contents); $this->assertStringContainsString("\ngroup = staff", $contents);
$this->assertStringContainsString("\nlisten = ".VALET_HOME_PATH.'/valet.sock', $contents); $this->assertStringContainsString("\nlisten = ".VALET_HOME_PATH.'/valet.sock', $contents);
// Passing speicifc version will change the .sock file // Passing specific version will change the .sock file
resolve(StubForUpdatingFpmConfigFiles::class)->updateConfiguration('php@7.2'); resolve(StubForUpdatingFpmConfigFiles::class)->updateConfiguration('php@7.2');
$contents = file_get_contents(__DIR__.'/output/fpm.conf'); $contents = file_get_contents(__DIR__.'/output/fpm.conf');
$this->assertStringContainsString(sprintf("\nuser = %s", user()), $contents); $this->assertStringContainsString(sprintf("\nuser = %s", user()), $contents);
@@ -209,13 +209,13 @@ public function test_stop_unused_php_versions()
// Would do nothing // Would do nothing
resolve(PhpFpm::class)->stopIfUnused(null); resolve(PhpFpm::class)->stopIfUnused(null);
// Currently, not utilizeing this PHP version, should be stopped // This currently-un-used PHP version should be stopped
$brewMock->shouldReceive('stopService')->times(3)->with('php@7.3'); $brewMock->shouldReceive('stopService')->times(3)->with('php@7.3');
resolve(PhpFpm::class)->stopIfUnused('73'); resolve(PhpFpm::class)->stopIfUnused('73');
resolve(PhpFpm::class)->stopIfUnused('php73'); resolve(PhpFpm::class)->stopIfUnused('php73');
resolve(PhpFpm::class)->stopIfUnused('php@7.3'); resolve(PhpFpm::class)->stopIfUnused('php@7.3');
// Utilizeing PHP Versions, should not receive stop command // These currently-used PHP versions should not be stopped
$brewMock->shouldNotReceive('stopService')->with('php@7.1'); $brewMock->shouldNotReceive('stopService')->with('php@7.1');
$brewMock->shouldNotReceive('stopService')->with('php@7.2'); $brewMock->shouldNotReceive('stopService')->with('php@7.2');
resolve(PhpFpm::class)->stopIfUnused('php@7.1'); resolve(PhpFpm::class)->stopIfUnused('php@7.1');
@@ -343,7 +343,7 @@ public function test_use_version_if_already_linked_php_will_unlink_before_instal
$this->assertSame('php@7.2', $phpFpmMock->useVersion('php@7.2')); $this->assertSame('php@7.2', $phpFpmMock->useVersion('php@7.2'));
} }
public function test_use_version_with_site_paramter_will_isolate_a_site() public function test_use_version_with_site_parameter_will_isolate_a_site()
{ {
$brewMock = Mockery::mock(Brew::class); $brewMock = Mockery::mock(Brew::class);
$nginxMock = Mockery::mock(Nginx::class); $nginxMock = Mockery::mock(Nginx::class);

View File

@@ -527,7 +527,7 @@ public function test_remove_proxy()
$this->assertEquals([], $site->proxies()->all()); $this->assertEquals([], $site->proxies()->all());
} }
public function test_get_site_url_from_directory() public function test_gets_site_url_from_directory()
{ {
$config = Mockery::mock(Configuration::class); $config = Mockery::mock(Configuration::class);
@@ -580,7 +580,7 @@ public function test_get_site_url_from_directory()
$this->assertEquals(false, $site->getSiteUrl('site3.test')); $this->assertEquals(false, $site->getSiteUrl('site3.test'));
} }
public function test_adding_ssl_certificate_would_preserve_isolation() public function test_isolation_will_persist_when_adding_ssl_certificate()
{ {
$files = Mockery::mock(Filesystem::class); $files = Mockery::mock(Filesystem::class);
$config = Mockery::mock(Configuration::class); $config = Mockery::mock(Configuration::class);
@@ -605,13 +605,13 @@ public function test_adding_ssl_certificate_would_preserve_isolation()
$siteMock->shouldReceive('replaceSockFile')->withArgs([Mockery::any(), 'valet73.sock', '73'])->once(); $siteMock->shouldReceive('replaceSockFile')->withArgs([Mockery::any(), 'valet73.sock', '73'])->once();
resolve(Site::class)->secure('site1.test'); resolve(Site::class)->secure('site1.test');
// Sites without isolated PHP version, should not replace anything // For sites without an isolated PHP version, nothing should be replaced
$siteMock->shouldReceive('customPhpVersion')->with('site2.test')->andReturn(null)->once(); $siteMock->shouldReceive('customPhpVersion')->with('site2.test')->andReturn(null)->once();
$siteMock->shouldNotReceive('replaceSockFile'); $siteMock->shouldNotReceive('replaceSockFile');
resolve(Site::class)->secure('site2.test'); resolve(Site::class)->secure('site2.test');
} }
public function test_removing_ssl_certificate_would_preserve_isolation() public function test_isolation_will_persist_when_removing_ssl_certificate()
{ {
$files = Mockery::mock(Filesystem::class); $files = Mockery::mock(Filesystem::class);
$config = Mockery::mock(Configuration::class); $config = Mockery::mock(Configuration::class);
@@ -628,12 +628,12 @@ public function test_removing_ssl_certificate_would_preserve_isolation()
$cli->shouldReceive('run'); $cli->shouldReceive('run');
$files->shouldReceive('exists')->andReturn(false); $files->shouldReceive('exists')->andReturn(false);
// If site has an isolated PHP version, it would install nginx site config // If a site has an isolated PHP version, there should still be a custom nginx site config
$siteMock->shouldReceive('customPhpVersion')->with('site1.test')->andReturn('73')->once(); $siteMock->shouldReceive('customPhpVersion')->with('site1.test')->andReturn('73')->once();
$siteMock->shouldReceive('installSiteConfig')->withArgs(['site1.test', 'valet73.sock', '73'])->once(); $siteMock->shouldReceive('installSiteConfig')->withArgs(['site1.test', 'valet73.sock', '73'])->once();
resolve(Site::class)->unsecure('site1.test'); resolve(Site::class)->unsecure('site1.test');
// Site without a custom PHP version, should not install site config // If a site doesn't have an isolated PHP version, there should no longer be a custom nginx site config
$siteMock->shouldReceive('customPhpVersion')->with('site2.test')->andReturn(null)->once(); $siteMock->shouldReceive('customPhpVersion')->with('site2.test')->andReturn(null)->once();
$siteMock->shouldNotReceive('installSiteConfig'); $siteMock->shouldNotReceive('installSiteConfig');
resolve(Site::class)->unsecure('site2.test'); resolve(Site::class)->unsecure('site2.test');
@@ -670,7 +670,7 @@ public function test_can_install_nginx_site_config_for_specific_php_version()
$siteMock->installSiteConfig('site1.test', 'valet80.sock', 'php@8.0'); $siteMock->installSiteConfig('site1.test', 'valet80.sock', 'php@8.0');
// When there's no Nginx file exists, create new config from the template // When no Nginx file exists, it will create a new config file from the template
$files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false); $files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false);
$files->shouldReceive('get') $files->shouldReceive('get')
->once() ->once()
@@ -691,7 +691,7 @@ public function test_can_install_nginx_site_config_for_specific_php_version()
$siteMock->installSiteConfig('site2.test', 'valet80.sock', 'php@8.0'); $siteMock->installSiteConfig('site2.test', 'valet80.sock', 'php@8.0');
} }
public function test_removeing_isolation() public function test_it_removes_isolation()
{ {
$files = Mockery::mock(Filesystem::class); $files = Mockery::mock(Filesystem::class);
@@ -716,7 +716,7 @@ public function test_removeing_isolation()
resolve(Site::class)->removeIsolation('site2.test'); resolve(Site::class)->removeIsolation('site2.test');
} }
public function test_retrive_custom_php_version_from_nginx_config() public function test_retrieves_custom_php_version_from_nginx_config()
{ {
$files = Mockery::mock(Filesystem::class); $files = Mockery::mock(Filesystem::class);
@@ -754,28 +754,28 @@ public function test_replace_sock_file_in_nginx_config()
{ {
$site = resolve(Site::class); $site = resolve(Site::class);
// Switiching to php71, valet71.sock should be replaced with valet.sock // When switching to php71, valet71.sock should be replaced with valet.sock;
// It would prepend isolation header // isolation header should be prepended
$this->assertEquals( $this->assertEquals(
'# Valet isolated PHP version : 71'.PHP_EOL.'server { fastcgi_pass: valet.sock }', '# Valet isolated PHP version : 71'.PHP_EOL.'server { fastcgi_pass: valet.sock }',
$site->replaceSockFile('server { fastcgi_pass: valet71.sock }', 'valet.sock', '71') $site->replaceSockFile('server { fastcgi_pass: valet71.sock }', 'valet.sock', '71')
); );
// Switiching to php72, valet.sock should be replaced with valet72.sock // When switching to php72, valet.sock should be replaced with valet72.sock
$this->assertEquals( $this->assertEquals(
'# Valet isolated PHP version : 72'.PHP_EOL.'server { fastcgi_pass: valet72.sock }', '# Valet isolated PHP version : 72'.PHP_EOL.'server { fastcgi_pass: valet72.sock }',
$site->replaceSockFile('server { fastcgi_pass: valet.sock }', 'valet72.sock', '72') $site->replaceSockFile('server { fastcgi_pass: valet.sock }', 'valet72.sock', '72')
); );
// Switiching to php73 from php72, valet72.sock should be replaced with valet73.sock // When switching to php73 from php72, valet72.sock should be replaced with valet73.sock;
// Isolation header should be updated to 73 // isolation header should be updated to php@7.3
$this->assertEquals( $this->assertEquals(
'# Valet isolated PHP version : 73'.PHP_EOL.'server { fastcgi_pass: valet73.sock }', '# Valet isolated PHP version : 73'.PHP_EOL.'server { fastcgi_pass: valet73.sock }',
$site->replaceSockFile('# Valet isolated PHP version : 72'.PHP_EOL.'server { fastcgi_pass: valet72.sock }', 'valet73.sock', '73') $site->replaceSockFile('# Valet isolated PHP version : 72'.PHP_EOL.'server { fastcgi_pass: valet72.sock }', 'valet73.sock', '73')
); );
// Switiching to php72 from php74, valet72.sock should be replaced with valet74.sock // When switching to php72 from php74, valet72.sock should be replaced with valet74.sock;
// Isolation header should be updated to php@7.4 // isolation header should be updated to php@7.4
$this->assertEquals( $this->assertEquals(
'# Valet isolated PHP version : php@7.4'.PHP_EOL.'server { fastcgi_pass: valet74.sock }', '# Valet isolated PHP version : php@7.4'.PHP_EOL.'server { fastcgi_pass: valet74.sock }',
$site->replaceSockFile('# Valet isolated PHP version : 72'.PHP_EOL.'server { fastcgi_pass: valet.sock }', 'valet74.sock', 'php@7.4') $site->replaceSockFile('# Valet isolated PHP version : 72'.PHP_EOL.'server { fastcgi_pass: valet.sock }', 'valet74.sock', 'php@7.4')