Skip to content

Commit

Permalink
CastObjectId merged into Casting;
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-thomas committed Oct 30, 2023
1 parent 8d9736b commit 64ef154
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
12 changes: 6 additions & 6 deletions tests/Casts/ObjectIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Generator;
use MongoDB\BSON\ObjectId;
use MongoDB\Laravel\Tests\Models\CastObjectId;
use MongoDB\Laravel\Tests\Models\Casting;
use MongoDB\Laravel\Tests\TestCase;

class ObjectIdTest extends TestCase
Expand All @@ -15,17 +15,17 @@ protected function setUp(): void
{
parent::setUp();

CastObjectId::truncate();
Casting::truncate();
}

/** @dataProvider provideObjectIdCast */
public function testStoreObjectId(string|ObjectId $saveObjectId, ObjectId $queryObjectId): void
{
$stringObjectId = (string) $saveObjectId;

CastObjectId::create(['oid' => $saveObjectId]);
Casting::create(['oid' => $saveObjectId]);

$model = CastObjectId::firstWhere('oid', $queryObjectId);
$model = Casting::firstWhere('oid', $queryObjectId);
$this->assertNotNull($model);
$this->assertSame($stringObjectId, $model->oid);
}
Expand All @@ -44,9 +44,9 @@ public function testQueryByStringDoesNotCast(): void
$objectId = new ObjectId();
$stringObjectId = (string) $objectId;

CastObjectId::create(['oid' => $objectId]);
Casting::create(['oid' => $objectId]);

$model = CastObjectId::firstWhere('oid', $stringObjectId);
$model = Casting::firstWhere('oid', $stringObjectId);
$this->assertNull($model);
}
}
17 changes: 0 additions & 17 deletions tests/Models/CastObjectId.php

This file was deleted.

3 changes: 3 additions & 0 deletions tests/Models/Casting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace MongoDB\Laravel\Tests\Models;

use MongoDB\Laravel\Eloquent\Casts\BinaryUuid;
use MongoDB\Laravel\Eloquent\Casts\ObjectId;
use MongoDB\Laravel\Eloquent\Model as Eloquent;

class Casting extends Eloquent
Expand All @@ -14,6 +15,7 @@ class Casting extends Eloquent

protected $fillable = [
'uuid',
'oid',
'intNumber',
'floatNumber',
'decimalNumber',
Expand All @@ -29,6 +31,7 @@ class Casting extends Eloquent

protected $casts = [
'uuid' => BinaryUuid::class,
'oid' => ObjectId::class,
'intNumber' => 'int',
'floatNumber' => 'float',
'decimalNumber' => 'decimal:2',
Expand Down

0 comments on commit 64ef154

Please sign in to comment.