forked from laravel/valet
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathLinuxServiceTest.php
63 lines (49 loc) · 1.63 KB
/
LinuxServiceTest.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
<?php
use Illuminate\Container\Container;
use PHPUnit\Framework\TestCase;
use Valet\CommandLine;
use Valet\ServiceManagers\LinuxService;
class LinuxServiceTest extends TestCase
{
protected function setUp(): void
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
protected function tearDown(): void
{
Mockery::close();
}
public function test_service_can_be_resolved_from_container()
{
$this->assertInstanceOf(LinuxService::class, resolve(LinuxService::class));
}
public function test_restart_restarts_the_service_using_linux_services()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('quietly')->once()->with('sudo service nginx restart');
swap(CommandLine::class, $cli);
resolve(StubForGetRealService::class)->restart('nginx');
}
public function test_start_starts_the_service_using_linux_services()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('quietly')->once()->with('sudo service nginx start');
swap(CommandLine::class, $cli);
resolve(StubForGetRealService::class)->start('nginx');
}
public function test_stop_stops_the_service_using_linux_services()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('quietly')->once()->with('sudo service nginx stop');
swap(CommandLine::class, $cli);
resolve(StubForGetRealService::class)->stop('nginx');
}
}
class StubForGetRealService extends LinuxService
{
public function getRealService($service)
{
return $service;
}
}