Skip to content

Commit

Permalink
Merge pull request #4 from edersoares/fix-naming-command
Browse files Browse the repository at this point in the history
Fix naming command
  • Loading branch information
edersoares committed Oct 6, 2021
2 parents ad2cb2e + 85a1781 commit 661cfa9
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 51 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"composer-plugin-api": "^2.0"
},
"require-dev": {
"composer/composer": "^2.0",
"composer/composer": "<=2.1.5",
"phpunit/phpunit": "^9.4"
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions src/Commands/CommandNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public function naming(string $command, array $aliases = [])
$this->setName($command);
$this->setAliases($aliases);
$this->addOption('plug-and-play', null, InputOption::VALUE_NONE, 'Run using plug and play plugin.');
$this->addOption('plug-and-play-pretend', null, InputOption::VALUE_NONE, 'Run pretending to use plug and play plugin.');
}
}
9 changes: 8 additions & 1 deletion src/Commands/ComposerCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ public function getComposer($required = true, $disablePlugins = null)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('plug-and-play')) {
$isTheCommand = $input->getFirstArgument() === $this->getName();
$hasOption = $input->getOption('plug-and-play');

if ($isTheCommand || $hasOption) {
$this->usePlugAndPlay = true;
$output->writeln('<info>You are using Composer Plug and Play Plugin.</info>');
}

if ($input->getOption('plug-and-play-pretend')) {
return 0;
}

return parent::execute($input, $output);
}
}
49 changes: 0 additions & 49 deletions tests/Unit/CommandsTest.php

This file was deleted.

130 changes: 130 additions & 0 deletions tests/Unit/ComposerCommandsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace Dex\Composer\PlugAndPlay\Tests\Unit;

use Dex\Composer\PlugAndPlay\Tests\Application;
use Dex\Composer\PlugAndPlay\Tests\TestCase;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;

class ComposerCommandsTest extends TestCase
{
/**
* @var string
*/
protected $directory = __DIR__ . '/../Fixtures/Plugin/';

public function testPlugAndPlayInstallCommand()
{
$application = new Application();
$input = new StringInput("plug-and-play:install --plug-and-play-pretend -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('You are using Composer Plug and Play Plugin.', $output->fetch());
}

public function testPlugAndPlayUpdateCommand()
{
$application = new Application();
$input = new StringInput("plug-and-play:update --plug-and-play-pretend -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('You are using Composer Plug and Play Plugin.', $output->fetch());
}

public function testPlugAndPlayDumpCommand()
{
$application = new Application();
$input = new StringInput("plug-and-play:dump --plug-and-play-pretend -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('You are using Composer Plug and Play Plugin.', $output->fetch());
}

public function testListCommand()
{
$application = new Application();
$input = new StringInput("list -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$content = $output->fetch();

$this->assertStringContainsString('plug-and-play:dump', $content);
$this->assertStringContainsString('plug-and-play:install', $content);
$this->assertStringContainsString('plug-and-play:update', $content);
}

public function testInstallCommand()
{
$application = new Application();
$input = new StringInput("install --plug-and-play --plug-and-play-pretend -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('You are using Composer Plug and Play Plugin.', $output->fetch());
}

public function testUpdateCommand()
{
$application = new Application();
$input = new StringInput("update --plug-and-play --plug-and-play-pretend -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('You are using Composer Plug and Play Plugin.', $output->fetch());
}

public function testDumpautoloadCommand()
{
$application = new Application();
$input = new StringInput("dumpautoload --plug-and-play --plug-and-play-pretend -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('You are using Composer Plug and Play Plugin.', $output->fetch());
}

public function testIfOptionIsPresentInInstallCommand()
{
$application = new Application();
$input = new StringInput("install --help -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('--plug-and-play', $output->fetch());
}

public function testIfOptionIsPresentInUpdateCommand()
{
$application = new Application();
$input = new StringInput("update --help -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('--plug-and-play', $output->fetch());
}

public function testIfOptionIsPresentInDumpautoloadCommand()
{
$application = new Application();
$input = new StringInput("dumpautoload --help -d {$this->directory}");
$output = new BufferedOutput();

$application->doRun($input, $output);

$this->assertStringContainsString('--plug-and-play', $output->fetch());
}
}

0 comments on commit 661cfa9

Please sign in to comment.