1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Component \Uid \Factory \MockUuidFactory ;
16- use Symfony \Component \Uid \Uuid ;
16+ use Symfony \Component \Uid \UuidV1 ;
17+ use Symfony \Component \Uid \UuidV3 ;
18+ use Symfony \Component \Uid \UuidV4 ;
19+ use Symfony \Component \Uid \UuidV5 ;
20+ use Symfony \Component \Uid \UuidV6 ;
21+ use Symfony \Component \Uid \UuidV7 ;
22+ use Symfony \Component \Uid \UuidV8 ;
1723
1824class MockUuidFactoryTest extends TestCase
1925{
@@ -22,76 +28,76 @@ public function testCreateV1()
2228 $ factory = new MockUuidFactory ([
2329 '6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' ,
2430 '6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' ,
25- ]);
31+ ], UuidV1::class );
2632
27- $ this ->assertSame ('6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v1 ());
28- $ this ->assertSame ('6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v1 ());
33+ $ this ->assertSame ('6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
34+ $ this ->assertSame ('6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
2935 }
3036
3137 public function testCreateV3 ()
3238 {
3339 $ factory = new MockUuidFactory ([
3440 '6ba7b810-9dad-31d1-80b4-00c04fd430c8 ' ,
3541 '6ba7b810-9dad-31d1-80b4-00c04fd430c8 ' ,
36- ]);
42+ ], UuidV3::class );
3743
38- $ this ->assertSame ('6ba7b810-9dad-31d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v3 ( new Uuid ( ' 00000000-0000-0000-0000-000000000000 ' ), ' name ' ));
39- $ this ->assertSame ('6ba7b810-9dad-31d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v3 ( new Uuid ( ' 00000000-0000-0000-0000-000000000000 ' ), ' name ' ));
44+ $ this ->assertSame ('6ba7b810-9dad-31d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ( ));
45+ $ this ->assertSame ('6ba7b810-9dad-31d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ( ));
4046 }
4147
4248 public function testCreateV4 ()
4349 {
4450 $ factory = new MockUuidFactory ([
4551 '6ba7b810-9dad-41d1-80b4-00c04fd430c8 ' ,
4652 '6ba7b810-9dad-41d1-80b4-00c04fd430c8 ' ,
47- ]);
53+ ], UuidV4::class );
4854
49- $ this ->assertSame ('6ba7b810-9dad-41d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v4 ());
50- $ this ->assertSame ('6ba7b810-9dad-41d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v4 ());
55+ $ this ->assertSame ('6ba7b810-9dad-41d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
56+ $ this ->assertSame ('6ba7b810-9dad-41d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
5157 }
5258
5359 public function testCreateV5 ()
5460 {
5561 $ factory = new MockUuidFactory ([
5662 '6ba7b810-9dad-51d1-80b4-00c04fd430c8 ' ,
5763 '6ba7b810-9dad-51d1-80b4-00c04fd430c8 ' ,
58- ]);
64+ ], UuidV5::class );
5965
60- $ this ->assertSame ('6ba7b810-9dad-51d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v5 ( new Uuid ( ' 00000000-0000-0000-0000-000000000000 ' ), ' name ' ));
61- $ this ->assertSame ('6ba7b810-9dad-51d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v5 ( new Uuid ( ' 00000000-0000-0000-0000-000000000000 ' ), ' name ' ));
66+ $ this ->assertSame ('6ba7b810-9dad-51d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ( ));
67+ $ this ->assertSame ('6ba7b810-9dad-51d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ( ));
6268 }
6369
6470 public function testCreateV6 ()
6571 {
6672 $ factory = new MockUuidFactory ([
6773 '6ba7b810-9dad-61d1-80b4-00c04fd430c8 ' ,
6874 '6ba7b810-9dad-61d1-80b4-00c04fd430c8 ' ,
69- ]);
75+ ], UuidV6::class );
7076
71- $ this ->assertSame ('6ba7b810-9dad-61d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v6 ());
72- $ this ->assertSame ('6ba7b810-9dad-61d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v6 ());
77+ $ this ->assertSame ('6ba7b810-9dad-61d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
78+ $ this ->assertSame ('6ba7b810-9dad-61d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
7379 }
7480
7581 public function testCreateV7 ()
7682 {
7783 $ factory = new MockUuidFactory ([
7884 '6ba7b810-9dad-71d1-80b4-00c04fd430c8 ' ,
7985 '6ba7b810-9dad-71d1-80b4-00c04fd430c8 ' ,
80- ]);
86+ ], UuidV7::class );
8187
82- $ this ->assertSame ('6ba7b810-9dad-71d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v7 ());
83- $ this ->assertSame ('6ba7b810-9dad-71d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v7 ());
88+ $ this ->assertSame ('6ba7b810-9dad-71d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
89+ $ this ->assertSame ('6ba7b810-9dad-71d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ());
8490 }
8591
8692 public function testCreateV8 ()
8793 {
8894 $ factory = new MockUuidFactory ([
8995 '6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' ,
9096 '6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' ,
91- ]);
97+ ], UuidV8::class );
9298
93- $ this ->assertSame ('6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v8 ( ' 6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' ));
94- $ this ->assertSame ('6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' , (string ) $ factory ->v8 ( ' 6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' ));
99+ $ this ->assertSame ('6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ( ));
100+ $ this ->assertSame ('6ba7b810-9dad-81d1-80b4-00c04fd430c8 ' , (string ) $ factory ->create ( ));
95101 }
96102
97103 public function testExhaustedSequence ()
@@ -101,9 +107,17 @@ public function testExhaustedSequence()
101107
102108 $ factory = new MockUuidFactory ([
103109 '6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' ,
104- ]);
110+ ], UuidV1::class );
105111
106- $ factory ->v1 ();
107- $ factory ->v1 ();
112+ $ factory ->create ();
113+ $ factory ->create ();
114+ }
115+
116+ public function testInvalidDefaultClass ()
117+ {
118+ $ this ->expectException (\InvalidArgumentException::class);
119+ $ this ->expectExceptionMessage ('The class "stdClass" must be a subclass of "Symfony \\Component \\Uid \\Uuid". ' );
120+
121+ new MockUuidFactory ([], 'stdClass ' );
108122 }
109123}
0 commit comments