Skip to content

Commit

Permalink
Merge pull request webmozart#20 from sstok/feature-full-symfony-adapter
Browse files Browse the repository at this point in the history
Complete the Symfony adapters for interactive and decorated
  • Loading branch information
webmozart authored Aug 9, 2016
2 parents 7e35380 + 5e386ef commit a6687e8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Adapter/ArgsInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class ArgsInput implements InputInterface
*/
private $args;

/**
* @var bool
*/
private $interactive = true;

/**
* Creates the adapter.
*
Expand Down Expand Up @@ -223,13 +228,14 @@ public function hasOption($name)
*/
public function isInteractive()
{
return true;
return $this->interactive;
}

/**
* {@inheritdoc}
*/
public function setInteractive($interactive)
{
$this->interactive = $interactive;
}
}
10 changes: 9 additions & 1 deletion src/Adapter/IOOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Webmozart\Console\Api\IO\IO;
use Webmozart\Console\Formatter\AnsiFormatter;

/**
* Adapts an {@link IO} instance to Symfony's {@link OutputInterface} API.
Expand All @@ -29,6 +30,11 @@ class IOOutput implements OutputInterface
*/
private $io;

/**
* @var bool
*/
private $decorated;

/**
* Creates a new composite output.
*
Expand All @@ -37,6 +43,7 @@ class IOOutput implements OutputInterface
public function __construct(IO $io)
{
$this->io = $io;
$this->decorated = $this->io->getFormatter() instanceof AnsiFormatter;
}

/**
Expand Down Expand Up @@ -162,14 +169,15 @@ public function isDebug()
*/
public function setDecorated($decorated)
{
$this->decorated = $decorated;
}

/**
* {@inheritdoc}
*/
public function isDecorated()
{
return false;
return $this->decorated;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Adapter/ArgsInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,15 @@ public function testHasOption()
$this->assertFalse($inputArgs->hasOption('option3'));
$this->assertFalse($inputNoArgs->hasOption('option1'));
}

public function testSetInteractive()
{
$inputArgs = new ArgsInput($this->rawArgs, $this->args);

$this->assertTrue($inputArgs->isInteractive());

$inputArgs->setInteractive(false);

$this->assertFalse($inputArgs->isInteractive());
}
}
29 changes: 29 additions & 0 deletions tests/Adapter/IOOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Webmozart\Console\Api\IO\Input;
use Webmozart\Console\Api\IO\IO;
use Webmozart\Console\Api\IO\Output;
use Webmozart\Console\Formatter\AnsiFormatter;
use Webmozart\Console\IO\InputStream\StringInputStream;
use Webmozart\Console\IO\OutputStream\BufferedOutputStream;

Expand Down Expand Up @@ -284,6 +285,34 @@ public function testGetVerbosityQuiet()
$this->assertSame(OutputInterface::VERBOSITY_QUIET, $this->output->getVerbosity());
}

public function testIsDecorated()
{
$input = new Input(new StringInputStream());
$output = new Output(new BufferedOutputStream(), new AnsiFormatter());
$nonDecoratedOutput = new Output(new BufferedOutputStream());
$errorOutput = new Output(new BufferedOutputStream());

// Decorated
$this->io = new IO($input, $output, $errorOutput);
$this->output = new IOOutput($this->io);

$this->assertTrue($this->output->isDecorated());

$this->output->setDecorated(false);

$this->assertFalse($this->output->isDecorated());

// Non decorated
$this->io = new IO($input, $nonDecoratedOutput, $errorOutput);
$this->output = new IOOutput($this->io);

$this->assertFalse($this->output->isDecorated());

$this->output->setDecorated(true);

$this->assertTrue($this->output->isDecorated());
}

public function testGetFormatter()
{
$this->assertEquals(new FormatterAdapter($this->io), $this->output->getFormatter());
Expand Down

0 comments on commit a6687e8

Please sign in to comment.