@@ -193,4 +193,96 @@ public function testNilUuid()
193193 $ this ->assertInstanceOf (NilUuid::class, $ uuid );
194194 $ this ->assertSame ('00000000-0000-0000-0000-000000000000 ' , (string ) $ uuid );
195195 }
196+
197+ public function testFromBinary ()
198+ {
199+ $ this ->assertEquals (
200+ Uuid::fromString ("\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08" ),
201+ Uuid::fromBinary ("\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08" )
202+ );
203+
204+ foreach ([
205+ '01EW2RYKDCT2SAK454KBR2QG08 ' ,
206+ '1BVXue8CnY8ogucrHX3TeF ' ,
207+ '0177058f-4dac-d0b2-a990-a49af02bc008 ' ,
208+ ] as $ ulid ) {
209+ try {
210+ Uuid::fromBinary ($ ulid );
211+
212+ $ this ->fail ();
213+ } catch (\Throwable $ e ) {
214+ }
215+
216+ $ this ->assertInstanceOf (\InvalidArgumentException::class, $ e );
217+ }
218+ }
219+
220+ public function testFromBase58 ()
221+ {
222+ $ this ->assertEquals (
223+ UuidV1::fromString ('94fSqj9oxGtsNbkfQNntwx ' ),
224+ UuidV1::fromBase58 ('94fSqj9oxGtsNbkfQNntwx ' )
225+ );
226+
227+ foreach ([
228+ "\x41\x4C\x08\x92\x57\x1B\x11\xEB\xBF\x70\x93\xF9\xB0\x82\x2C\x57" ,
229+ '219G494NRV27NVYW4KZ6R84B2Q ' ,
230+ '414c0892-571b-11eb-bf70-93f9b0822c57 ' ,
231+ ] as $ ulid ) {
232+ try {
233+ UuidV1::fromBase58 ($ ulid );
234+
235+ $ this ->fail ();
236+ } catch (\Throwable $ e ) {
237+ }
238+
239+ $ this ->assertInstanceOf (\InvalidArgumentException::class, $ e );
240+ }
241+ }
242+
243+ public function testFromBase32 ()
244+ {
245+ $ this ->assertEquals (
246+ UuidV5::fromString ('2VN0S74HBDBB0AQRXAHFVG35KK ' ),
247+ UuidV5::fromBase32 ('2VN0S74HBDBB0AQRXAHFVG35KK ' )
248+ );
249+
250+ foreach ([
251+ "\x5B\xA8\x32\x72\x45\x6D\x5A\xC0\xAB\xE3\xAA\x8B\xF7\x01\x96\x73" ,
252+ 'CKTRYycTes6WAqSQJsTDaz ' ,
253+ '5ba83272-456d-5ac0-abe3-aa8bf7019673 ' ,
254+ ] as $ ulid ) {
255+ try {
256+ Ulid::fromBase32 ($ ulid );
257+
258+ $ this ->fail ();
259+ } catch (\Throwable $ e ) {
260+ }
261+
262+ $ this ->assertInstanceOf (\InvalidArgumentException::class, $ e );
263+ }
264+ }
265+
266+ public function testFromRfc4122 ()
267+ {
268+ $ this ->assertEquals (
269+ UuidV6::fromString ('1eb571b4-14c0-6893-bf70-2d4c83cf755a ' ),
270+ UuidV6::fromRfc4122 ('1eb571b4-14c0-6893-bf70-2d4c83cf755a ' )
271+ );
272+
273+ foreach ([
274+ "\x1E\xB5\x71\xB4\x14\xC0\x68\x93\xBF\x70\x2D\x4C\x83\xCF\x75\x5A" ,
275+ '0YPNRV8560D29VYW1D9J1WYXAT ' ,
276+ '4nwTLZ2TdMtTVDE5AwVjaR ' ,
277+ ] as $ ulid ) {
278+ try {
279+ Ulid::fromRfc4122 ($ ulid );
280+
281+ $ this ->fail ();
282+ } catch (\Throwable $ e ) {
283+ }
284+
285+ $ this ->assertInstanceOf (\InvalidArgumentException::class, $ e );
286+ }
287+ }
196288}
0 commit comments