Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit d9ec671

Browse files
committed
Add assertion on expected value
1 parent f77fb7d commit d9ec671

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

tests/ModelTest.php

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -332,26 +332,27 @@ public function testSoftDelete(): void
332332
/**
333333
* @dataProvider provideId
334334
*/
335-
public function testPrimaryKey(string $model, $id, string $type): void
335+
public function testPrimaryKey(string $model, $id, $expected): void
336336
{
337337
$model::truncate();
338+
$expectedType = get_debug_type($expected);
338339

339340
$document = new $model;
340341
$this->assertEquals('_id', $document->getKeyName());
341342

342343
$document->_id = $id;
343344
$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());
348349

349350
$check = $model::find($id);
350351

351352
$this->assertNotNull($check, 'Not found');
352-
$this->assertSame($type, get_debug_type($check->_id));
353+
$this->assertSame($expectedType, get_debug_type($check->_id));
353354
$this->assertEquals($id, $check->_id);
354-
$this->assertSame($type, get_debug_type($check->getKey()));
355+
$this->assertSame($expectedType, get_debug_type($check->getKey()));
355356
$this->assertEquals($id, $check->getKey());
356357
}
357358

@@ -360,73 +361,55 @@ public static function provideId(): iterable
360361
yield 'int' => [
361362
User::class,
362363
10,
363-
'int',
364+
10,
364365
];
365366

366367
yield 'cast as int' => [
367368
IdIsInt::class,
368369
10,
369-
'int',
370+
10,
370371
];
371372

372373
yield 'string' => [
373374
User::class,
374375
'user-10',
375-
'string',
376+
'user-10',
376377
];
377378

378379
yield 'cast as string' => [
379380
IdIsString::class,
380381
'user-10',
381-
'string',
382+
'user-10',
382383
];
383384

385+
$objectId = new ObjectID();
384386
yield 'ObjectID' => [
385387
User::class,
386-
new ObjectID(),
387-
'string',
388+
$objectId,
389+
(string) $objectId,
388390
];
389391

392+
$binaryUuid = new Binary(hex2bin('0c103357380648c9a84b867dcb625cfb'), Binary::TYPE_UUID);
390393
yield 'BinaryUuid' => [
391394
User::class,
392-
new Binary(hex2bin('0c103357380648c9a84b867dcb625cfb'), Binary::TYPE_UUID),
393-
'string',
395+
$binaryUuid,
396+
(string) $binaryUuid,
394397
];
395398

396399
yield 'cast as BinaryUuid' => [
397400
IdIsBinaryUuid::class,
398-
new Binary(hex2bin('0c103357380648c9a84b867dcb625cfb'), Binary::TYPE_UUID),
399-
'string',
401+
$binaryUuid,
402+
(string) $binaryUuid,
400403
];
401404

405+
$date = new UTCDateTime();
402406
yield 'UTCDateTime' => [
403407
User::class,
404-
new UTCDateTime(),
405-
UTCDateTime::class,
408+
$date,
409+
$date,
406410
];
407411
}
408412

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-
430413
public function testCustomPrimaryKey(): void
431414
{
432415
$book = new Book;

0 commit comments

Comments
 (0)