Skip to content

Commit 705bcd3

Browse files
authored
Merge pull request #834 from jrbarnard/bugfix/parked-showing-files
Ignore parked paths that are not directories when getting sites
2 parents fdd67d2 + cb8d971 commit 705bcd3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

cli/Valet/Site.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ function getSites($path, $certs)
198198
$realPath = $this->files->realpath($sitePath);
199199
}
200200
return [$site => $realPath];
201+
})->filter(function ($path) {
202+
return $this->files->isDir($path);
201203
})->map(function ($path, $site) use ($certs, $config) {
202204
$secured = $certs->has($site);
203205
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['tld'];

tests/SiteTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function test_get_sites_will_return_if_secured()
6363
$files->shouldReceive('realpath')
6464
->twice()
6565
->andReturn($dirPath . '/sitetwo', $dirPath . '/sitethree');
66+
$files->shouldReceive('isDir')->andReturn(true);
6667

6768
$config = Mockery::mock(Configuration::class);
6869
$config->shouldReceive('read')
@@ -117,6 +118,7 @@ public function test_get_sites_will_work_with_non_symlinked_path()
117118
->once()
118119
->with($dirPath . '/sitetwo')
119120
->andReturn($dirPath . '/sitetwo');
121+
$files->shouldReceive('isDir')->once()->with($dirPath . '/sitetwo')->andReturn(true);
120122

121123
$config = Mockery::mock(Configuration::class);
122124
$config->shouldReceive('read')
@@ -140,6 +142,41 @@ public function test_get_sites_will_work_with_non_symlinked_path()
140142
}
141143

142144

145+
public function test_get_sites_will_not_return_if_path_is_not_directory()
146+
{
147+
$files = Mockery::mock(Filesystem::class);
148+
$dirPath = '/Users/usertest/parkedpath';
149+
$files->shouldReceive('scandir')
150+
->once()
151+
->with($dirPath)
152+
->andReturn(['sitetwo', 'siteone']);
153+
$files->shouldReceive('isLink')->andReturn(false);
154+
$files->shouldReceive('realpath')->andReturn($dirPath . '/sitetwo', $dirPath . '/siteone');
155+
$files->shouldReceive('isDir')->twice()
156+
->andReturn(false, true);
157+
158+
$config = Mockery::mock(Configuration::class);
159+
$config->shouldReceive('read')
160+
->once()
161+
->andReturn(['tld' => 'local']);
162+
163+
swap(Filesystem::class, $files);
164+
swap(Configuration::class, $config);
165+
166+
/** @var Site $site */
167+
$site = resolve(Site::class);
168+
169+
$sites = $site->getSites($dirPath, collect());
170+
$this->assertCount(1, $sites);
171+
$this->assertSame([
172+
'site' => 'siteone',
173+
'secured' => '',
174+
'url' => 'http://siteone.local',
175+
'path' => $dirPath . '/siteone',
176+
], $sites->first());
177+
}
178+
179+
143180
public function test_get_sites_will_work_with_symlinked_path()
144181
{
145182
$files = Mockery::mock(Filesystem::class);
@@ -156,6 +193,7 @@ public function test_get_sites_will_work_with_symlinked_path()
156193
->once()
157194
->with($dirPath . '/siteone')
158195
->andReturn($linkedPath = '/Users/usertest/linkedpath/siteone');
196+
$files->shouldReceive('isDir')->andReturn(true);
159197

160198
$config = Mockery::mock(Configuration::class);
161199
$config->shouldReceive('read')

0 commit comments

Comments
 (0)