Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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