forked from laravel/valet
-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathPackageKitTest.php
82 lines (65 loc) · 2.62 KB
/
PackageKitTest.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
77
78
79
80
81
82
<?php
use Illuminate\Container\Container;
use PHPUnit\Framework\TestCase;
use Valet\CommandLine;
use Valet\PackageManagers\PackageKit;
class PackageKitTest extends TestCase
{
protected function setUp(): void
{
$_SERVER['SUDO_USER'] = user();
Container::setInstance(new Container);
}
protected function tearDown(): void
{
Mockery::close();
}
public function test_PackageKit_can_be_resolved_from_container()
{
$this->assertInstanceOf(PackageKit::class, resolve(PackageKit::class));
}
public function test_installed_returns_true_when_given_formula_is_installed()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('run')->once()
->with("pkcon search php7.0-cli | grep '^In' | sed 's/\s\+/ /g' | cut -d' ' -f2 | sed 's/-[0-9].*//'")
->andReturn('php7.0-cli');
swap(CommandLine::class, $cli);
$this->assertTrue(resolve(PackageKit::class)->installed('php7.0-cli'));
}
public function test_installed_returns_false_when_given_formula_is_not_installed()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('run')->once()
->with("pkcon search php7.0-cli | grep '^In' | sed 's/\s\+/ /g' | cut -d' ' -f2 | sed 's/-[0-9].*//'")
->andReturn('');
swap(CommandLine::class, $cli);
$this->assertFalse(resolve(PackageKit::class)->installed('php7.0-cli'));
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('run')->once()
->with("pkcon search php7.0-cli | grep '^In' | sed 's/\s\+/ /g' | cut -d' ' -f2 | sed 's/-[0-9].*//'")
->andReturn('php7.0-mcrypt');
swap(CommandLine::class, $cli);
$this->assertFalse(resolve(PackageKit::class)->installed('php7.0-cli'));
}
public function test_install_or_fail_will_install_packages()
{
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('run')->once()->with('pkcon install -y dnsmasq', Mockery::type('Closure'));
swap(CommandLine::class, $cli);
resolve(PackageKit::class)->installOrFail('dnsmasq');
}
/**
* @expectedException DomainException
*/
public function test_install_or_fail_throws_exception_on_failure()
{
$this->expectException(DomainException::class);
$cli = Mockery::mock(CommandLine::class);
$cli->shouldReceive('run')->andReturnUsing(function ($command, $onError) {
$onError(1, 'test error ouput');
});
swap(CommandLine::class, $cli);
resolve(PackageKit::class)->installOrFail('dnsmasq');
}
}