forked from tursodatabase/libsql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimestampDataTest.php
63 lines (46 loc) · 1.75 KB
/
TimestampDataTest.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
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
beforeEach(function () {
Schema::create('timestamp_table', function ($table) {
$table->id();
$table->timestamp('added_at', precision: 0);
});
});
afterEach(function () {
Schema::dropIfExists('timestamp_table');
});
test('it can insert a new timestamp data', function () {
$timestamp = '2021-01-01 12:34:56';
$result = DB::table('timestamp_table')->insert([
'added_at' => $timestamp,
]);
$newData = DB::table('timestamp_table')->first();
expect($result)->toBeTrue()
->and(DB::table('timestamp_table')->count())->toBe(1)
->and($newData->added_at)->toBe($timestamp);
})->group('TimestampDataTest', 'DataTypes', 'FeatureTest');
test('it can update an existing timestamp data', function () {
$timestamp = '2021-01-01 12:34:56';
DB::table('timestamp_table')->insert([
'added_at' => $timestamp,
]);
$newTimestamp = '2021-02-01 23:45:01';
$result = DB::table('timestamp_table')->update([
'added_at' => $newTimestamp,
]);
$updatedData = DB::table('timestamp_table')->first();
expect($result)->toBe(1)
->and($updatedData->added_at)->toBe($newTimestamp);
})->group('TimestampDataTest', 'DataTypes', 'FeatureTest');
test('it can find the saved record', function () {
$timestamp = '2021-01-01 12:34:56';
DB::table('timestamp_table')->insert([
'added_at' => '2021-02-01 23:45:01',
]);
DB::table('timestamp_table')->insert([
'added_at' => $timestamp,
]);
$found = DB::table('timestamp_table')->where('added_at', $timestamp)->first();
expect($found->added_at)->toBe($timestamp);
})->group('TimestampDataTest', 'DataTypes', 'FeatureTest');