Skip to content

Commit

Permalink
Add accessor for SymfonyStyle object.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Sep 4, 2016
1 parent 14df06a commit 26b6668
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Common/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;

trait IO
{
use InputAwareTrait;
use OutputAwareTrait;

/** var: SymfonyStyle */
protected $io;

/**
* Provide access to SymfonyStyle object.
* See: http://symfony.com/blog/new-in-symfony-2-8-console-style-guide
* @return SymfonyStyle
*/
protected function io()
{
if (!$this->io) {
$this->io = new SymfonyStyle($this->input(), $this->output());
}
return $this->io;
}

protected function decorationCharacter($nonDecorated, $decorated)
{
if (!$this->output()->isDecorated() || (strncasecmp(PHP_OS, 'WIN', 3) == 0)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/src/TestRoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public function testArrayArgs(array $a)
$this->say("The parameters passed are:\n" . var_export($a, true));
}

/**
* Demonstrate use of SymfonyStyle
*/
public function testSymfonyStyle()
{
$this->io()->title('My Title');
$this->io()->section('Section 1');
$this->io()->text('Some text in section one.');
$this->io()->comment('This is just an example of different styles.');
$this->io()->section('Section 2');
$this->io()->text('Some text in section two.');
}

/**
* Demonstrate Robo error output and command failure.
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public function testRunnerTryArgs()
$this->guy->seeOutputEquals($expected);
}

public function testSymfonyStyle()
{
$argv = ['placeholder', 'test:symfony-style'];
$this->runner->execute($argv, Robo::output());
$this->guy->seeInOutput('Some text in section one.');
}

public function testRunnerTryError()
{
$argv = ['placeholder', 'test:error'];
Expand Down

0 comments on commit 26b6668

Please sign in to comment.