-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathShortUuidTest.php
More file actions
91 lines (80 loc) · 2.37 KB
/
Copy pathShortUuidTest.php
File metadata and controls
91 lines (80 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace PascalDeVink\ShortUuid\Tests;
use PascalDeVink\ShortUuid\ShortUuid;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* @covers \PascalDeVink\ShortUuid\ShortUuid
* @group FullCoverage
*/
class ShortUuidTest extends TestCase
{
/**
* @var ShortUuid
*/
private ShortUuid $shortUuid;
public function setUp() : void
{
$this->shortUuid = new ShortUuid();
}
/**
* @test
* @dataProvider uuid_provider
*/
public function it_should_encode_a_given_uuid($uuid, $expectedShortUuid): void
{
$shortUuid = $this->shortUuid->encode($uuid);
$this->assertSame($expectedShortUuid, $shortUuid);
}
public function uuid_provider(): array
{
return [
[Uuid::fromString('4e52c919-513e-4562-9248-7dd612c6c1ca'), 'fpfyRTmt6XeE9ehEKZ5LwF'],
[Uuid::fromString('59a3e9ab-6b99-4936-928a-d8b465dd41e0'), 'BnxtX5wGumMUWXmnbey6xH'],
];
}
/**
* @test
* @dataProvider shortuuid_provider
*/
public function it_should_decode_a_given_short_uuid($shortUuid, $expectedUuid): void
{
$uuid = $this->shortUuid->decode($shortUuid);
$this->assertTrue($expectedUuid->equals($uuid));
}
public function shortuuid_provider(): array
{
return [
['fpfyRTmt6XeE9ehEKZ5LwF', Uuid::fromString('4e52c919-513e-4562-9248-7dd612c6c1ca')],
['BnxtX5wGumMUWXmnbey6xH', Uuid::fromString('59a3e9ab-6b99-4936-928a-d8b465dd41e0')],
];
}
/**
* @test
*/
public function it_should_generate_a_short_uuid1(): void
{
$shortUuid = ShortUuid::uuid1();
$this->assertLessThanOrEqual(22, strlen($shortUuid));
$this->assertGreaterThanOrEqual(20, strlen($shortUuid));
}
/**
* @test
*/
public function it_should_generate_a_short_uuid4(): void
{
$shortUuid = ShortUuid::uuid4();
$this->assertLessThanOrEqual(22, strlen($shortUuid));
$this->assertGreaterThanOrEqual(20, strlen($shortUuid));
}
/**
* @test
*/
public function it_should_generate_a_short_uuid5(): void
{
$shortUuid = ShortUuid::uuid5(Uuid::NAMESPACE_DNS, 'ticketswap.com');
$this->assertLessThanOrEqual(22, strlen($shortUuid));
$this->assertGreaterThanOrEqual(20, strlen($shortUuid));
}
}