@@ -332,26 +332,27 @@ public function testSoftDelete(): void
332
332
/**
333
333
* @dataProvider provideId
334
334
*/
335
- public function testPrimaryKey (string $ model , $ id , string $ type ): void
335
+ public function testPrimaryKey (string $ model , $ id , string $ expected ): void
336
336
{
337
337
$ model ::truncate ();
338
+ $ expectedType = get_debug_type ($ expected );
338
339
339
340
$ document = new $ model ;
340
341
$ this ->assertEquals ('_id ' , $ document ->getKeyName ());
341
342
342
343
$ document ->_id = $ id ;
343
344
$ document ->save ();
344
- $ this ->assertSame ($ type , get_debug_type ($ document ->_id ));
345
- $ this ->assertEquals ($ id , $ document ->_id );
346
- $ this ->assertSame ($ type , get_debug_type ($ document ->getKey ()));
347
- $ this ->assertEquals ($ id , $ document ->getKey ());
345
+ $ this ->assertSame ($ expectedType , get_debug_type ($ document ->_id ));
346
+ $ this ->assertEquals ($ expected , $ document ->_id );
347
+ $ this ->assertSame ($ expectedType , get_debug_type ($ document ->getKey ()));
348
+ $ this ->assertEquals ($ expected , $ document ->getKey ());
348
349
349
350
$ check = $ model ::find ($ id );
350
351
351
352
$ this ->assertNotNull ($ check , 'Not found ' );
352
- $ this ->assertSame ($ type , get_debug_type ($ check ->_id ));
353
+ $ this ->assertSame ($ expectedType , get_debug_type ($ check ->_id ));
353
354
$ this ->assertEquals ($ id , $ check ->_id );
354
- $ this ->assertSame ($ type , get_debug_type ($ check ->getKey ()));
355
+ $ this ->assertSame ($ expectedType , get_debug_type ($ check ->getKey ()));
355
356
$ this ->assertEquals ($ id , $ check ->getKey ());
356
357
}
357
358
@@ -360,43 +361,45 @@ public static function provideId(): iterable
360
361
yield 'int ' => [
361
362
User::class,
362
363
10 ,
363
- ' int ' ,
364
+ 10 ,
364
365
];
365
366
366
367
yield 'cast as int ' => [
367
368
IdIsInt::class,
368
369
10 ,
369
- ' int ' ,
370
+ 10 ,
370
371
];
371
372
372
373
yield 'string ' => [
373
374
User::class,
374
375
'user-10 ' ,
375
- 'string ' ,
376
+ 'user-10 ' ,
376
377
];
377
378
378
379
yield 'cast as string ' => [
379
380
IdIsString::class,
380
381
'user-10 ' ,
381
- 'string ' ,
382
+ 'user-10 ' ,
382
383
];
383
384
385
+ $ objectId = new ObjectID ();
384
386
yield 'ObjectID ' => [
385
387
User::class,
386
- new ObjectID () ,
387
- ' string ' ,
388
+ $ objectId ,
389
+ ( string ) $ objectId ,
388
390
];
389
391
392
+ $ binaryUuid = new Binary (hex2bin ('0c103357380648c9a84b867dcb625cfb ' ), Binary::TYPE_UUID );
390
393
yield 'BinaryUuid ' => [
391
394
User::class,
392
- new Binary ( hex2bin ( ' 0c103357380648c9a84b867dcb625cfb ' ), Binary:: TYPE_UUID ) ,
393
- ' string ' ,
395
+ $ binaryUuid ,
396
+ ( string ) $ binaryUuid ,
394
397
];
395
398
396
399
yield 'cast as BinaryUuid ' => [
397
400
IdIsBinaryUuid::class,
398
- new Binary ( hex2bin ( ' 0c103357380648c9a84b867dcb625cfb ' ), Binary:: TYPE_UUID ) ,
399
- ' string ' ,
401
+ $ binaryUuid ,
402
+ ( string ) $ binaryUuid ,
400
403
];
401
404
402
405
yield 'UTCDateTime ' => [
@@ -406,27 +409,6 @@ public static function provideId(): iterable
406
409
];
407
410
}
408
411
409
- public function testPrimaryKeyBinaryUuid (): void
410
- {
411
- $ user = new IdIsBinaryUuid ;
412
- $ this ->assertEquals ('_id ' , $ user ->getKeyName ());
413
-
414
- $ uuid = new Binary (hex2bin ('0c103357380648c9a84b867dcb625cfb ' ), Binary::TYPE_UUID );
415
- $ idAsString = (string ) $ uuid ;
416
- $ user ->_id = $ uuid ;
417
- $ user ->name = 'John Doe ' ;
418
- $ user ->save ();
419
- $ this ->assertIsString ($ user ->getKey ());
420
- $ this ->assertSame ($ idAsString , $ user ->getKey ());
421
-
422
- $ check = IdIsBinaryUuid::find ($ uuid );
423
- $ this ->assertIsString ($ check ->_id );
424
- $ this ->assertSame ($ idAsString , $ check ->_id );
425
- $ this ->assertIsString ($ check ->getKey ());
426
- $ this ->assertSame ($ idAsString , $ check ->getKey ());
427
- $ this ->assertSame ('John Doe ' , $ check ->name );
428
- }
429
-
430
412
public function testCustomPrimaryKey (): void
431
413
{
432
414
$ book = new Book ;
0 commit comments