forked from laravel/valet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSiteTest.php
76 lines (59 loc) · 2.15 KB
/
SiteTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
use Valet\Site;
use Valet\Filesystem;
use Valet\Configuration;
use Illuminate\Container\Container;
class SiteTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
public function tearDown()
{
exec('rm -rf '.__DIR__.'/output');
mkdir(__DIR__.'/output');
touch(__DIR__.'/output/.gitkeep');
Mockery::close();
}
public function test_symlink_creates_symlink_to_given_path()
{
$files = Mockery::mock(Filesystem::class);
$files->shouldReceive('ensureDirExists')->once()->with(VALET_HOME_PATH.'/Sites', user());
$config = Mockery::mock(Configuration::class);
$config->shouldReceive('prependPath')->once()->with(VALET_HOME_PATH.'/Sites');
$files->shouldReceive('symlinkAsUser')->once()->with('target', VALET_HOME_PATH.'/Sites/link');
swap(Filesystem::class, $files);
swap(Configuration::class, $config);
$linkPath = resolve(Site::class)->link('target', 'link');
$this->assertSame(VALET_HOME_PATH.'/Sites/link', $linkPath);
}
public function test_unlink_removes_existing_symlink()
{
file_put_contents(__DIR__.'/output/file.out', 'test');
symlink(__DIR__.'/output/file.out', __DIR__.'/output/link');
$site = resolve(StubForRemovingLinks::class);
$site->unlink('link');
$this->assertFileNotExists(__DIR__.'/output/link');
$site = resolve(StubForRemovingLinks::class);
$site->unlink('link');
$this->assertFileNotExists(__DIR__.'/output/link');
}
public function test_prune_links_removes_broken_symlinks_in_sites_path()
{
file_put_contents(__DIR__.'/output/file.out', 'test');
symlink(__DIR__.'/output/file.out', __DIR__.'/output/link');
unlink(__DIR__.'/output/file.out');
$site = resolve(StubForRemovingLinks::class);
$site->pruneLinks();
$this->assertFileNotExists(__DIR__.'/output/link');
}
}
class StubForRemovingLinks extends Site
{
function sitesPath()
{
return __DIR__.'/output';
}
}