@@ -332,7 +332,7 @@ public function testSoftDelete(): void
332
332
/**
333
333
* @dataProvider provideId
334
334
*/
335
- public function testPrimaryKey (string $ model , $ id , $ expected ): void
335
+ public function testPrimaryKey (string $ model , $ id , $ expected, bool $ expectedFound ): void
336
336
{
337
337
$ model ::truncate ();
338
338
$ expectedType = get_debug_type ($ expected );
@@ -349,78 +349,78 @@ public function testPrimaryKey(string $model, $id, $expected): void
349
349
350
350
$ check = $ model ::find ($ id );
351
351
352
- $ this ->assertNotNull ($ check , 'Not found ' );
353
- $ this ->assertSame ($ expectedType , get_debug_type ($ check ->_id ));
354
- $ this ->assertEquals ($ id , $ check ->_id );
355
- $ this ->assertSame ($ expectedType , get_debug_type ($ check ->getKey ()));
356
- $ this ->assertEquals ($ id , $ check ->getKey ());
352
+ if ($ expectedFound ) {
353
+ $ this ->assertNotNull ($ check , 'Not found ' );
354
+ $ this ->assertSame ($ expectedType , get_debug_type ($ check ->_id ));
355
+ $ this ->assertEquals ($ id , $ check ->_id );
356
+ $ this ->assertSame ($ expectedType , get_debug_type ($ check ->getKey ()));
357
+ $ this ->assertEquals ($ id , $ check ->getKey ());
358
+ } else {
359
+ $ this ->assertNull ($ check , 'Found ' );
360
+ }
357
361
}
358
362
359
363
public static function provideId (): iterable
360
364
{
361
365
yield 'int ' => [
362
- User::class,
363
- 10 ,
364
- 10 ,
366
+ 'model ' => User::class,
367
+ 'id ' => 10 ,
368
+ 'expected ' => 10 ,
369
+ // Don't expect this to be found, as the int is cast to string for the query
370
+ 'expectedFound ' => false ,
365
371
];
366
372
367
373
yield 'cast as int ' => [
368
- IdIsInt::class,
369
- 10 ,
370
- 10 ,
374
+ 'model ' => IdIsInt::class,
375
+ 'id ' => 10 ,
376
+ 'expected ' => 10 ,
377
+ 'expectedFound ' => true ,
371
378
];
372
379
373
380
yield 'string ' => [
374
- User::class,
375
- 'user-10 ' ,
376
- 'user-10 ' ,
381
+ 'model ' => User::class,
382
+ 'id ' => 'user-10 ' ,
383
+ 'expected ' => 'user-10 ' ,
384
+ 'expectedFound ' => true ,
377
385
];
378
386
379
387
yield 'cast as string ' => [
380
- IdIsString::class,
381
- 'user-10 ' ,
382
- 'user-10 ' ,
388
+ 'model ' => IdIsString::class,
389
+ 'id ' => 'user-10 ' ,
390
+ 'expected ' => 'user-10 ' ,
391
+ 'expectedFound ' => true ,
383
392
];
384
393
385
394
$ objectId = new ObjectID ();
386
395
yield 'ObjectID ' => [
387
- User::class,
388
- $ objectId ,
389
- (string ) $ objectId ,
396
+ 'model ' => User::class,
397
+ 'id ' => $ objectId ,
398
+ 'expected ' => (string ) $ objectId ,
399
+ 'expectedFound ' => true ,
390
400
];
391
401
392
402
$ binaryUuid = new Binary (hex2bin ('0c103357380648c9a84b867dcb625cfb ' ), Binary::TYPE_UUID );
393
403
yield 'BinaryUuid ' => [
394
- User::class,
395
- $ binaryUuid ,
396
- (string ) $ binaryUuid ,
404
+ 'model ' => User::class,
405
+ 'id ' => $ binaryUuid ,
406
+ 'expected ' => (string ) $ binaryUuid ,
407
+ 'expectedFound ' => true ,
397
408
];
398
409
399
410
yield 'cast as BinaryUuid ' => [
400
- IdIsBinaryUuid::class,
401
- $ binaryUuid ,
402
- (string ) $ binaryUuid ,
411
+ 'model ' => IdIsBinaryUuid::class,
412
+ 'id ' => $ binaryUuid ,
413
+ 'expected ' => (string ) $ binaryUuid ,
414
+ 'expectedFound ' => true ,
403
415
];
404
416
405
417
$ date = new UTCDateTime ();
406
418
yield 'UTCDateTime ' => [
407
- User::class,
408
- $ date ,
409
- $ date ,
410
- ];
411
-
412
- $ array = ['foo ' => 'bar ' ];
413
- yield 'array ' => [
414
- User::class,
415
- $ array ,
416
- $ array ,
417
- ];
418
-
419
- $ object = (object ) ['foo ' => 'bar ' ];
420
- yield 'object ' => [
421
- User::class,
422
- $ object ,
423
- $ object ,
419
+ 'model ' => User::class,
420
+ 'id ' => $ date ,
421
+ 'expected ' => $ date ,
422
+ // Don't expect this to be found, as the original value is stored as UTCDateTime but then cast to string
423
+ 'expectedFound ' => false ,
424
424
];
425
425
}
426
426
0 commit comments