forked from tursodatabase/libsql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimestampCastingTest.php
78 lines (57 loc) · 2.06 KB
/
TimestampCastingTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
use Illuminate\Support\Facades\Schema;
beforeEach(function () {
Schema::create('timestamp_casting_table', function ($table) {
$table->id();
$table->timestamp('added_at');
});
});
afterEach(function () {
Schema::dropIfExists('timestamp_casting_table');
});
class TimestampCastingModel extends \Illuminate\Database\Eloquent\Model
{
protected $table = 'timestamp_casting_table';
protected $guarded = false;
public $timestamps = false;
protected function casts(): array
{
return [
'added_at' => 'timestamp',
];
}
}
test('it can insert a new record using Eloquent ORM', function () {
$addedAt = now();
TimestampCastingModel::create([
'added_at' => $addedAt,
]);
$result = TimestampCastingModel::first();
expect($result->id)->toBe(1)
->and(gettype($result->added_at))->toBe('integer')
->and($result->added_at)->toBe($addedAt->timestamp);
})->group('TimestampCastingTest', 'EloquentAttributeCastings', 'FeatureTest');
test('it can update an existing record using Eloquent ORM', function () {
$addedAt = now();
TimestampCastingModel::create([
'added_at' => $addedAt,
]);
$newAddedAt = now()->addHour();
TimestampCastingModel::first()->update([
'added_at' => $newAddedAt,
]);
$result = TimestampCastingModel::first();
expect($result->id)->toBe(1)
->and(gettype($result->added_at))->toBe('integer')
->and($result->added_at)->toBe($newAddedAt->timestamp);
})->group('TimestampCastingTest', 'EloquentAttributeCastings', 'FeatureTest');
test('it can retrieve a record using Eloquent ORM', function () {
$addedAt = now();
TimestampCastingModel::create([
'added_at' => $addedAt,
]);
$result = TimestampCastingModel::where('added_at', $addedAt)->first();
expect($result->id)->toBe(1)
->and(gettype($result->added_at))->toBe('integer')
->and($result->added_at)->toBe($addedAt->timestamp);
})->group('TimestampCastingTest', 'EloquentAttributeCastings', 'FeatureTest');