Skip to content

Commit f8d4ef5

Browse files
authored
Merge pull request #1415 from laravel/mes/ensure-base-configuration
Ensure base configuration is correct even if file already exists
2 parents c95334a + 9ce0ca9 commit f8d4ef5

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

cli/Valet/Configuration.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Valet;
44

5+
use Exception;
6+
57
class Configuration
68
{
79
public function __construct(public Filesystem $files)
@@ -18,7 +20,7 @@ public function install(): void
1820
$this->createSitesDirectory();
1921
$this->createLogDirectory();
2022
$this->createCertificatesDirectory();
21-
$this->writeBaseConfiguration();
23+
$this->ensureBaseConfiguration();
2224

2325
$this->files->chown($this->path(), user());
2426
}
@@ -84,7 +86,23 @@ public function createCertificatesDirectory(): void
8486
}
8587

8688
/**
87-
* Write the base, initial configuration for Valet.
89+
* Ensure the base initial configuration has been installed.
90+
*/
91+
public function ensureBaseConfiguration(): void
92+
{
93+
$this->writeBaseConfiguration();
94+
95+
if (empty($this->read()['tld'])) {
96+
$this->updateKey('tld', 'test');
97+
}
98+
99+
if (empty($this->read()['loopback'])) {
100+
$this->updateKey('loopback', '127.0.0.1');
101+
}
102+
}
103+
104+
/**
105+
* Write the base initial configuration for Valet.
88106
*/
89107
public function writeBaseConfiguration(): void
90108
{

cli/app.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ function (ConsoleCommandEvent $event) {
100100
/**
101101
* Upgrade helper: ensure the tld config exists and the loopback config exists.
102102
*/
103-
if (empty(Configuration::read()['tld']) || empty(Configuration::read()['loopback'])) {
104-
Configuration::writeBaseConfiguration();
105-
}
103+
Configuration::ensureBaseConfiguration();
106104

107105
/**
108106
* Get or set the TLD currently being used by Valet.

tests/ConfigurationTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,14 @@ public function test_trust_adds_the_sudoer_files()
132132
resolve(Brew::class)->createSudoersEntry();
133133
resolve(Valet::class)->createSudoersEntry();
134134
}
135+
136+
public function test_ensure_configuration_exists_writes_tld_and_loopback_if_empty()
137+
{
138+
$config = Mockery::mock(Configuration::class.'[writeBaseConfiguration,read,updateKey]', [new Filesystem]);
139+
$config->shouldReceive('writeBaseConfiguration')->once();
140+
$config->shouldReceive('read')->times(2)->andReturn([]);
141+
$config->shouldReceive('updateKey')->with('tld', 'test');
142+
$config->shouldReceive('updateKey')->with('loopback', '127.0.0.1');
143+
$config->ensureBaseConfiguration();
144+
}
135145
}

0 commit comments

Comments
 (0)