Optimize codec algorithms

This commit is contained in:
Ben Ramsey
2020-01-21 22:17:32 -06:00
parent 19f01c7985
commit 4963f2320a
6 changed files with 78 additions and 180 deletions
+9 -4
View File
@@ -4,10 +4,12 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Test\Codec;
use Mockery;
use PHPUnit\Framework\MockObject\MockObject;
use Ramsey\Uuid\Builder\UuidBuilderInterface;
use Ramsey\Uuid\Codec\StringCodec;
use Ramsey\Uuid\Rfc4122\Fields;
use Ramsey\Uuid\Rfc4122\FieldsInterface;
use Ramsey\Uuid\Test\TestCase;
use Ramsey\Uuid\UuidInterface;
@@ -68,10 +70,13 @@ class StringCodecTest extends TestCase
public function testEncodeBinaryReturnsBinaryString(): void
{
$expected = hex2bin('123456781234abcdabef1234abcd4321');
$this->uuid->method('getHex')
->willReturn('123456781234abcdabef1234abcd4321');
$this->uuid->method('getBytes')
->willReturn(hex2bin('123456781234abcdabef1234abcd4321'));
$fields = Mockery::mock(FieldsInterface::class, [
'getBytes' => hex2bin('123456781234abcdabef1234abcd4321'),
]);
$this->uuid->method('getFields')->willReturn($fields);
$codec = new StringCodec($this->builder);
$result = $codec->encodeBinary($this->uuid);
$this->assertSame($expected, $result);