Add "require command with conflicting keys" test (#12072)
* Add test case for conflicting both with `--dev` and without * Implement interactive case * Restrcture so that interactive case is actually interactive I don't know why specifying `'--no-interaction' => !$isInteractive,` didn't give the desired behavior of the prompt being interactive. You can verify that by printing the `$appTester->getDisplay()` which doesn't contain a prompt. In fact, it doesn't make any difference whether I set it to true or false. The only difference is if I set it or don't set it. * Fix dreaded trainling commapull/12068/head
parent
cbfa298501
commit
dca85cc940
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Test\Command;
|
||||
|
||||
use Composer\Json\JsonFile;
|
||||
use Composer\Test\TestCase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
|
@ -263,4 +264,91 @@ Using version 1.1.0 for required/pkg
|
|||
OUTPUT
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInconsistentRequireKeys
|
||||
* @param bool $isDev
|
||||
* @param bool $isInteractive
|
||||
* @param string $expectedWarning
|
||||
*/
|
||||
public function testInconsistentRequireKeys(bool $isDev, bool $isInteractive, string $expectedWarning): void
|
||||
{
|
||||
$currentKey = $isDev ? "require" : "require-dev";
|
||||
$otherKey = $isDev ? "require-dev" : "require";
|
||||
|
||||
$dir = $this->initTempComposer([
|
||||
'repositories' => [
|
||||
'packages' => [
|
||||
'type' => 'package',
|
||||
'package' => [
|
||||
['name' => 'required/pkg', 'version' => '1.0.0'],
|
||||
],
|
||||
],
|
||||
],
|
||||
$currentKey => [
|
||||
"required/pkg" => "^1.0",
|
||||
],
|
||||
]);
|
||||
|
||||
$package = self::getPackage('required/pkg');
|
||||
if ($isDev) {
|
||||
$this->createComposerLock([], [$package]);
|
||||
$this->createInstalledJson([], [$package]);
|
||||
} else {
|
||||
$this->createComposerLock([$package], []);
|
||||
$this->createInstalledJson([$package], []);
|
||||
}
|
||||
|
||||
$appTester = $this->getApplicationTester();
|
||||
$command = [
|
||||
'command' => 'require',
|
||||
'--no-audit' => true,
|
||||
'--dev' => $isDev,
|
||||
'--no-install' => true,
|
||||
'packages' => ['required/pkg']
|
||||
];
|
||||
|
||||
if ($isInteractive)
|
||||
$appTester->setInputs(['yes']);
|
||||
else
|
||||
$command['--no-interaction'] = true;
|
||||
|
||||
$appTester->run($command);
|
||||
|
||||
self::assertStringContainsString(
|
||||
$expectedWarning,
|
||||
$appTester->getDisplay(true)
|
||||
);
|
||||
|
||||
$composer_content = (new JsonFile($dir . '/composer.json'))->read();
|
||||
self::assertArrayHasKey($otherKey, $composer_content);
|
||||
self::assertArrayNotHasKey($currentKey, $composer_content);
|
||||
}
|
||||
|
||||
public function provideInconsistentRequireKeys(): \Generator
|
||||
{
|
||||
yield [
|
||||
true,
|
||||
false,
|
||||
'<warning>required/pkg is currently present in the require key and you ran the command with the --dev flag, which will move it to the require-dev key.</warning>'
|
||||
];
|
||||
|
||||
yield [
|
||||
false,
|
||||
false,
|
||||
'<warning>required/pkg is currently present in the require-dev key and you ran the command without the --dev flag, which will move it to the require key.</warning>'
|
||||
];
|
||||
|
||||
yield [
|
||||
true,
|
||||
true,
|
||||
'<warning>required/pkg is currently present in the require key and you ran the command with the --dev flag, which will move it to the require-dev key.</warning>'
|
||||
];
|
||||
|
||||
yield [
|
||||
false,
|
||||
true,
|
||||
'<warning>required/pkg is currently present in the require-dev key and you ran the command without the --dev flag, which will move it to the require key.</warning>'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue