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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
local spy = require "luassert.spy"
local mock = require "luassert.mock"
local installer = require "mason-core.installer"
local Optional = require "mason-core.optional"
local composer = require "mason-core.managers.composer"
local Result = require "mason-core.result"
local spawn = require "mason-core.spawn"
local path = require "mason-core.path"
describe("composer manager", function()
it(
"should call composer require",
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
ctx.fs.file_exists = spy.new(mockx.returns(false))
installer.run_installer(
ctx,
composer.packages { "main-package", "supporting-package", "supporting-package2" }
)
assert.spy(ctx.spawn.composer).was_called(2)
assert.spy(ctx.spawn.composer).was_called_with {
"init",
"--no-interaction",
"--stability=stable",
}
assert.spy(ctx.spawn.composer).was_called_with {
"require",
{
"main-package:42.13.37",
"supporting-package",
"supporting-package2",
},
}
end)
)
it(
"should provide receipt information",
async_test(function()
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" })
installer.run_installer(
ctx,
composer.packages { "main-package", "supporting-package", "supporting-package2" }
)
assert.same({
type = "composer",
package = "main-package",
}, ctx.receipt.primary_source)
assert.same({
{
type = "composer",
package = "supporting-package",
},
{
type = "composer",
package = "supporting-package2",
},
}, ctx.receipt.secondary_sources)
end)
)
end)
describe("composer version check", function()
it(
"should return current version",
async_test(function()
spawn.composer = spy.new(function()
return Result.success {
stdout = [[
{
"name": "vimeo/psalm",
"versions": [
"4.0.0"
]
}
]],
}
end)
local result = composer.get_installed_primary_package_version(
mock.new {
primary_source = mock.new {
type = "composer",
package = "vimeo/psalm",
},
},
path.package_prefix "dummy"
)
assert.spy(spawn.composer).was_called(1)
assert.spy(spawn.composer).was_called_with {
"info",
"--format=json",
"vimeo/psalm",
cwd = path.package_prefix "dummy",
}
assert.is_true(result:is_success())
assert.equals("4.0.0", result:get_or_nil())
spawn.composer = nil
end)
)
it(
"should return outdated primary package",
async_test(function()
spawn.composer = spy.new(function()
return Result.success {
stdout = [[
{
"installed": [
{
"name": "vimeo/psalm",
"version": "4.0.0",
"latest": "4.22.0",
"latest-status": "semver-safe-update",
"description": "A static analysis tool for finding errors in PHP applications"
}
]
}
]],
}
end)
local result = composer.check_outdated_primary_package(
mock.new {
primary_source = mock.new {
type = "composer",
package = "vimeo/psalm",
},
},
path.package_prefix "dummy"
)
assert.spy(spawn.composer).was_called(1)
assert.spy(spawn.composer).was_called_with {
"outdated",
"--no-interaction",
"--format=json",
cwd = path.package_prefix "dummy",
}
assert.is_true(result:is_success())
assert.same({
name = "vimeo/psalm",
current_version = "4.0.0",
latest_version = "4.22.0",
}, result:get_or_nil())
spawn.composer = nil
end)
)
it(
"should return failure if primary package is not outdated",
async_test(function()
spawn.composer = spy.new(function()
return Result.success {
stdout = [[{"installed": []}]],
}
end)
local result = composer.check_outdated_primary_package(
mock.new {
primary_source = mock.new {
type = "composer",
package = "vimeo/psalm",
},
},
path.package_prefix "dummy"
)
assert.is_true(result:is_failure())
assert.equals("Primary package is not outdated.", result:err_or_nil())
spawn.composer = nil
end)
)
end)
|