diff --git a/bin/uuid b/bin/uuid deleted file mode 100755 index 4359f9f..0000000 --- a/bin/uuid +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env php - - * @license http://opensource.org/licenses/MIT MIT - */ - -date_default_timezone_set('UTC'); - -if (PHP_SAPI !== 'cli') { - die('uuid should be invoked via the CLI version of PHP, not the ' . PHP_SAPI . ' SAPI' . PHP_EOL); -} - -$files = array( - __DIR__ . '/../vendor/autoload.php', - __DIR__ . '/../../../autoload.php', -); - -foreach ($files as $file) { - if (file_exists($file)) { - require $file; - define('UUID_COMPOSER_INSTALL', $file); - break; - } -} - -if (!defined('UUID_COMPOSER_INSTALL')) { - die( - 'You need to set up the project dependencies using the following commands:' . PHP_EOL . - 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . - 'php composer.phar install' . PHP_EOL - ); -} - -// We require the Symfony Console component and Moontoast\Math to run -// this command line tool. -if (!class_exists('Symfony\Component\Console\Application') || !class_exists('Moontoast\Math\BigNumber')) { - die( - 'To use the uuid command line tool, you need to install symfony/console' . PHP_EOL . - 'and moontoast/math. To do so, run the following Composer commands:' . PHP_EOL . - '' . PHP_EOL . - 'composer.phar require "moontoast/math=~1.1" "symfony/console=~2.3"' . PHP_EOL - ); -} - -use Ramsey\Uuid\Console\Application; -use Ramsey\Uuid\Console\Command; - -$app = new Application(); -$app->add(new Command\GenerateCommand()); -$app->add(new Command\DecodeCommand()); -$app->run(); diff --git a/composer.json b/composer.json index 7d718c4..027e6b9 100644 --- a/composer.json +++ b/composer.json @@ -30,18 +30,16 @@ "require-dev": { "moontoast/math": "~1.1", "ircmaxell/random-lib": "~1.0", - "symfony/console": "~2.3", "phpunit/phpunit": "~4.5", "squizlabs/php_codesniffer": "^2.3", "jakub-onderka/php-parallel-lint": "^0.9.0", "satooshi/php-coveralls": "~0.6" }, - "bin": ["bin/uuid"], "suggest": { "ramsey/uuid-doctrine": "Allow the use of a UUID as Doctrine field type.", + "ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid", "moontoast/math": "Support for converting UUID to 128-bit integer (in string form).", - "ircmaxell/random-lib": "Provides RandomLib to use with the RandomLibAdapter", - "symfony/console": "Support for use of the bin/uuid command line tool." + "ircmaxell/random-lib": "Provides RandomLib to use with the RandomLibAdapter" }, "autoload": { "psr-4": {"Ramsey\\Uuid\\": "src/"} diff --git a/src/Console/Application.php b/src/Console/Application.php deleted file mode 100644 index d146471..0000000 --- a/src/Console/Application.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -namespace Ramsey\Uuid\Console; - -use Ramsey\Uuid\Console\Util; -use Ramsey\Uuid\Uuid; -use Symfony\Component\Console\Application as BaseApplication; - -/** - * The console application that handles CLI commands - */ -class Application extends BaseApplication -{ - /** - * Constructor - */ - public function __construct() - { - Util\ErrorHandler::register(); - parent::__construct('uuid', Uuid::VERSION); - } -} diff --git a/src/Console/Command/DecodeCommand.php b/src/Console/Command/DecodeCommand.php deleted file mode 100644 index 00512cc..0000000 --- a/src/Console/Command/DecodeCommand.php +++ /dev/null @@ -1,66 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -namespace Ramsey\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\Output\OutputInterface; -use Ramsey\Uuid\Console\Exception; -use Ramsey\Uuid\Uuid; -use Ramsey\Uuid\Console\Util\UuidFormatter; -use Symfony\Component\Console\Helper\Table; - -/** - * Provides the console command to decode UUIDs and dump information about them - */ -class DecodeCommand extends Command -{ - /** - * {@inheritDoc} - */ - protected function configure() - { - parent::configure(); - - $this->setName('decode') - ->setDescription('Decode a UUID and dump information about it') - ->addArgument( - 'uuid', - InputArgument::REQUIRED, - 'The UUID to decode.' - ); - } - - /** - * {@inheritDoc} - * - * @param InputInterface $input - * @param OutputInterface $output - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if (!Uuid::isValid($input->getArgument('uuid'))) { - throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')'); - } - - $uuid = Uuid::fromString($input->getArgument('uuid')); - - $table = $this->getHelperSet()->get('table'); - $table->setLayout(TableHelper::LAYOUT_BORDERLESS); - - (new UuidFormatter())->write($table, $uuid); - - $table->render($output); - } -} diff --git a/src/Console/Command/GenerateCommand.php b/src/Console/Command/GenerateCommand.php deleted file mode 100644 index 6b55f9c..0000000 --- a/src/Console/Command/GenerateCommand.php +++ /dev/null @@ -1,200 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -namespace Ramsey\Uuid\Console\Command; - -use Symfony\Component\Console\Command\Command; -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 Ramsey\Uuid\Console\Exception; -use Ramsey\Uuid\Uuid; -use Ramsey\Uuid\Generator\CombGenerator; -use Ramsey\Uuid\Codec\GuidStringCodec; -use Ramsey\Uuid\FeatureSet; -use Ramsey\Uuid\UuidFactory; - -/** - * Provides the console command to generate UUIDs - */ -class GenerateCommand extends Command -{ - /** - * {@inheritDoc} - */ - protected function configure() - { - parent::configure(); - - $this->setName('generate') - ->setDescription('Generate a UUID') - ->addArgument( - 'version', - InputArgument::OPTIONAL, - 'The UUID version to generate. Supported are version "1", "3", ' - . '"4" and "5".', - 1 - ) - ->addArgument( - 'namespace', - InputArgument::OPTIONAL, - 'For version 3 or 5 UUIDs, the namespace to create a UUID for. ' - . 'May be either a UUID in string representation or an identifier ' - . 'for internally pre-defined namespace UUIDs (currently known ' - . 'are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500").' - ) - ->addArgument( - 'name', - InputArgument::OPTIONAL, - 'For version 3 or 5 UUIDs, the name to create a UUID for. ' - . 'The name is a string of arbitrary length.' - ) - ->addOption( - 'count', - 'c', - InputOption::VALUE_REQUIRED, - 'Generate count UUIDs instead of just a single one.', - 1 - ) - ->addOption( - 'comb', - null, - InputOption::VALUE_NONE, - 'For version 4 UUIDs, uses the COMB strategy to generate the random data.' - ) - ->addOption( - 'guid', - 'g', - InputOption::VALUE_NONE, - 'Returns a GUID formatted UUID.' - ); - } - - /** - * {@inheritDoc} - * - * @param InputInterface $input - * @param OutputInterface $output - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $uuids = array(); - - $count = filter_var( - $input->getOption('count'), - FILTER_VALIDATE_INT, - array( - 'default' => 1, - 'min_range' => 1, - ) - ); - - if (((bool) $input->getOption('guid')) == true) { - $features = new FeatureSet(true); - - Uuid::setFactory(new UuidFactory($features)); - } - - if (((bool) $input->getOption('comb')) === true) { - Uuid::getFactory()->setRandomGenerator( - new CombGenerator( - Uuid::getFactory()->getRandomGenerator(), - Uuid::getFactory()->getNumberConverter() - ) - ); - } - - for ($i = 0; $i < $count; $i++) { - $uuids[] = $this->createUuid( - $input->getArgument('version'), - $input->getArgument('namespace'), - $input->getArgument('name') - ); - } - - foreach ($uuids as $uuid) { - $output->writeln((string) $uuid); - } - } - - /** - * Creates the requested UUID - * - * @param int $version - * @param string $namespace - * @param string $name - * @return Uuid - */ - protected function createUuid($version, $namespace = null, $name = null) - { - switch ((int) $version) { - case 1: - $uuid = Uuid::uuid1(); - break; - case 4: - $uuid = Uuid::uuid4(); - break; - case 3: - case 5: - $ns = $this->validateNamespace($namespace); - if (empty($name)) { - throw new Exception('The name argument is required for version 3 or 5 UUIDs'); - } - if ($version == 3) { - $uuid = Uuid::uuid3($ns, $name); - } else { - $uuid = Uuid::uuid5($ns, $name); - } - break; - default: - throw new Exception('Invalid UUID version. Supported are version "1", "3", "4", and "5".'); - } - - return $uuid; - } - - /** - * Validates the namespace argument - * - * @param string $namespace - * @return string The namespace, if valid - * @throws Exception - */ - protected function validateNamespace($namespace) - { - switch ($namespace) { - case 'ns:DNS': - return Uuid::NAMESPACE_DNS; - break; - case 'ns:URL': - return Uuid::NAMESPACE_URL; - break; - case 'ns:OID': - return Uuid::NAMESPACE_OID; - break; - case 'ns:X500': - return Uuid::NAMESPACE_X500; - break; - } - - if (Uuid::isValid($namespace)) { - return $namespace; - } - - throw new Exception( - 'Invalid namespace. ' - . 'May be either a UUID in string representation or an identifier ' - . 'for internally pre-defined namespace UUIDs (currently known ' - . 'are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500").' - ); - } -} diff --git a/src/Console/Exception.php b/src/Console/Exception.php deleted file mode 100644 index f8970a9..0000000 --- a/src/Console/Exception.php +++ /dev/null @@ -1,19 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -namespace Ramsey\Uuid\Console; - -/** - * Console exception - */ -class Exception extends \RuntimeException -{ -} diff --git a/src/Console/Util/ErrorHandler.php b/src/Console/Util/ErrorHandler.php deleted file mode 100644 index cd0fa23..0000000 --- a/src/Console/Util/ErrorHandler.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -namespace Ramsey\Uuid\Console\Util; - -/** - * Convert PHP errors into exceptions - */ -class ErrorHandler -{ - /** - * Error handler - * - * @param int $level Level of the error raised - * @param string $message Error message - * @param string $file Filename that the error was raised in - * @param int $line Line number the error was raised at - * - * @static - * @throws \ErrorException - */ - public static function handle($level, $message, $file, $line) - { - // respect error_reporting being disabled - if (!error_reporting()) { - return; - } - - throw new \ErrorException($message, 0, $level, $file, $line); - } - - /** - * Register error handler - * - * @static - */ - public static function register() - { - set_error_handler(array(__CLASS__, 'handle')); - } -} diff --git a/src/Console/Util/Formatter/V1Formatter.php b/src/Console/Util/Formatter/V1Formatter.php deleted file mode 100644 index 1486c9b..0000000 --- a/src/Console/Util/Formatter/V1Formatter.php +++ /dev/null @@ -1,19 +0,0 @@ -getDateTime()->format('c')), - array('', '', 'clock: ' . $uuid->getClockSequence() . ' (usually random)'), - array('', '', 'node: ' . substr(chunk_split($uuid->getNodeHex(), 2, ':'), 0, -1)), - ); - } -} diff --git a/src/Console/Util/Formatter/V2Formatter.php b/src/Console/Util/Formatter/V2Formatter.php deleted file mode 100644 index df08bcb..0000000 --- a/src/Console/Util/Formatter/V2Formatter.php +++ /dev/null @@ -1,15 +0,0 @@ -getHex(), 2, ':'), 0, -1)), - array('', '', '(not decipherable: MD5 message digest only)'), - ); - } -} diff --git a/src/Console/Util/Formatter/V4Formatter.php b/src/Console/Util/Formatter/V4Formatter.php deleted file mode 100644 index 3dd5f8a..0000000 --- a/src/Console/Util/Formatter/V4Formatter.php +++ /dev/null @@ -1,18 +0,0 @@ -getHex(), 2, ':'), 0, -1)), - array('', '', '(no semantics: random data only)'), - ); - } -} diff --git a/src/Console/Util/Formatter/V5Formatter.php b/src/Console/Util/Formatter/V5Formatter.php deleted file mode 100644 index fa41f21..0000000 --- a/src/Console/Util/Formatter/V5Formatter.php +++ /dev/null @@ -1,18 +0,0 @@ -getHex(), 2, ':'), 0, -1)), - array('', '', '(not decipherable: SHA1 message digest only)'), - ); - } -} diff --git a/src/Console/Util/UuidContentFormatterInterface.php b/src/Console/Util/UuidContentFormatterInterface.php deleted file mode 100644 index aa7b7ef..0000000 --- a/src/Console/Util/UuidContentFormatterInterface.php +++ /dev/null @@ -1,10 +0,0 @@ - '1 (time and node based)', - 2 => '2 (DCE security based)', - 3 => '3 (name based, MD5)', - 4 => '4 (random data based)', - 5 => '5 (name based, SHA-1)' - ]; - - private static $variantMap = [ - Uuid::RESERVED_NCS => 'Reserved', - Uuid::RFC_4122 => 'RFC 4122', - Uuid::RESERVED_MICROSOFT => 'Reserved for Microsoft use.', - Uuid::RESERVED_FUTURE => 'Reserved for future use.' - ]; - - private static $formatters; - - public function __construct() - { - if (self::$formatters == null) { - self::$formatters = [ - 1 => new V1Formatter(), - 2 => new V2Formatter(), - 3 => new V3Formatter(), - 4 => new V4Formatter(), - 5 => new V5Formatter() - ]; - } - } - - public function write(TableHelper $table, UuidInterface $uuid) - { - $table->addRows(array( - array('encode:', 'STR:', (string) $uuid), - array('', 'INT:', (string) $uuid->getInteger()), - )); - - if ($uuid->getVariant() == Uuid::RFC_4122) { - $table->addRows(array( - array('decode:', 'variant:',$this->getFormattedVariant($uuid)), - array('', 'version:', $this->getFormattedVersion($uuid)), - )); - - $table->addRows($this->getContent($uuid)); - } else { - $table->addRows(array( - array('decode:', 'variant:', 'Not an RFC 4122 UUID'), - )); - } - } - - public function getFormattedVersion(UuidInterface $uuid) - { - return self::$versionMap[$uuid->getVersion()]; - } - - public function getFormattedVariant(UuidInterface $uuid) - { - return self::$variantMap[$uuid->getVariant()]; - } - - /** - * Returns content as an array of rows, each row being an array containing column values. - */ - public function getContent(UuidInterface $uuid) - { - $formatter = self::$formatters[$uuid->getVersion()]; - - return $formatter->getContent($uuid); - } -} diff --git a/tests/Console/ApplicationTest.php b/tests/Console/ApplicationTest.php deleted file mode 100644 index 5e040b0..0000000 --- a/tests/Console/ApplicationTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertInstanceOf('Ramsey\\Uuid\\Console\\Application', $app); - $this->assertEquals('uuid', $app->getName()); - $this->assertEquals(\Ramsey\Uuid\Uuid::VERSION, $app->getVersion()); - } -} diff --git a/tests/Console/Command/DecodeCommandTest.php b/tests/Console/Command/DecodeCommandTest.php deleted file mode 100644 index d32de49..0000000 --- a/tests/Console/Command/DecodeCommandTest.php +++ /dev/null @@ -1,167 +0,0 @@ -execute = new \ReflectionMethod('Ramsey\\Uuid\\Console\\Command\\DecodeCommand', 'execute'); - $this->execute->setAccessible(true); - - $this->decode = new DecodeCommand(); - $this->decode->setApplication(new \Ramsey\Uuid\Console\Application()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::configure - */ - public function testConfigure() - { - $decode = new DecodeCommand(); - - $this->assertEquals('decode', $decode->getName()); - $this->assertEquals('Decode a UUID and dump information about it', $decode->getDescription()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - * @expectedException Ramsey\Uuid\Console\Exception - * @expectedExceptionMessage Invalid UUID - */ - public function testExecuteForInvalidUuid() - { - $input = new StringInput( - 'foobar', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - */ - public function testExecuteForNonRFC4122Uuid() - { - $expected = file_get_contents('tests/console-mocks/testExecuteForNonRFC4122Uuid.txt'); - - $input = new StringInput( - 'ff6f8cb0-c57d-11e1-0b21-0800200c9a66', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - - $this->assertEquals($expected, $output->fetch()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - */ - public function testExecuteForVersion1Uuid() - { - $expected = file_get_contents('tests/console-mocks/testExecuteForVersion1Uuid.txt'); - - $input = new StringInput( - '2ddbf60e-7fc4-11e3-a5ac-080027cd5e4d', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - - $this->assertEquals($expected, $output->fetch()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - */ - public function testExecuteForVersion2Uuid() - { - $expected = file_get_contents('tests/console-mocks/testExecuteForVersion2Uuid.txt'); - - $input = new StringInput( - '6fa459ea-ee8a-2ca4-894e-db77e160355e', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - - $this->assertEquals($expected, $output->fetch()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - */ - public function testExecuteForVersion3Uuid() - { - $expected = file_get_contents('tests/console-mocks/testExecuteForVersion3Uuid.txt'); - - $input = new StringInput( - '6fa459ea-ee8a-3ca4-894e-db77e160355e', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - - $this->assertEquals($expected, $output->fetch()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - */ - public function testExecuteForVersion4Uuid() - { - $expected = file_get_contents('tests/console-mocks/testExecuteForVersion4Uuid.txt'); - - $input = new StringInput( - '83fc61b6-b5ef-467f-9a15-89ddee668005', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - - $this->assertEquals($expected, $output->fetch()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\DecodeCommand::execute - */ - public function testExecuteForVersion5Uuid() - { - $expected = file_get_contents('tests/console-mocks/testExecuteForVersion5Uuid.txt'); - - $input = new StringInput( - '886313e1-3b8a-5372-9b90-0c9aee199e5d', - $this->decode->getDefinition() - ); - - $output = new BufferedOutput(); - - $this->execute->invoke($this->decode, $input, $output); - - $this->assertEquals($expected, $output->fetch()); - } -} diff --git a/tests/Console/Command/GenerateCommandTest.php b/tests/Console/Command/GenerateCommandTest.php deleted file mode 100644 index 3f7c203..0000000 --- a/tests/Console/Command/GenerateCommandTest.php +++ /dev/null @@ -1,638 +0,0 @@ -execute = new \ReflectionMethod('Ramsey\\Uuid\\Console\\Command\\GenerateCommand', 'execute'); - $this->execute->setAccessible(true); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::configure - */ - public function testConfigure() - { - $generate = new GenerateCommand(); - - $this->assertEquals('generate', $generate->getName()); - $this->assertEquals('Generate a UUID', $generate->getDescription()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - */ - public function testExecuteForUuidDefault() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(1, Uuid::fromString($output->messages[0])->getVersion()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - */ - public function testExecuteForUuidDefaultWithCount() - { - $generate = new GenerateCommand(); - - // - // Test using the "-c" option - // - - $input1 = new StringInput( - '-c 9', - $generate->getDefinition() - ); - - $output1 = new TestOutput(); - $this->execute->invoke($generate, $input1, $output1); - - $this->assertCount(9, $output1->messages); - - foreach ($output1->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(1, Uuid::fromString($uuid)->getVersion()); - } - - // - // Test using the "--count" option - // - - $input2 = new StringInput( - '--count=12', - $generate->getDefinition() - ); - - $output2 = new TestOutput(); - $this->execute->invoke($generate, $input2, $output2); - - $this->assertCount(12, $output2->messages); - - foreach ($output2->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(1, Uuid::fromString($uuid)->getVersion()); - } - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - */ - public function testExecuteForUuidSpecifyVersion1() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '1', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(1, Uuid::fromString($output->messages[0])->getVersion()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - */ - public function testExecuteForUuidSpecifyVersion1WithCount() - { - $generate = new GenerateCommand(); - - // - // Test using the "-c" option - // - - $input1 = new StringInput( - '1 -c 3', - $generate->getDefinition() - ); - - $output1 = new TestOutput(); - $this->execute->invoke($generate, $input1, $output1); - - $this->assertCount(3, $output1->messages); - - foreach ($output1->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(1, Uuid::fromString($uuid)->getVersion()); - } - - // - // Test using the "--count" option - // - - $input2 = new StringInput( - '1 --count=8', - $generate->getDefinition() - ); - - $output2 = new TestOutput(); - $this->execute->invoke($generate, $input2, $output2); - - $this->assertCount(8, $output2->messages); - - foreach ($output2->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(1, Uuid::fromString($uuid)->getVersion()); - } - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - */ - public function testExecuteForUuidSpecifyVersion4() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '4', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(4, Uuid::fromString($output->messages[0])->getVersion()); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - */ - public function testExecuteForUuidSpecifyVersion4WithCount() - { - $generate = new GenerateCommand(); - - // - // Test using the "-c" option - // - - $input1 = new StringInput( - '4 -c 3', - $generate->getDefinition() - ); - - $output1 = new TestOutput(); - $this->execute->invoke($generate, $input1, $output1); - - $this->assertCount(3, $output1->messages); - - foreach ($output1->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(4, Uuid::fromString($uuid)->getVersion()); - } - - // - // Test using the "--count" option - // - - $input2 = new StringInput( - '4 --count=8', - $generate->getDefinition() - ); - - $output2 = new TestOutput(); - $this->execute->invoke($generate, $input2, $output2); - - $this->assertCount(8, $output2->messages); - - foreach ($output2->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(4, Uuid::fromString($uuid)->getVersion()); - } - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion3WithDnsNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 ns:DNS "python.org"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(3, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('6fa459ea-ee8a-3ca4-894e-db77e160355e', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion3WithUrlNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 ns:URL "http://python.org/"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(3, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('9fe8e8c4-aaa8-32a9-a55c-4535a88b748d', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion3WithOidNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 ns:OID "1.3.6.1"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(3, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('dd1a1cef-13d5-368a-ad82-eca71acd4cd1', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion3WithX500Ns() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 ns:X500 "c=ca"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(3, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('658d3002-db6b-3040-a1d1-8ddd7d189a4d', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion3WithOtherNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 bbd8a651-6f00-11e3-8ad8-28cfe91e4895 foobar', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(3, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('0707b2c0-1f0f-3b2b-9a90-371396a90a86', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - * @expectedException Ramsey\Uuid\Console\Exception - * @expectedExceptionMessage May be either a UUID in string representation or an identifier - */ - public function testExecuteForUuidSpecifyVersion3WithInvalidNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 foo foobar', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion3WithCount() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 ns:DNS "python.org" -c 21', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(21, $output->messages); - - foreach ($output->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(3, Uuid::fromString($uuid)->getVersion()); - $this->assertEquals('6fa459ea-ee8a-3ca4-894e-db77e160355e', $uuid); - } - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - * @expectedException Ramsey\Uuid\Console\Exception - * @expectedExceptionMessage The name argument is required for version 3 or 5 UUIDs - */ - public function testExecuteForUuidSpecifyVersion3WithoutName() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '3 ns:DNS', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion5WithDnsNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 ns:DNS "python.org"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(5, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('886313e1-3b8a-5372-9b90-0c9aee199e5d', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion5WithUrlNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 ns:URL "http://python.org/"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(5, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('4c565f0d-3f5a-5890-b41b-20cf47701c5e', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion5WithOidNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 ns:OID "1.3.6.1"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(5, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('1447fa61-5277-5fef-a9b3-fbc6e44f4af3', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion5WithX500Ns() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 ns:X500 "c=ca"', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(5, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('cc957dd1-a972-5349-98cd-874190002798', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion5WithOtherNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 bbd8a651-6f00-11e3-8ad8-28cfe91e4895 foobar', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(1, $output->messages); - $this->assertTrue(Uuid::isValid($output->messages[0])); - $this->assertEquals(5, Uuid::fromString($output->messages[0])->getVersion()); - $this->assertEquals('385c280b-1d07-5d6b-932b-ca7a11d2e7e5', $output->messages[0]); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - * @expectedException Ramsey\Uuid\Console\Exception - * @expectedExceptionMessage May be either a UUID in string representation or an identifier - */ - public function testExecuteForUuidSpecifyVersion5WithInvalidNs() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 foo foobar', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - */ - public function testExecuteForUuidSpecifyVersion5WithCount() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 ns:DNS "python.org" -c 21', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - - $this->assertCount(21, $output->messages); - - foreach ($output->messages as $uuid) { - $this->assertTrue(Uuid::isValid($uuid)); - $this->assertEquals(5, Uuid::fromString($uuid)->getVersion()); - $this->assertEquals('886313e1-3b8a-5372-9b90-0c9aee199e5d', $uuid); - } - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::validateNamespace - * @expectedException Ramsey\Uuid\Console\Exception - * @expectedExceptionMessage The name argument is required for version 3 or 5 UUIDs - */ - public function testExecuteForUuidSpecifyVersion5WithoutName() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '5 ns:DNS', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - } - - /** - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::execute - * @covers Ramsey\Uuid\Console\Command\GenerateCommand::createUuid - * @expectedException Ramsey\Uuid\Console\Exception - * @expectedExceptionMessage Invalid UUID version. Supported are version "1", "3", "4", and "5". - */ - public function testExecuteForUuidSpecifyInvalidVersion() - { - $generate = new GenerateCommand(); - - $input = new StringInput( - '6', - $generate->getDefinition() - ); - - $output = new TestOutput(); - - $this->execute->invoke($generate, $input, $output); - } -} diff --git a/tests/Console/TestCase.php b/tests/Console/TestCase.php deleted file mode 100644 index 727b9c1..0000000 --- a/tests/Console/TestCase.php +++ /dev/null @@ -1,13 +0,0 @@ -skipIfNoSymfonyConsole(); - $this->skipIfNoMoontoastMath(); - } -} diff --git a/tests/Console/Util/BufferedOutput.php b/tests/Console/Util/BufferedOutput.php deleted file mode 100644 index 53ef80e..0000000 --- a/tests/Console/Util/BufferedOutput.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Ramsey\Uuid\Console\Util; - -use Symfony\Component\Console\Output\Output; - -/** - * @author Jean-François Simon - */ -class BufferedOutput extends Output -{ - /** - * @var string - */ - private $buffer = ''; - - /** - * Empties buffer and returns its content. - * - * @return string - */ - public function fetch() - { - $content = $this->buffer; - $this->buffer = ''; - - return $content; - } - - /** - * {@inheritdoc} - */ - protected function doWrite($message, $newline) - { - $this->buffer .= $message; - - if ($newline) { - $this->buffer .= "\n"; - } - } -} diff --git a/tests/Console/Util/ErrorHandlerTest.php b/tests/Console/Util/ErrorHandlerTest.php deleted file mode 100644 index a49015a..0000000 --- a/tests/Console/Util/ErrorHandlerTest.php +++ /dev/null @@ -1,49 +0,0 @@ -assertEquals($expected, $testHandler); - } - - /** - * @covers Ramsey\Uuid\Console\Util\ErrorHandler::handle - * @expectedException ErrorException - * @expectedExceptionMessage Test exception - */ - public function testHandle() - { - error_reporting(E_ALL); - ErrorHandler::handle(1, 'Test exception', __FILE__, __LINE__); - } - - /** - * @covers Ramsey\Uuid\Console\Util\ErrorHandler::handle - */ - public function testHandleNoException() - { - error_reporting(0); - - $this->assertEmpty(ErrorHandler::handle(1, 'Test exception', __FILE__, __LINE__)); - } -} diff --git a/tests/Console/Util/TestOutput.php b/tests/Console/Util/TestOutput.php deleted file mode 100644 index 968a64e..0000000 --- a/tests/Console/Util/TestOutput.php +++ /dev/null @@ -1,14 +0,0 @@ -messages[] = $message; - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 178a14f..63ec65f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -21,22 +21,8 @@ class TestCase extends \PHPUnit_Framework_TestCase } } - protected function skipIfNoSymfonyConsole() - { - if (!$this->hasSymfonyConsole()) { - $this->markTestSkipped( - 'Skipping test that requires symfony/console.' - ); - } - } - protected function hasMoontoastMath() { return class_exists('Moontoast\\Math\\BigNumber'); } - - protected function hasSymfonyConsole() - { - return class_exists('Symfony\\Component\\Console\\Application'); - } } diff --git a/tests/console-mocks/testExecuteForNonRFC4122Uuid.txt b/tests/console-mocks/testExecuteForNonRFC4122Uuid.txt deleted file mode 100644 index c1da839..0000000 --- a/tests/console-mocks/testExecuteForNonRFC4122Uuid.txt +++ /dev/null @@ -1,5 +0,0 @@ - ========= ========== ========================================= - encode: STR: ff6f8cb0-c57d-11e1-0b21-0800200c9a66 - INT: 339532337419071774295426818102463863398 - decode: variant: Not an RFC 4122 UUID - ========= ========== ========================================= diff --git a/tests/console-mocks/testExecuteForVersion1Uuid.txt b/tests/console-mocks/testExecuteForVersion1Uuid.txt deleted file mode 100644 index 4021e4c..0000000 --- a/tests/console-mocks/testExecuteForVersion1Uuid.txt +++ /dev/null @@ -1,9 +0,0 @@ - ========= ========== ======================================== - encode: STR: 2ddbf60e-7fc4-11e3-a5ac-080027cd5e4d - INT: 60957363443838745229478843813485960781 - decode: variant: RFC 4122 - version: 1 (time and node based) - content: time: 2014-01-17T22:10:31+00:00 - clock: 9644 (usually random) - node: 08:00:27:cd:5e:4d - ========= ========== ======================================== diff --git a/tests/console-mocks/testExecuteForVersion2Uuid.txt b/tests/console-mocks/testExecuteForVersion2Uuid.txt deleted file mode 100644 index 4fe7f72..0000000 --- a/tests/console-mocks/testExecuteForVersion2Uuid.txt +++ /dev/null @@ -1,6 +0,0 @@ - ========= ========== ========================================= - encode: STR: 6fa459ea-ee8a-2ca4-894e-db77e160355e - INT: 148397667964594601879796619558430717278 - decode: variant: RFC 4122 - version: 2 (DCE security based) - ========= ========== ========================================= diff --git a/tests/console-mocks/testExecuteForVersion3Uuid.txt b/tests/console-mocks/testExecuteForVersion3Uuid.txt deleted file mode 100644 index 326642f..0000000 --- a/tests/console-mocks/testExecuteForVersion3Uuid.txt +++ /dev/null @@ -1,8 +0,0 @@ - ========= ========== ================================================= - encode: STR: 6fa459ea-ee8a-3ca4-894e-db77e160355e - INT: 148397667964594677437660345472754136414 - decode: variant: RFC 4122 - version: 3 (name based, MD5) - content: 6f:a4:59:ea:ee:8a:3c:a4:89:4e:db:77:e1:60:35:5e - (not decipherable: MD5 message digest only) - ========= ========== ================================================= diff --git a/tests/console-mocks/testExecuteForVersion4Uuid.txt b/tests/console-mocks/testExecuteForVersion4Uuid.txt deleted file mode 100644 index 0c80511..0000000 --- a/tests/console-mocks/testExecuteForVersion4Uuid.txt +++ /dev/null @@ -1,8 +0,0 @@ - ========= ========== ================================================= - encode: STR: 83fc61b6-b5ef-467f-9a15-89ddee668005 - INT: 175439308125737940688973558970912768005 - decode: variant: RFC 4122 - version: 4 (random data based) - content: 83:fc:61:b6:b5:ef:46:7f:9a:15:89:dd:ee:66:80:05 - (no semantics: random data only) - ========= ========== ================================================= diff --git a/tests/console-mocks/testExecuteForVersion5Uuid.txt b/tests/console-mocks/testExecuteForVersion5Uuid.txt deleted file mode 100644 index 2498622..0000000 --- a/tests/console-mocks/testExecuteForVersion5Uuid.txt +++ /dev/null @@ -1,8 +0,0 @@ - ========= ========== ================================================= - encode: STR: 886313e1-3b8a-5372-9b90-0c9aee199e5d - INT: 181289448026289383154478846676280385117 - decode: variant: RFC 4122 - version: 5 (name based, SHA-1) - content: 88:63:13:e1:3b:8a:53:72:9b:90:0c:9a:ee:19:9e:5d - (not decipherable: SHA1 message digest only) - ========= ========== =================================================