ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UuidTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22
23use PHPUnit\Framework\TestCase;
26use Ramsey\Uuid\Exception\InvalidUuidStringException;
27
28class UuidTest extends TestCase
29{
30 private const VALID_UUID4 = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$/';
31
32 private const UUID4 = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
33 private const NO_UUID = 'lorem ipsum dolor';
34
35 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
36 public function test_init(): Factory
37 {
38 return new Factory();
39 }
40
41 #[\PHPUnit\Framework\Attributes\Depends('test_init')]
42 public function test_uuid4(): void
43 {
44 $factory = new Factory();
45 $uuid = $factory->uuid4();
46
47 $this->assertMatchesRegularExpression(self::VALID_UUID4, $uuid->toString());
48 }
49
50 #[\PHPUnit\Framework\Attributes\Depends('test_init')]
51 public function test_uuid4_string(): void
52 {
53 $factory = new Factory();
54 $uuid = $factory->uuid4AsString();
55
56 $this->assertIsString($uuid);
57 $this->assertMatchesRegularExpression(self::VALID_UUID4, $uuid);
58 }
59
60 #[\PHPUnit\Framework\Attributes\Depends('test_init')]
61 public function test_from_string(): void
62 {
63 $factory = new Factory();
64 $uuid = $factory->fromString(self::UUID4);
65
66 $this->assertMatchesRegularExpression(self::VALID_UUID4, $uuid->toString());
67 $this->assertEquals(self::UUID4, $uuid->toString());
68 }
69
70 #[\PHPUnit\Framework\Attributes\Depends('test_init')]
71 public function test_from_illegal_string(): void
72 {
73 $this->expectException(InvalidUuidStringException::class);
74
75 $factory = new Factory();
76 $factory->fromString(self::NO_UUID);
77 }
78}
test_from_illegal_string()
Definition: UuidTest.php:71
test_uuid4_string()
Definition: UuidTest.php:51
const VALID_UUID4
Definition: UuidTest.php:30
const NO_UUID
Definition: UuidTest.php:33
test_uuid4()
Definition: UuidTest.php:42
test_from_string()
Definition: UuidTest.php:61
test_init()
Definition: UuidTest.php:36
const UUID4
Definition: UuidTest.php:32