Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/php/extensions/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ func (e *ComposerExtension) versionMatchesConstraint(version, constraint string)
return false
}

// Handle OR constraints (|)
if strings.Contains(constraint, "|") {
parts := strings.Split(constraint, "|")
for _, part := range parts {
if e.versionMatchesConstraint(version, strings.TrimSpace(part)) {
return true
}
}
return false
}

// Handle AND constraints (space-separated)
if strings.Contains(constraint, " ") {
parts := strings.Fields(constraint)
Expand Down
39 changes: 39 additions & 0 deletions src/php/extensions/composer/composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,45 @@ var _ = Describe("ComposerExtension", func() {
})
})

Context("when lock use | (OR) constraint", func() {
BeforeEach(func() {
composerJSON := filepath.Join(buildDir, "composer.json")
jsonContent := `{
"require": {
"php": ">=8.3"
}
}`
err := os.WriteFile(composerJSON, []byte(jsonContent), 0644)
Expect(err).NotTo(HaveOccurred())

composerLock := filepath.Join(buildDir, "composer.lock")
lockContent := `{
"packages": [
{
"name": "simple/package",
"version": "1.0.0",
"require": {
"php": "^7.1 | ^8.0"
}
}
]
}`
err = os.WriteFile(composerLock, []byte(lockContent), 0644)
Expect(err).NotTo(HaveOccurred())

ext.ShouldCompile(ctx)
})

It("should select highest version matching all constraints", func() {
err := ext.Configure(ctx)
Expect(err).NotTo(HaveOccurred())

phpVersion := ctx.GetString("PHP_VERSION")
// In Composer, ^7.1 | ^8.0 is same as ^7.1 || ^8.0, so 8.3.21 is valid
Expect(phpVersion).To(Equal("8.3.21"))
})
})

Context("when composer.json specifies AND constraints (space-separated)", func() {
BeforeEach(func() {
composerJSON := filepath.Join(buildDir, "composer.json")
Expand Down