ILIAS  release_8 Revision v8.24
UuidTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5require_once("libs/composer/vendor/autoload.php");
6
7use PHPUnit\Framework\TestCase;
10use Ramsey\Uuid\Exception\InvalidUuidStringException;
11
12class UuidTest extends TestCase
13{
14 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}$/';
15
16 private const UUID4 = 'f47ac10b-58cc-4372-a567-0e02b2c3d479';
17 private const NO_UUID = 'lorem ipsum dolor';
18
22 public function test_init(): Factory
23 {
24 return new Factory();
25 }
26
30 public function test_uuid4(): void
31 {
32 $factory = new Factory();
33 $uuid = $factory->uuid4();
34
35 $this->assertMatchesRegularExpression(self::VALID_UUID4, $uuid->toString());
36 }
37
41 public function test_uuid4_string(): void
42 {
43 $factory = new Factory();
44 $uuid = $factory->uuid4AsString();
45
46 $this->assertIsString($uuid);
47 $this->assertMatchesRegularExpression(self::VALID_UUID4, $uuid);
48 }
49
53 public function test_from_string(): void
54 {
55 $factory = new Factory();
56 $uuid = $factory->fromString(self::UUID4);
57
58 $this->assertMatchesRegularExpression(self::VALID_UUID4, $uuid->toString());
59 $this->assertEquals(self::UUID4, $uuid->toString());
60 }
61
65 public function test_from_illegal_string(): void
66 {
67 $this->expectException(InvalidUuidStringException::class);
68
69 $factory = new Factory();
70 $factory->fromString(self::NO_UUID);
71 }
72}
test_from_illegal_string()
@depends test_init
Definition: UuidTest.php:65
test_uuid4_string()
@depends test_init
Definition: UuidTest.php:41
const VALID_UUID4
Definition: UuidTest.php:14
const NO_UUID
Definition: UuidTest.php:17
test_uuid4()
@depends test_init
Definition: UuidTest.php:30
test_from_string()
@depends test_init
Definition: UuidTest.php:53
test_init()
@doesNotPerformAssertions
Definition: UuidTest.php:22
const UUID4
Definition: UuidTest.php:16
$factory
Definition: metadata.php:75