Skip to content

Commit 72d3ec3

Browse files
committed
test: add postgres date format test
1 parent ce4ea18 commit 72d3ec3

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

tests/Integration/Database/Postgres/DatabasePostgresConnectionTest.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Tests\Integration\Database\Postgres;
44

55
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Carbon;
67
use Illuminate\Support\Facades\DB;
78
use Illuminate\Support\Facades\Schema;
89
use PHPUnit\Framework\Attributes\DataProvider;
@@ -15,32 +16,33 @@ class DatabasePostgresConnectionTest extends PostgresTestCase
1516
{
1617
protected function afterRefreshingDatabase()
1718
{
18-
if (! Schema::hasTable('json_table')) {
19-
Schema::create('json_table', function (Blueprint $table) {
19+
if (! Schema::hasTable('pgsql_table')) {
20+
Schema::create('pgsql_table', function (Blueprint $table) {
2021
$table->json('json_col')->nullable();
22+
$table->timestamptz('timestamptz', precision: 6)->nullable();
2123
});
2224
}
2325
}
2426

2527
protected function destroyDatabaseMigrations()
2628
{
27-
Schema::drop('json_table');
29+
Schema::drop('pgsql_table');
2830
}
2931

3032
#[DataProvider('jsonWhereNullDataProvider')]
3133
public function testJsonWhereNull($expected, $key, array $value = ['value' => 123])
3234
{
33-
DB::table('json_table')->insert(['json_col' => json_encode($value)]);
35+
DB::table('pgsql_table')->insert(['json_col' => json_encode($value)]);
3436

35-
$this->assertSame($expected, DB::table('json_table')->whereNull("json_col->$key")->exists());
37+
$this->assertSame($expected, DB::table('pgsql_table')->whereNull("json_col->$key")->exists());
3638
}
3739

3840
#[DataProvider('jsonWhereNullDataProvider')]
3941
public function testJsonWhereNotNull($expected, $key, array $value = ['value' => 123])
4042
{
41-
DB::table('json_table')->insert(['json_col' => json_encode($value)]);
43+
DB::table('pgsql_table')->insert(['json_col' => json_encode($value)]);
4244

43-
$this->assertSame(! $expected, DB::table('json_table')->whereNotNull("json_col->$key")->exists());
45+
$this->assertSame(! $expected, DB::table('pgsql_table')->whereNotNull("json_col->$key")->exists());
4446
}
4547

4648
public static function jsonWhereNullDataProvider()
@@ -71,18 +73,18 @@ public static function jsonWhereNullDataProvider()
7173

7274
public function testJsonPathUpdate()
7375
{
74-
DB::table('json_table')->insert([
76+
DB::table('pgsql_table')->insert([
7577
['json_col' => '{"foo":["bar"]}'],
7678
['json_col' => '{"foo":["baz"]}'],
7779
['json_col' => '{"foo":[["array"]]}'],
7880
]);
7981

80-
$updatedCount = DB::table('json_table')->where('json_col->foo[0]', 'baz')->update([
82+
$updatedCount = DB::table('pgsql_table')->where('json_col->foo[0]', 'baz')->update([
8183
'json_col->foo[0]' => 'updated',
8284
]);
8385
$this->assertSame(1, $updatedCount);
8486

85-
$updatedCount = DB::table('json_table')->where('json_col->foo[0][0]', 'array')->update([
87+
$updatedCount = DB::table('pgsql_table')->where('json_col->foo[0][0]', 'array')->update([
8688
'json_col->foo[0][0]' => 'updated',
8789
]);
8890
$this->assertSame(1, $updatedCount);
@@ -91,15 +93,27 @@ public function testJsonPathUpdate()
9193
#[DataProvider('jsonContainsKeyDataProvider')]
9294
public function testWhereJsonContainsKey($count, $column)
9395
{
94-
DB::table('json_table')->insert([
96+
DB::table('pgsql_table')->insert([
9597
['json_col' => '{"foo":{"bar":["baz"]}}'],
9698
['json_col' => '{"foo":{"bar":false}}'],
9799
['json_col' => '{"foo":{}}'],
98100
['json_col' => '{"foo":[{"bar":"bar"},{"baz":"baz"}]}'],
99101
['json_col' => '{"bar":null}'],
100102
]);
101103

102-
$this->assertSame($count, DB::table('json_table')->whereJsonContainsKey($column)->count());
104+
$this->assertSame($count, DB::table('pgsql_table')->whereJsonContainsKey($column)->count());
105+
}
106+
107+
public function testDateTimeInterfacesAreNotTruncated()
108+
{
109+
$datetime = Carbon::parse('2021-01-01 12:34:56.123456', 'America/New_York');
110+
111+
DB::table('pgsql_table')->insert([['timestamptz' => $datetime]]);
112+
113+
$this->assertSame(
114+
'2021-01-01 07:34:56.123456+00',
115+
DB::table('pgsql_table')->pluck('timestamptz')->first(),
116+
);
103117
}
104118

105119
public static function jsonContainsKeyDataProvider()

0 commit comments

Comments
 (0)