Skip to content

Commit

Permalink
Merge pull request #94 from pkruithof/sf3-support
Browse files Browse the repository at this point in the history
Added support for symfony/console v3
  • Loading branch information
ramsey committed Dec 17, 2015
2 parents 767a5b5 + 9640408 commit 93a056a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 147 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
sudo: false

language: php

php:
Expand All @@ -7,9 +9,15 @@ php:
- 5.6
- hhvm

matrix:
include:
- php: 5.6
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
fast_finish: true

before_script:
- composer self-update
- composer install --dev --prefer-source
- composer update $COMPOSER_FLAGS --prefer-source

script: ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
},
"require-dev": {
"moontoast/math": "~1.1",
"symfony/console": "~2.3",
"symfony/console": "~2.3|~3.0",
"doctrine/dbal": ">=2.3",
"phpunit/phpunit": "~4.1",
"phpunit/phpunit": "~4.1|~5.0",
"satooshi/php-coveralls": "~0.6",
"squizlabs/php_codesniffer": "^2.3",
"jakub-onderka/php-parallel-lint": "^0.9.0"
Expand Down
28 changes: 24 additions & 4 deletions src/Console/Command/DecodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
namespace Rhumsaa\Uuid\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\TableHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Rhumsaa\Uuid\Console\Exception;
use Rhumsaa\Uuid\Uuid;
Expand Down Expand Up @@ -55,8 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

$uuid = Uuid::fromString($input->getArgument('uuid'));

$table = $this->getHelperSet()->get('table');
$table->setLayout(TableHelper::LAYOUT_BORDERLESS);
$table = $this->createTable($output);
$this->setTableLayout($table);

$table->addRows(array(
array('encode:', 'STR:', (string) $uuid),
Expand Down Expand Up @@ -120,4 +118,26 @@ protected function execute(InputInterface $input, OutputInterface $output)

$table->render($output);
}

protected function createTable(OutputInterface $output)
{
$class = 'Symfony\\Component\\Console\\Helper\\Table';
if (class_exists($class)) {
return new $class($output);
}

return $this->getHelperSet()->get('table');
}

/**
* @param object $table
*/
protected function setTableLayout($table)
{
if (method_exists($table, 'setLayout')) {
$table->setLayout(1); // TableHelper::LAYOUT_BORDERLESS
} else {
$table->setStyle('borderless');
}
}
}
53 changes: 22 additions & 31 deletions tests/Console/Command/DecodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
namespace Rhumsaa\Uuid\Console\Command;

use Rhumsaa\Uuid\Console\TestCase;
use Rhumsaa\Uuid\Console\Util\TestOutput;
use Rhumsaa\Uuid\Console\Util\BufferedOutput;
use Rhumsaa\Uuid\Uuid;
use Symfony\Component\Console\Input\StringInput;

class DecodeCommandTest extends TestCase
{
/**
* @var \ReflectionMethod
*/
protected $execute;

/**
* @var DecodeCommand
*/
protected $decode;

protected function setUp()
Expand All @@ -36,15 +41,13 @@ public function testConfigure()

/**
* @covers Rhumsaa\Uuid\Console\Command\DecodeCommand::execute
* @expectedException Rhumsaa\Uuid\Console\Exception
* @expectedException \Rhumsaa\Uuid\Console\Exception
* @expectedExceptionMessage Invalid UUID
*/
public function testExecuteForInvalidUuid()
{
$input = new StringInput(
'foobar',
$this->decode->getDefinition()
);
$input = new StringInput('foobar');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand All @@ -58,10 +61,8 @@ public function testExecuteForNonRFC4122Uuid()
{
$expected = file_get_contents('tests/console-mocks/testExecuteForNonRFC4122Uuid.txt');

$input = new StringInput(
'ff6f8cb0-c57d-11e1-0b21-0800200c9a66',
$this->decode->getDefinition()
);
$input = new StringInput('ff6f8cb0-c57d-11e1-0b21-0800200c9a66');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand All @@ -77,10 +78,8 @@ public function testExecuteForVersion1Uuid()
{
$expected = file_get_contents('tests/console-mocks/testExecuteForVersion1Uuid.txt');

$input = new StringInput(
'2ddbf60e-7fc4-11e3-a5ac-080027cd5e4d',
$this->decode->getDefinition()
);
$input = new StringInput('2ddbf60e-7fc4-11e3-a5ac-080027cd5e4d');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand All @@ -96,10 +95,8 @@ public function testExecuteForVersion2Uuid()
{
$expected = file_get_contents('tests/console-mocks/testExecuteForVersion2Uuid.txt');

$input = new StringInput(
'6fa459ea-ee8a-2ca4-894e-db77e160355e',
$this->decode->getDefinition()
);
$input = new StringInput('6fa459ea-ee8a-2ca4-894e-db77e160355e');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand All @@ -115,10 +112,8 @@ public function testExecuteForVersion3Uuid()
{
$expected = file_get_contents('tests/console-mocks/testExecuteForVersion3Uuid.txt');

$input = new StringInput(
'6fa459ea-ee8a-3ca4-894e-db77e160355e',
$this->decode->getDefinition()
);
$input = new StringInput('6fa459ea-ee8a-3ca4-894e-db77e160355e');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand All @@ -134,10 +129,8 @@ public function testExecuteForVersion4Uuid()
{
$expected = file_get_contents('tests/console-mocks/testExecuteForVersion4Uuid.txt');

$input = new StringInput(
'83fc61b6-b5ef-467f-9a15-89ddee668005',
$this->decode->getDefinition()
);
$input = new StringInput('83fc61b6-b5ef-467f-9a15-89ddee668005');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand All @@ -153,10 +146,8 @@ public function testExecuteForVersion5Uuid()
{
$expected = file_get_contents('tests/console-mocks/testExecuteForVersion5Uuid.txt');

$input = new StringInput(
'886313e1-3b8a-5372-9b90-0c9aee199e5d',
$this->decode->getDefinition()
);
$input = new StringInput('886313e1-3b8a-5372-9b90-0c9aee199e5d');
$input->bind($this->decode->getDefinition());

$output = new BufferedOutput();

Expand Down
Loading

0 comments on commit 93a056a

Please sign in to comment.