From 5ae774dd597f4f3043f6391d382d9228bfa075f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 24 Dec 2018 16:19:08 +0100 Subject: [PATCH] Fix: Deprecate the file argument --- src/Command/NormalizeCommand.php | 4 ++- test/Integration/NormalizeTest.php | 49 ++++++++++++++++++++++++++++++ test/Util/CommandInvocation.php | 5 +++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 69ea6e7e..938a269d 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -70,7 +70,7 @@ protected function configure(): void new Console\Input\InputArgument( 'file', Console\Input\InputArgument::OPTIONAL, - 'Path to composer.json file' + 'Path to composer.json file (deprecated, use --working-dir instead)' ), new Console\Input\InputOption( 'dry-run', @@ -123,6 +123,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O if (null === $composerFile) { $composerFile = Factory::getComposerFile(); + } else { + $io->write('Note: The file argument is deprecated and will be removed in 2.0.0. Please use the --working-dir option instead.'); } try { diff --git a/test/Integration/NormalizeTest.php b/test/Integration/NormalizeTest.php index a0d7798f..999bc2be 100644 --- a/test/Integration/NormalizeTest.php +++ b/test/Integration/NormalizeTest.php @@ -759,6 +759,55 @@ public function testSucceedsWhenComposerJsonIsPresentAndValidAndComposerLockIsPr self::assertComposerLockFileFresh($currentState); } + public function testSucceedsWhenComposerJsonIsPresentAndValidAndComposerLockIsPresentAndFreshBeforeAndComposerJsonIsNotYetNormalizedAndComposerLockIsNotFreshAfterAndInformsWhenFileArgumentIsUsed(): void + { + $scenario = $this->createScenario( + CommandInvocation::usingFileArgument(), + __DIR__ . '/../Fixture/json/valid/lock/present/lock/fresh-before/json/not-yet-normalized/lock/not-fresh-after' + ); + + $initialState = $scenario->initialState(); + + self::assertComposerJsonFileExists($initialState); + self::assertComposerLockFileExists($initialState); + self::assertComposerLockFileFresh($initialState); + + $application = $this->createApplication(new NormalizeCommand( + new Factory(), + new ComposerJsonNormalizer(), + new Formatter(), + new Differ() + )); + + $input = new Console\Input\ArrayInput($scenario->consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(0, $exitCode); + + $renderedOutput = $output->fetch(); + + self::assertContains('Note: The file argument is deprecated and will be removed in 2.0.0. Please use the --working-dir option instead.', $renderedOutput); + + $expected = \sprintf( + 'Successfully normalized %s.', + $scenario->composerJsonFileReference() + ); + + self::assertContains($expected, $renderedOutput); + + $currentState = $scenario->currentState(); + + self::assertComposerJsonFileModified($initialState, $currentState); + self::assertComposerLockFileModified($initialState, $currentState); + self::assertComposerLockFileFresh($currentState); + } + /** * @dataProvider providerCommandInvocation * diff --git a/test/Util/CommandInvocation.php b/test/Util/CommandInvocation.php index a71e5039..3cde118a 100644 --- a/test/Util/CommandInvocation.php +++ b/test/Util/CommandInvocation.php @@ -30,6 +30,11 @@ public static function inCurrentWorkingDirectory(): self return new self('in-current-working-directory'); } + /** + * @deprecated The file argument will be removed in 2.0.0. + * + * @return CommandInvocation + */ public static function usingFileArgument(): self { return new self('using-file-argument');