Merge pull request #162 from garak/specific-exception

add a specific exception for invalid UUID string
This commit is contained in:
Ben Ramsey
2017-03-11 08:30:28 -06:00
committed by GitHub
3 changed files with 25 additions and 2 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ namespace Ramsey\Uuid\Codec;
use InvalidArgumentException;
use Ramsey\Uuid\Builder\UuidBuilderInterface;
use Ramsey\Uuid\Exception\InvalidUuidStringException;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
@@ -139,7 +140,7 @@ class StringCodec implements CodecInterface
$nameParsed = implode('-', $components);
if (!Uuid::isValid($nameParsed)) {
throw new InvalidArgumentException('Invalid UUID string: ' . $encodedUuid);
throw new InvalidUuidStringException('Invalid UUID string: ' . $encodedUuid);
}
return $components;
@@ -0,0 +1,22 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Exception;
/**
* Thrown to indicate that the parsed UUID string is invalid.
*/
class InvalidUuidStringException extends \InvalidArgumentException
{
}
+1 -1
View File
@@ -80,7 +80,7 @@ class UuidTest extends TestCase
}
/**
* @expectedException InvalidArgumentException
* @expectedException \Ramsey\Uuid\Exception\InvalidUuidStringException
* @expectedExceptionMessage Invalid UUID string:
*/
public function testFromStringWithInvalidUuidString()