Skip to content
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

Fix: Deprecate the file argument #145

Merged
merged 1 commit into from
Dec 24, 2018
Merged
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
4 changes: 3 additions & 1 deletion src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -123,6 +123,8 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O

if (null === $composerFile) {
$composerFile = Factory::getComposerFile();
} else {
$io->write('<fg=yellow>Note: The file argument is deprecated and will be removed in 2.0.0. Please use the --working-dir option instead.</fg>');
}

try {
Expand Down
49 changes: 49 additions & 0 deletions test/Integration/NormalizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions test/Util/CommandInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down