mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
a252f29847
As documented in https://wiki.php.net/rfc/use_global_elements, the engine (by default) does a local namespace lookup, then falls back to global namespace when first calling a global function referenced in namespaced code, unless that function is referenced via fully qualified name (FQN). By using the FQN, the actual symbol can be looked up at compile-time, both by the PHP engine and by static analysis tooling, allowing for compiler (in particular) optimizations to replace known hot-path functions with specialized opcodes. Sadly, no actual benchmark at hand: the improvements can be minimal or massive, depending on where this library is used (tight loops being most relevant).
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Ramsey\Uuid\Test\Builder;
|
|
|
|
use Mockery;
|
|
use Ramsey\Uuid\Builder\DefaultUuidBuilder;
|
|
use Ramsey\Uuid\Codec\CodecInterface;
|
|
use Ramsey\Uuid\Converter\NumberConverterInterface;
|
|
use Ramsey\Uuid\Converter\TimeConverterInterface;
|
|
use Ramsey\Uuid\Test\TestCase;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
use function hex2bin;
|
|
use function implode;
|
|
|
|
class DefaultUuidBuilderTest extends TestCase
|
|
{
|
|
public function testBuildCreatesUuid(): void
|
|
{
|
|
$numberConverter = Mockery::mock(NumberConverterInterface::class);
|
|
$timeConverter = Mockery::mock(TimeConverterInterface::class);
|
|
$codec = Mockery::mock(CodecInterface::class);
|
|
|
|
$builder = new DefaultUuidBuilder($numberConverter, $timeConverter);
|
|
|
|
$fields = [
|
|
'time_low' => '754cd475',
|
|
'time_mid' => '7e58',
|
|
'time_hi_and_version' => '4411',
|
|
'clock_seq_hi_and_reserved' => '93',
|
|
'clock_seq_low' => '22',
|
|
'node' => 'be0725c8ce01',
|
|
];
|
|
|
|
$bytes = (string) hex2bin(implode('', $fields));
|
|
|
|
$result = $builder->build($codec, $bytes);
|
|
$this->assertInstanceOf(Uuid::class, $result);
|
|
}
|
|
}
|