Skip to content

Commit

Permalink
Merge pull request #35 from edersoares/create-file
Browse files Browse the repository at this point in the history
Create file if not exists
  • Loading branch information
edersoares authored Sep 26, 2022
2 parents 7ea0281 + 53e01de commit e71ee7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/Commands/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('<info>You are using Composer Plug and Play Plugin.</info>');

if (file_exists(PlugAndPlayInterface::PACKAGES_FILE) === false) {
$output->writeln('The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.');
$json = [];

return 1;
}

$composer = file_get_contents(PlugAndPlayInterface::PACKAGES_FILE);
if (file_exists(PlugAndPlayInterface::PACKAGES_FILE)) {
$composer = file_get_contents(PlugAndPlayInterface::PACKAGES_FILE);

$json = json_decode($composer, true);
$json = json_decode($composer, true);
}

$json['require'][$input->getArgument('package')] = $input->getArgument('version');

Expand Down
12 changes: 8 additions & 4 deletions tests/Unit/Commands/AddCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ public function testWithVersion(): void
$this->assertJsonStringEqualsJsonFile($this->packagesFile(), $expected);
}

public function testFileNotExists(): void
public function testMergeJsonFiles(): void
{
$output = $this->runCommand('plug-and-play:add dex/extra');
$this->runCommand('plug-and-play:add dex/extra');

$message = 'The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.';
$expected = $this->encodeContent([
'require' => [
'dex/extra' => '*',
],
]);

$this->assertStringContainsString($message, $output->fetch());
$this->assertJsonStringEqualsJsonFile($this->packagesFile(), $expected);
}
}

0 comments on commit e71ee7a

Please sign in to comment.