1 | <?php |
||
2 | |||
3 | namespace Nip\Utility\Tests; |
||
4 | |||
5 | use Nip\Utility\Uuid; |
||
6 | use Ramsey\Uuid\UuidInterface; |
||
7 | |||
8 | /** |
||
9 | * Class UuidTest |
||
10 | * @package Nip\Utility\Tests |
||
11 | */ |
||
12 | class UuidTest extends AbstractTest |
||
13 | { |
||
14 | public function test_uuid() |
||
15 | { |
||
16 | $uuid = Uuid::uuid(); |
||
17 | self::assertIsObject($uuid); |
||
18 | $uuid = (string) $uuid; |
||
19 | self::assertIsString($uuid); |
||
20 | self::assertTrue(Uuid::isValid($uuid)); |
||
21 | self::assertSame(36, strlen($uuid)); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @dataProvider validUuidList |
||
26 | * @param $uuid |
||
27 | */ |
||
28 | public function test_isValid_validList($uuid) |
||
29 | { |
||
30 | static::assertTrue(Uuid::isValid($uuid)); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @dataProvider invalidUuidList |
||
35 | * @param $uuid |
||
36 | */ |
||
37 | public function test_isValid_invalidList($uuid) |
||
38 | { |
||
39 | static::assertFalse(Uuid::isValid($uuid)); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @dataProvider validUuidList |
||
44 | * @param $uuid |
||
45 | */ |
||
46 | public function test_fromString($string) |
||
47 | { |
||
48 | $uuid = Uuid::fromString($string); |
||
49 | static::assertInstanceOf(UuidInterface::class, $uuid); |
||
50 | self::assertStringContainsStringIgnoringCase($uuid->toString(), $string); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return \string[][]LazyUuidFromString |
||
55 | */ |
||
56 | public function validUuidList() |
||
57 | { |
||
58 | return [ |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
59 | ['a0a2a2d2-0b87-4a18-83f2-2529882be2de'], |
||
60 | ['145a1e72-d11d-11e8-a8d5-f2801f1b9fd1'], |
||
61 | ['00000000-0000-0000-0000-000000000000'], |
||
62 | ['e60d3f48-95d7-4d8d-aad0-856f29a27da2'], |
||
63 | ['ff6f8cb0-c57d-11e1-9b21-0800200c9a66'], |
||
64 | ['ff6f8cb0-c57d-21e1-9b21-0800200c9a66'], |
||
65 | ['ff6f8cb0-c57d-31e1-9b21-0800200c9a66'], |
||
66 | ['ff6f8cb0-c57d-41e1-9b21-0800200c9a66'], |
||
67 | ['ff6f8cb0-c57d-51e1-9b21-0800200c9a66'], |
||
68 | ['FF6F8CB0-C57D-11E1-9B21-0800200C9A66'], |
||
69 | ]; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return \string[][] |
||
74 | */ |
||
75 | public function invalidUuidList() |
||
76 | { |
||
77 | return [ |
||
0 ignored issues
–
show
|
|||
78 | ['not a valid uuid so we can test this'], |
||
79 | ['zf6f8cb0-c57d-11e1-9b21-0800200c9a66'], |
||
80 | ['145a1e72-d11d-11e8-a8d5-f2801f1b9fd1' . PHP_EOL], |
||
81 | ['145a1e72-d11d-11e8-a8d5-f2801f1b9fd1 '], |
||
82 | [' 145a1e72-d11d-11e8-a8d5-f2801f1b9fd1'], |
||
83 | ['145a1e72-d11d-11e8-a8d5-f2z01f1b9fd1'], |
||
84 | ['3f6f8cb0-c57d-11e1-9b21-0800200c9a6'], |
||
85 | ['af6f8cb-c57d-11e1-9b21-0800200c9a66'], |
||
86 | ['af6f8cb0c57d11e19b210800200c9a66'], |
||
87 | ['ff6f8cb0-c57da-51e1-9b21-0800200c9a66'], |
||
88 | ]; |
||
89 | } |
||
90 | } |
||
91 |