Skip to content

Commit

Permalink
Merge pull request #834 from jrbarnard/bugfix/parked-showing-files
Browse files Browse the repository at this point in the history
Ignore parked paths that are not directories when getting sites
  • Loading branch information
mattstauffer authored Oct 29, 2019
2 parents fdd67d2 + cb8d971 commit 705bcd3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/Valet/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ function getSites($path, $certs)
$realPath = $this->files->realpath($sitePath);
}
return [$site => $realPath];
})->filter(function ($path) {
return $this->files->isDir($path);
})->map(function ($path, $site) use ($certs, $config) {
$secured = $certs->has($site);
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['tld'];
Expand Down
38 changes: 38 additions & 0 deletions tests/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function test_get_sites_will_return_if_secured()
$files->shouldReceive('realpath')
->twice()
->andReturn($dirPath . '/sitetwo', $dirPath . '/sitethree');
$files->shouldReceive('isDir')->andReturn(true);

$config = Mockery::mock(Configuration::class);
$config->shouldReceive('read')
Expand Down Expand Up @@ -117,6 +118,7 @@ public function test_get_sites_will_work_with_non_symlinked_path()
->once()
->with($dirPath . '/sitetwo')
->andReturn($dirPath . '/sitetwo');
$files->shouldReceive('isDir')->once()->with($dirPath . '/sitetwo')->andReturn(true);

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


public function test_get_sites_will_not_return_if_path_is_not_directory()
{
$files = Mockery::mock(Filesystem::class);
$dirPath = '/Users/usertest/parkedpath';
$files->shouldReceive('scandir')
->once()
->with($dirPath)
->andReturn(['sitetwo', 'siteone']);
$files->shouldReceive('isLink')->andReturn(false);
$files->shouldReceive('realpath')->andReturn($dirPath . '/sitetwo', $dirPath . '/siteone');
$files->shouldReceive('isDir')->twice()
->andReturn(false, true);

$config = Mockery::mock(Configuration::class);
$config->shouldReceive('read')
->once()
->andReturn(['tld' => 'local']);

swap(Filesystem::class, $files);
swap(Configuration::class, $config);

/** @var Site $site */
$site = resolve(Site::class);

$sites = $site->getSites($dirPath, collect());
$this->assertCount(1, $sites);
$this->assertSame([
'site' => 'siteone',
'secured' => '',
'url' => 'http://siteone.local',
'path' => $dirPath . '/siteone',
], $sites->first());
}


public function test_get_sites_will_work_with_symlinked_path()
{
$files = Mockery::mock(Filesystem::class);
Expand All @@ -156,6 +193,7 @@ public function test_get_sites_will_work_with_symlinked_path()
->once()
->with($dirPath . '/siteone')
->andReturn($linkedPath = '/Users/usertest/linkedpath/siteone');
$files->shouldReceive('isDir')->andReturn(true);

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

0 comments on commit 705bcd3

Please sign in to comment.