Skip to content

Commit 2dc9ea2

Browse files
randhircskbukum1
andauthored
Provided bug fix issue no 9166. (#12002)
* Fixed issue https://github.com/github/dependabot-updates/issues/9166 --------- Co-authored-by: Kamil Bukum <[email protected]>
1 parent 57ba18d commit 2dc9ea2

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

composer/lib/dependabot/composer/update_checker/version_resolver.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,16 @@ def handle_composer_errors(error)
263263
# league/csv 9.21.0 requires php ^8.1.2 -> your php version 8.1
264264
if error.message.include?("your php version")
265265
tool_name = "PHP"
266-
detected_version = error.message.match(/your php version \((.*?)\s*;/)[1]
267-
supported_versions = error.message.match(/requires php\s(.*?)\s->/)[1]
266+
# Match for the detected PHP version
267+
detected_version_match =
268+
error.message.match(/your php version \((\d+\.\d+\.\d+)\)/) ||
269+
error.message.match(/your php version \((.*?)\s*;/)
270+
detected_version = detected_version_match ? detected_version_match[1] : nil
271+
272+
# Match for the supported PHP versions
273+
supported_versions_match = error.message.match(/requires php\s(.*?)\s->/)
274+
supported_versions = supported_versions_match ? supported_versions_match[1] : nil
275+
268276
raise ToolVersionNotSupported.new(tool_name, detected_version, supported_versions)
269277
end
270278

composer/spec/dependabot/composer/update_checker/version_resolver_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@
167167
end
168168
end
169169
end
170+
171+
context "when the PHP version is invalid" do
172+
let(:project_name) { "php_version_invalid_with_lock_file" }
173+
let(:dependency_name) { "phpunit/phpunit" }
174+
let(:dependency_version) { "12.1.0" }
175+
let(:string_req) { ">=10.0.16, ==12.1.0" }
176+
let(:latest_allowable_version) { Gem::Version.new("12.1.0") }
177+
178+
it "raises a Dependabot::ToolVersionNotSupported error with correct version details" do
179+
expect { resolver.latest_resolvable_version }
180+
.to raise_error(Dependabot::ToolVersionNotSupported) do |error|
181+
expect(error.tool_name).to eq("PHP")
182+
expect(error.detected_version).to eq("8.2.28")
183+
expect(error.supported_versions).to eq(">=8.3")
184+
end
185+
end
186+
end
170187
end
171188

172189
context "when updating a subdependency that's not required anymore" do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"content-hash": "abcdef1234567890abcdef1234567890",
3+
"require": {
4+
"phpunit/phpunit": ">=10.0.16, ==12.1.0"
5+
}
6+
}

composer/spec/fixtures/projects/php_version_invalid_with_lock_file/composer.lock

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)