-
-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate fields passed to specific UUID version classes
- Loading branch information
Showing
10 changed files
with
441 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ramsey\Uuid\Test\Rfc4122; | ||
|
||
use Mockery; | ||
use Ramsey\Uuid\Codec\CodecInterface; | ||
use Ramsey\Uuid\Converter\NumberConverterInterface; | ||
use Ramsey\Uuid\Converter\TimeConverterInterface; | ||
use Ramsey\Uuid\Exception\InvalidArgumentException; | ||
use Ramsey\Uuid\Rfc4122\FieldsInterface; | ||
use Ramsey\Uuid\Rfc4122\UuidV1; | ||
use Ramsey\Uuid\Test\TestCase; | ||
|
||
class UuidV1Test extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideTestVersions | ||
*/ | ||
public function testConstructorThrowsExceptionWhenFieldsAreNotValidForType(int $version): void | ||
{ | ||
$fields = Mockery::mock(FieldsInterface::class, [ | ||
'getVersion' => $version, | ||
]); | ||
|
||
$numberConverter = Mockery::mock(NumberConverterInterface::class); | ||
$codec = Mockery::mock(CodecInterface::class); | ||
$timeConverter = Mockery::mock(TimeConverterInterface::class); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage( | ||
'Fields used to create a UuidV1 must represent a ' | ||
. 'version 1 (time-based) UUID' | ||
); | ||
|
||
new UuidV1($fields, $numberConverter, $codec, $timeConverter); | ||
} | ||
|
||
/** | ||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification | ||
*/ | ||
public function provideTestVersions(): array | ||
{ | ||
return [ | ||
['version' => 0], | ||
['version' => 2], | ||
['version' => 3], | ||
['version' => 4], | ||
['version' => 5], | ||
['version' => 6], | ||
['version' => 7], | ||
['version' => 8], | ||
['version' => 9], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ramsey\Uuid\Test\Rfc4122; | ||
|
||
use Mockery; | ||
use Ramsey\Uuid\Codec\CodecInterface; | ||
use Ramsey\Uuid\Converter\NumberConverterInterface; | ||
use Ramsey\Uuid\Converter\TimeConverterInterface; | ||
use Ramsey\Uuid\Exception\InvalidArgumentException; | ||
use Ramsey\Uuid\Rfc4122\FieldsInterface; | ||
use Ramsey\Uuid\Rfc4122\UuidV2; | ||
use Ramsey\Uuid\Test\TestCase; | ||
|
||
class UuidV2Test extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideTestVersions | ||
*/ | ||
public function testConstructorThrowsExceptionWhenFieldsAreNotValidForType(int $version): void | ||
{ | ||
$fields = Mockery::mock(FieldsInterface::class, [ | ||
'getVersion' => $version, | ||
]); | ||
|
||
$numberConverter = Mockery::mock(NumberConverterInterface::class); | ||
$codec = Mockery::mock(CodecInterface::class); | ||
$timeConverter = Mockery::mock(TimeConverterInterface::class); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage( | ||
'Fields used to create a UuidV2 must represent a ' | ||
. 'version 2 (DCE Security) UUID' | ||
); | ||
|
||
new UuidV2($fields, $numberConverter, $codec, $timeConverter); | ||
} | ||
|
||
/** | ||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification | ||
*/ | ||
public function provideTestVersions(): array | ||
{ | ||
return [ | ||
['version' => 0], | ||
['version' => 1], | ||
['version' => 3], | ||
['version' => 4], | ||
['version' => 5], | ||
['version' => 6], | ||
['version' => 7], | ||
['version' => 8], | ||
['version' => 9], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ramsey\Uuid\Test\Rfc4122; | ||
|
||
use Mockery; | ||
use Ramsey\Uuid\Codec\CodecInterface; | ||
use Ramsey\Uuid\Converter\NumberConverterInterface; | ||
use Ramsey\Uuid\Converter\TimeConverterInterface; | ||
use Ramsey\Uuid\Exception\InvalidArgumentException; | ||
use Ramsey\Uuid\Rfc4122\FieldsInterface; | ||
use Ramsey\Uuid\Rfc4122\UuidV3; | ||
use Ramsey\Uuid\Test\TestCase; | ||
|
||
class UuidV3Test extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideTestVersions | ||
*/ | ||
public function testConstructorThrowsExceptionWhenFieldsAreNotValidForType(int $version): void | ||
{ | ||
$fields = Mockery::mock(FieldsInterface::class, [ | ||
'getVersion' => $version, | ||
]); | ||
|
||
$numberConverter = Mockery::mock(NumberConverterInterface::class); | ||
$codec = Mockery::mock(CodecInterface::class); | ||
$timeConverter = Mockery::mock(TimeConverterInterface::class); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage( | ||
'Fields used to create a UuidV3 must represent a ' | ||
. 'version 3 (name-based, MD5-hashed) UUID' | ||
); | ||
|
||
new UuidV3($fields, $numberConverter, $codec, $timeConverter); | ||
} | ||
|
||
/** | ||
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification | ||
*/ | ||
public function provideTestVersions(): array | ||
{ | ||
return [ | ||
['version' => 0], | ||
['version' => 1], | ||
['version' => 2], | ||
['version' => 4], | ||
['version' => 5], | ||
['version' => 6], | ||
['version' => 7], | ||
['version' => 8], | ||
['version' => 9], | ||
]; | ||
} | ||
} |
Oops, something went wrong.