-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathPluginInstallerTest.php
134 lines (107 loc) · 3.58 KB
/
PathPluginInstallerTest.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace TypedPHP\Composer\Tests;
use Composer\Composer;
use Composer\Package\PackageInterface;
use Mockery;
use TypedPHP\Composer\PathPluginInstaller;
class PathPluginInstallerTest extends TestCase
{
/**
* @test
*
* @return void
*/
public function installerReturnsPackageBasePath()
{
$root = $this->getNewPackageMock();
$composer = $this->getNewComposerMock();
$composer->shouldReceive("getPackage")->andReturn($root);
$package = $this->getNewPackageMock();
$package->shouldReceive("getName")->andReturn("bar/baz");
$installer = $this->getNewInstallerMock();
$installer->composer = $composer;
$installer->shouldReceive("getRootPath")->once();
$installer->shouldReceive("getPackagePath")->once();
$this->assertEquals("mocked parent method", $installer->getPackageBasePath($package));
$installer->shouldReceive("getRootPath")->once();
$installer->shouldReceive("getPackagePath")->once()->andReturn("foo");
$this->assertEquals("foo/bar/baz", $installer->getPackageBasePath($package));
$installer->shouldReceive("getRootPath")->once()->andReturn("bar");
$this->assertEquals("bar/bar/baz", $installer->getPackageBasePath($package));
}
/**
* @test
*
* @return void
*/
public function installerReturnsRootPathWhenSet()
{
$root = $this->getNewPackageMock();
$root->shouldReceive("getExtra")->once();
$package = $this->getNewPackageMock();
$package->shouldReceive("getName")->andReturn("foo/bar");
$installer = new PathPluginInstaller();
$this->assertNull($installer->getRootPath($root, $package));
$root->shouldReceive("getExtra")->once()->andReturn(["paths" => ["foo/bar" => "baz"]]);
$this->assertEquals("baz", $installer->getRootPath($root, $package));
}
/**
* @test
*
* @return void
*/
public function installerMatchesStringsWithPatterns()
{
$installer = new PathPluginInstaller();
$this->assertTrue($installer->matches("foo/bar", "foo/bar"));
$this->assertFalse($installer->matches("bar/baz", "foo/*"));
$this->assertTrue($installer->matches("foo/baz", "foo/*"));
$this->assertFalse($installer->matches("foo/bar", "*/baz"));
$this->assertTrue($installer->matches("foo/baz", "*/baz"));
}
/**
* @test
*
* @return void
*/
public function installerReturnsPackagePathIfSet()
{
$installer = new PathPluginInstaller();
$package = $this->getNewPackageMock();
$package->shouldReceive("getExtra")->once();
$this->assertNull($installer->getPackagePath($package));
$package->shouldReceive("getExtra")->once()->andReturn(["path" => "foo"]);
$this->assertEquals("foo", $installer->getPackagePath($package));
}
/**
* @return PackageInterface
*/
protected function getNewPackageMock()
{
return Mockery::mock(PackageInterface::class);
}
/**
* @test
*
* @return void
*/
public function installerSupportsAllTypes()
{
$installer = new PathPluginInstaller();
$this->assertTrue($installer->supports("foo"));
}
/**
* @return Composer
*/
protected function getNewComposerMock()
{
return Mockery::mock(Composer::class);
}
/**
* @return PathPluginInstaller
*/
protected function getNewInstallerMock()
{
return Mockery::mock(PathPluginInstaller::class)->makePartial();
}
}