New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add warning when the latest version of a package cannot be auto-selected in require/init/create-project #10896
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Composer. | ||
* | ||
* (c) Nils Adermann <naderman@naderman.de> | ||
* Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Composer\Test\Command; | ||
|
||
use Composer\Test\TestCase; | ||
use InvalidArgumentException; | ||
|
||
class RequireCommandTest extends TestCase | ||
{ | ||
public function testRequireThrowsIfNoneMatches(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage( | ||
'Package required/pkg has requirements incompatible with your PHP version, PHP extensions and Composer version:' . PHP_EOL . | ||
' - required/pkg 1.0.0 requires ext-foobar ^1 but it is not present.' | ||
); | ||
|
||
$this->initTempComposer([ | ||
'repositories' => [ | ||
'packages' => [ | ||
'type' => 'package', | ||
'package' => [ | ||
['name' => 'required/pkg', 'version' => '1.0.0', 'require' => ['ext-foobar' => '^1']], | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$appTester = $this->getApplicationTester(); | ||
$appTester->run(['command' => 'require', '--dry-run' => true, '--no-audit' => true, 'packages' => ['required/pkg']]); | ||
} | ||
|
||
/** | ||
* @dataProvider provideRequire | ||
* @param array<mixed> $composerJson | ||
* @param array<mixed> $command | ||
*/ | ||
public function testRequire(array $composerJson, array $command, string $expected): void | ||
{ | ||
$this->initTempComposer($composerJson); | ||
|
||
$appTester = $this->getApplicationTester(); | ||
$appTester->run(array_merge(['command' => 'require', '--dry-run' => true, '--no-audit' => true], $command)); | ||
|
||
if (str_contains($expected, '%d')) { | ||
$pattern = '{^'.str_replace('%d', '[0-9.]+', preg_quote(trim($expected))).'$}'; | ||
$this->assertMatchesRegularExpression($pattern, trim($appTester->getDisplay(true))); | ||
} else { | ||
$this->assertSame(trim($expected), trim($appTester->getDisplay(true))); | ||
} | ||
|
||
// workaround until https://github.com/symfony/symfony/pull/46747 is merged | ||
putenv('SHELL_VERBOSITY'); | ||
unset($_ENV['SHELL_VERBOSITY']); | ||
unset($_SERVER['SHELL_VERBOSITY']); | ||
} | ||
|
||
public function provideRequire(): \Generator | ||
{ | ||
yield 'warn once for missing ext but a lower package matches' => [ | ||
[ | ||
'repositories' => [ | ||
'packages' => [ | ||
'type' => 'package', | ||
'package' => [ | ||
['name' => 'required/pkg', 'version' => '1.2.0', 'require' => ['ext-foobar' => '^1']], | ||
['name' => 'required/pkg', 'version' => '1.1.0', 'require' => ['ext-foobar' => '^1']], | ||
['name' => 'required/pkg', 'version' => '1.0.0'], | ||
], | ||
], | ||
], | ||
], | ||
['packages' => ['required/pkg']], | ||
<<<OUTPUT | ||
<warning>Cannot use required/pkg's latest version 1.2.0 as it requires ext-foobar ^1 which is missing from your platform. | ||
Using version ^1.0 for required/pkg | ||
./composer.json has been updated | ||
Running composer update required/pkg | ||
Loading composer repositories with package information | ||
Updating dependencies | ||
Lock file operations: 1 install, 0 updates, 0 removals | ||
- Locking required/pkg (1.0.0) | ||
Installing dependencies from lock file (including require-dev) | ||
Package operations: 1 install, 0 updates, 0 removals | ||
- Installing required/pkg (1.0.0) | ||
OUTPUT | ||
]; | ||
|
||
yield 'warn multiple times when verbose' => [ | ||
[ | ||
'repositories' => [ | ||
'packages' => [ | ||
'type' => 'package', | ||
'package' => [ | ||
['name' => 'required/pkg', 'version' => '1.2.0', 'require' => ['ext-foobar' => '^1']], | ||
['name' => 'required/pkg', 'version' => '1.1.0', 'require' => ['ext-foobar' => '^1']], | ||
['name' => 'required/pkg', 'version' => '1.0.0'], | ||
], | ||
], | ||
], | ||
], | ||
['packages' => ['required/pkg'], '--no-install' => true, '-v' => true], | ||
<<<OUTPUT | ||
<warning>Cannot use required/pkg's latest version 1.2.0 as it requires ext-foobar ^1 which is missing from your platform. | ||
<warning>Cannot use required/pkg 1.1.0 as it requires ext-foobar ^1 which is missing from your platform. | ||
Using version ^1.0 for required/pkg | ||
./composer.json has been updated | ||
Running composer update required/pkg | ||
Loading composer repositories with package information | ||
Updating dependencies | ||
Dependency resolution completed in %d seconds | ||
Analyzed %d packages to resolve dependencies | ||
Analyzed %d rules to resolve dependencies | ||
Lock file operations: 1 install, 0 updates, 0 removals | ||
Installs: required/pkg:1.0.0 | ||
- Locking required/pkg (1.0.0) | ||
OUTPUT | ||
]; | ||
|
||
yield 'warn for not satisfied req which is satisfied by lower version' => [ | ||
[ | ||
'repositories' => [ | ||
'packages' => [ | ||
'type' => 'package', | ||
'package' => [ | ||
['name' => 'required/pkg', 'version' => '1.1.0', 'require' => ['php' => '^20']], | ||
['name' => 'required/pkg', 'version' => '1.0.0', 'require' => ['php' => '>=7']], | ||
], | ||
], | ||
], | ||
], | ||
['packages' => ['required/pkg'], '--no-install' => true], | ||
<<<OUTPUT | ||
<warning>Cannot use required/pkg's latest version 1.1.0 as it requires php ^20 which is not satisfied by your platform. | ||
Using version ^1.0 for required/pkg | ||
./composer.json has been updated | ||
Running composer update required/pkg | ||
Loading composer repositories with package information | ||
Updating dependencies | ||
Lock file operations: 1 install, 0 updates, 0 removals | ||
- Locking required/pkg (1.0.0) | ||
OUTPUT | ||
]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi its Tony Edmunds ere I am depending on your system to help me to get access to my product account please help me I am a complete newbie and I will be great full for your help and support I really appreciate it yours sincerely Tony Edmunds ps I am waiting to hear from you soon I hope, thanks for your help and support