Skip to content

Commit 0596b0a

Browse files
committed
Remove date conversion from results
1 parent 6a05d69 commit 0596b0a

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

docs/includes/usage-examples/FindOneTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public function testFindOne(): void
2424

2525
// begin-find-one
2626
$movie = Movie::where('directors', 'Rob Reiner')
27-
->orderBy('_id')
27+
->orderBy('id')
2828
->first();
2929

3030
echo $movie->toJson();
3131
// end-find-one
3232

3333
$this->assertInstanceOf(Movie::class, $movie);
34-
$this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/');
34+
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
3535
}
3636
}

docs/includes/usage-examples/InsertOneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public function testInsertOne(): void
3030
// end-insert-one
3131

3232
$this->assertInstanceOf(Movie::class, $movie);
33-
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/');
33+
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","id":"[a-z0-9]{24}"}$/');
3434
}
3535
}

src/Query/Builder.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,7 @@ private function aliasIdForResult(stdClass|array $values): stdClass|array
15931593
}
15941594

15951595
foreach ($values as $key => $value) {
1596-
if ($value instanceof UTCDateTime) {
1597-
$values[$key] = CarbonImmutable::createFromTimestamp($value->toDateTime()->getTimestamp(), 'UTC')->setTimezone(date_default_timezone_get());
1598-
} elseif (is_array($value) || $value instanceof stdClass) {
1596+
if (is_array($value) || $value instanceof stdClass) {
15991597
$values[$key] = $this->aliasIdForResult($value);
16001598
}
16011599
}
@@ -1606,9 +1604,7 @@ private function aliasIdForResult(stdClass|array $values): stdClass|array
16061604
}
16071605

16081606
foreach (get_object_vars($values) as $key => $value) {
1609-
if ($value instanceof UTCDateTime) {
1610-
$values->{$key} = CarbonImmutable::createFromTimestamp($value->toDateTime()->getTimestamp(), 'UTC')->setTimezone(date_default_timezone_get());
1611-
} elseif (is_array($value) || $value instanceof stdClass) {
1607+
if (is_array($value) || $value instanceof stdClass) {
16121608
$values->{$key} = $this->aliasIdForResult($value);
16131609
}
16141610
}

tests/AuthTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Facades\Auth;
1010
use Illuminate\Support\Facades\DB;
1111
use Illuminate\Support\Facades\Hash;
12+
use MongoDB\BSON\UTCDateTime;
1213
use MongoDB\Laravel\Tests\Models\User;
1314

1415
use function bcrypt;
@@ -63,7 +64,7 @@ function ($actualUser, $actualToken) use ($user, &$token) {
6364
$reminder = DB::collection('password_reset_tokens')->first();
6465
$this->assertEquals('[email protected]', $reminder->email);
6566
$this->assertNotNull($reminder->token);
66-
$this->assertInstanceOf(DateTimeInterface::class, $reminder->created_at);
67+
$this->assertInstanceOf(UTCDateTime::class, $reminder->created_at);
6768

6869
$credentials = [
6970
'email' => '[email protected]',

tests/Casts/DecimalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function setBSONType($value, $id = null)
120120
return Casting::raw(function (Collection $collection) use ($id, $value) {
121121
if (! empty($id)) {
122122
return $collection->updateOne(
123-
['id' => $id],
123+
['_id' => $id], // "id" is not translated to "_id" by the raw method
124124
['$set' => ['decimalNumber' => $value]],
125125
);
126126
}

tests/QueueTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Support\Facades\Queue;
1111
use Illuminate\Support\Str;
1212
use Mockery;
13+
use MongoDB\BSON\UTCDateTime;
1314
use MongoDB\Laravel\Queue\MongoJob;
1415
use MongoDB\Laravel\Queue\MongoQueue;
1516

@@ -188,7 +189,7 @@ public function testFailedJobLogging()
188189
$this->assertSame('test_connection', $failedJob->connection);
189190
$this->assertSame('test_queue', $failedJob->queue);
190191
$this->assertSame('test_payload', $failedJob->payload);
191-
$this->assertEquals(Carbon::now(), $failedJob->failed_at);
192+
$this->assertEquals(new UTCDateTime(Carbon::now()), $failedJob->failed_at);
192193
$this->assertStringStartsWith('Exception: test_exception in ', $failedJob->exception);
193194
}
194195
}

0 commit comments

Comments
 (0)