-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
InstallCommandTest.php
104 lines (78 loc) · 3.68 KB
/
InstallCommandTest.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php declare(strict_types = 1);
namespace PharIo\Phive\RegressionTests;
use PharIo\FileSystem\Filename;
use PharIo\Phive\Cli\Runner;
use PharIo\Phive\ConfiguredPhar;
use PharIo\Phive\InstalledPhar;
use PharIo\Phive\PharAlias;
use PharIo\Phive\PharUrl;
use PharIo\Phive\RequestedPhar;
use PharIo\Version\AnyVersionConstraint;
use PharIo\Version\ExactVersionConstraint;
use PharIo\Version\Version;
class InstallCommandTest extends RegressionTestCase {
public function testInstallsPhar(): void {
$this->addPharToRegistry('phpunit', '5.3.1', 'phpunit-5.3.1.phar');
$this->runPhiveCommand('install', ['phpunit@5.3.1']);
$this->assertSymlinkTargetEquals(
$this->getToolsDirectory()->file('phpunit')->asString(),
$this->getPhiveHomeDirectory()->child('phars')->file('phpunit-5.3.1.phar')->asString()
);
}
public function testCopiesPhar(): void {
$this->addPharToRegistry('phpunit', '5.3.1', 'phpunit-5.3.1.phar');
$this->runPhiveCommand('install', ['--copy', 'phpunit@5.3.1']);
$target = $this->getToolsDirectory()->file('phpunit')->asString();
$this->assertFileIsNotASymlink($target);
$this->assertFileEquals(
$this->getPhiveHomeDirectory()->child('phars')->file('phpunit-5.3.1.phar')->asString(),
$target
);
}
public function testAddsPharNodeToPhiveXmlConfig(): void {
$phiveXmlConfig = $this->getPhiveXmlConfig();
$this->addPharToRegistry('phpunit', '5.3.1', 'phpunit-5.3.1.phar');
$this->assertEmpty($phiveXmlConfig->getPhars());
$this->runPhiveCommand('install', ['phpunit@5.3.1']);
// config needs to be reloaded
$phiveXmlConfig = $this->getPhiveXmlConfig();
$expectedPhars = [
new ConfiguredPhar('phpunit', new ExactVersionConstraint('5.3.1'), new Version('5.3.1'), new Filename('./tools/phpunit'))
];
$this->assertEquals($expectedPhars, $phiveXmlConfig->getPhars());
}
public function testThrowsErrorIfGlobalAndTargetOptionsAreCombined(): void {
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode(Runner::RC_PARAM_ERROR);
$this->runPhiveCommand('install', ['--global', '--target tools', 'phpunit']);
}
public function testLinksPharToLocationConfiguredInPhiveXml(): void {
$this->addPharToRegistry('phpunit', '5.3.1', 'phpunit-5.3.1.phar');
$phiveXmlConfig = $this->getPhiveXmlConfig();
$phiveXmlConfig->addPhar(
new InstalledPhar(
'phpunit',
new Version('5.3.1'),
new AnyVersionConstraint(),
new Filename('./foo/tests'),
false
),
new RequestedPhar(
new PharAlias('phpunit'),
new AnyVersionConstraint(),
new AnyVersionConstraint()
)
);
$this->runPhiveCommand('install');
$this->assertFileNotExists($this->getWorkingDirectory()->child('tools')->file('phpunit')->asString());
$this->assertFileExists($this->getWorkingDirectory()->child('foo')->file('tests')->asString());
}
public function testAddsSourceUrlToPhiveXml(): void {
$this->runPhiveCommand('install', ['https://phar.phpunit.de/test-mapper-1.0.0.phar']);
$config = $this->getPhiveXmlConfig();
$this->assertTrue($config->hasConfiguredPhar('test-mapper', new Version('1.0.0')));
$phar = $config->getConfiguredPhar('test-mapper', new Version('1.0.0'));
$this->assertTrue($phar->hasUrl());
$this->assertEquals(new PharUrl('https://phar.phpunit.de/test-mapper-1.0.0.phar'), $phar->getUrl());
}
}