Skip to content

Commit fa1a46d

Browse files
authored
Merge pull request #1274 from cloudfoundry/fix/composer-install-options-ignored-1265
fix: COMPOSER_INSTALL_OPTIONS from options.json silently ignored (#1265)
2 parents 5ad5a20 + 162b891 commit fa1a46d

6 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"COMPOSER_INSTALL_OPTIONS": ["--dev"]
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "cloudfoundry/composer_install_options_test",
3+
"require": {
4+
"php": ">=8.1"
5+
},
6+
"require-dev": {
7+
"psr/log": "^3.0"
8+
}
9+
}

fixtures/composer_install_options/composer.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
require '../lib/vendor/autoload.php';
3+
4+
// psr/log is a require-dev dependency.
5+
// If COMPOSER_INSTALL_OPTIONS: ["--dev"] is honoured, this class exists.
6+
if (interface_exists('Psr\Log\LoggerInterface')) {
7+
echo "dev dependencies installed";
8+
} else {
9+
http_response_code(500);
10+
echo "dev dependencies missing";
11+
}

src/php/integration/composer_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ func testComposer(platform switchblade.Platform, fixtures string) func(*testing.
117117
})
118118
})
119119

120+
// Regression test for https://github.com/cloudfoundry/php-buildpack/issues/1265
121+
// COMPOSER_INSTALL_OPTIONS in options.json was silently ignored in v5 because
122+
// supply.go never wrote the parsed value into the extension Context.Data map.
123+
// As a result, composer always ran with the hardcoded default ["--no-interaction",
124+
// "--no-dev"], making it impossible to install dev dependencies via options.json.
125+
context("composer app with COMPOSER_INSTALL_OPTIONS set to --dev in options.json", func() {
126+
it("installs dev dependencies (issue #1265)", func() {
127+
deployment, logs, err := platform.Deploy.
128+
WithEnv(map[string]string{
129+
"COMPOSER_GITHUB_OAUTH_TOKEN": os.Getenv("COMPOSER_GITHUB_OAUTH_TOKEN"),
130+
}).
131+
Execute(name, filepath.Join(fixtures, "composer_install_options"))
132+
Expect(err).NotTo(HaveOccurred(), logs.String)
133+
134+
// Staging log must NOT contain --no-dev, confirming the user option overrides the default
135+
Expect(logs.String()).NotTo(ContainSubstring("--no-dev"))
136+
137+
// The running app confirms psr/log (a require-dev package) was installed
138+
Eventually(deployment).Should(Serve(ContainSubstring("dev dependencies installed")))
139+
})
140+
})
141+
120142
if !settings.Cached {
121143
context("deployed with invalid COMPOSER_GITHUB_OAUTH_TOKEN", func() {
122144
it("logs warning", func() {

src/php/supply/supply.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (s *Supplier) createExtensionContext() (*extensions.Context, error) {
201201
// Set additional options
202202
ctx.Set("ADMIN_EMAIL", s.Options.AdminEmail)
203203
ctx.Set("COMPOSER_VENDOR_DIR", s.Options.ComposerVendorDir)
204+
ctx.Set("COMPOSER_INSTALL_OPTIONS", s.Options.ComposerInstallOptions)
204205

205206
// Set dynamic PHP version variables
206207
for key, version := range s.Options.PHPVersions {

0 commit comments

Comments
 (0)