Skip to content

Commit

Permalink
tests: more tests on date type
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Jan 6, 2019
1 parent d134a06 commit f00154c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 33 deletions.
54 changes: 37 additions & 17 deletions tests/cases/integration/datetime.mysqli.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class DateTimeMysqlTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_write (
a datetime,
b timestamp
b timestamp,
c date
);
');

$connection->query('INSERT INTO dates_write VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write VALUES (%dts, %dt, %dts)',
new DateTime('2015-01-01 12:00:00'), // simple
new DateTime('2015-01-01 12:00:00') // 11:00 UTC
new DateTime('2015-01-01 12:00:00'), // 11:00 UTC
new DateTime('2015-01-01 00:00:00') // simple
);

$result = $connection->query('SELECT * FROM dates_write');
Expand All @@ -39,11 +41,13 @@ class DateTimeMysqlTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 12:00:00', $row->b);
Assert::same('2015-01-01', $row->c);

$connection->query('DELETE FROM dates_write');
$connection->query('INSERT INTO dates_write VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write VALUES (%dts, %dt, %dts)',
new DateTime('2015-01-01 12:00:00'), // simple
new DateTime('2015-01-01 12:00:00 Europe/Kiev') // 10:00 UTC
new DateTime('2015-01-01 12:00:00 Europe/Kiev'), // 10:00 UTC,
new DateTime('2015-01-01 12:13:14') // simple
);

$result = $connection->query('SELECT * FROM dates_write');
Expand All @@ -52,6 +56,7 @@ class DateTimeMysqlTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 11:00:00', $row->b);
Assert::same('2015-01-01', $row->c);
}


Expand All @@ -64,13 +69,15 @@ class DateTimeMysqlTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_write2 (
a datetime,
b timestamp
b timestamp,
c date
);
');

$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt)',
new DateTime('2015-01-01 12:00:00'), // simple
new DateTime('2015-01-01 12:00:00') // 11:00 UTC
$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt, %dts)',
new \DateTimeImmutable('2015-01-01 12:00:00'), // simple
new \DateTimeImmutable('2015-01-01 12:00:00'), // 11:00 UTC
new \DateTimeImmutable('2015-01-01 00:00:00') // simple
);

$result = $connection->query('SELECT * FROM dates_write2');
Expand All @@ -79,11 +86,13 @@ class DateTimeMysqlTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 13:00:00', $row->b);
Assert::same('2015-01-01', $row->c);

$connection->query('DELETE FROM dates_write2');
$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt, %dts)',
new \DateTimeImmutable('2015-01-01 12:00:00'), // simple
new \DateTimeImmutable('2015-01-01 12:00:00 Europe/Kiev') // 10:00 UTC
new \DateTimeImmutable('2015-01-01 12:00:00 Europe/Kiev'), // 10:00 UTC
new \DateTimeImmutable('2015-01-01 12:13:14') // simple
);

$result = $connection->query('SELECT * FROM dates_write2');
Expand All @@ -92,6 +101,7 @@ class DateTimeMysqlTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 12:00:00', $row->b);
Assert::same('2015-01-01', $row->c);
}


Expand All @@ -102,21 +112,26 @@ class DateTimeMysqlTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_read (
a datetime,
b timestamp
b timestamp,
c date
);
');

$connection->query('INSERT INTO dates_read VALUES (%s, %s)',
$connection->query('INSERT INTO dates_read VALUES (%s, %s, %s)',
'2015-01-01 12:00:00', // simple
'2015-01-01 12:00:00' // 11:00 UTC
'2015-01-01 12:00:00', // 11:00 UTC
'2015-01-01'
);

$result = $connection->query('SELECT * FROM dates_read');

$row = $result->fetch();
Assert::type(DateTimeImmutable::class, $row->a);
Assert::type(DateTimeImmutable::class, $row->b);
Assert::type(DateTimeImmutable::class, $row->c);
Assert::same('2015-01-01T12:00:00+01:00', $row->a->format('c'));
Assert::same('2015-01-01T12:00:00+01:00', $row->b->format('c'));
Assert::same('2015-01-01T00:00:00+01:00', $row->c->format('c'));
}


Expand All @@ -129,21 +144,26 @@ class DateTimeMysqlTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_read2 (
a datetime,
b timestamp
b timestamp,
c date
);
');

$connection->query('INSERT INTO dates_read2 VALUES (%s, %s)',
$connection->query('INSERT INTO dates_read2 VALUES (%s, %s, %s)',
'2015-01-01 12:00:00', // simple
'2015-01-01 12:00:00' // 10:00 UTC
'2015-01-01 12:00:00', // 10:00 UTC
'2015-01-01'
);

$result = $connection->query('SELECT * FROM dates_read2');

$row = $result->fetch();
Assert::type(DateTimeImmutable::class, $row->a);
Assert::type(DateTimeImmutable::class, $row->b);
Assert::type(DateTimeImmutable::class, $row->c);
Assert::same('2015-01-01T12:00:00+01:00', $row->a->format('c'));
Assert::same('2015-01-01T11:00:00+01:00', $row->b->format('c'));
Assert::same('2015-01-01T00:00:00+01:00', $row->c->format('c'));
}


Expand Down
52 changes: 36 additions & 16 deletions tests/cases/integration/datetime.pgsql.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class DateTimePostgreTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_write (
a timestamp,
b timestamptz
b timestamptz,
c date
);
');

$connection->query('INSERT INTO dates_write VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write VALUES (%dts, %dt, %dts)',
new DateTime('2015-01-01 12:00:00'), // simple
new DateTime('2015-01-01 12:00:00') // 11:00 UTC
new DateTime('2015-01-01 12:00:00'), // 11:00 UTC
new DateTime('2015-01-01 00:00:00') // simple
);

$result = $connection->query('SELECT * FROM dates_write');
Expand All @@ -39,11 +41,13 @@ class DateTimePostgreTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 12:00:00+01', $row->b);
Assert::same('2015-01-01', $row->c);

$connection->query('DELETE FROM dates_write');
$connection->query('INSERT INTO dates_write VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write VALUES (%dts, %dt, %dts)',
new DateTime('2015-01-01 12:00:00'), // simple
new DateTime('2015-01-01 12:00:00 Europe/Kiev') // 10:00 UTC
new DateTime('2015-01-01 12:00:00 Europe/Kiev'), // 10:00 UTC
new DateTime('2015-01-01 12:13:14') // simple
);

$result = $connection->query('SELECT * FROM dates_write');
Expand All @@ -52,6 +56,7 @@ class DateTimePostgreTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 11:00:00+01', $row->b);
Assert::same('2015-01-01', $row->c);
}


Expand All @@ -65,13 +70,15 @@ class DateTimePostgreTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_write2 (
a timestamp,
b timestamptz
b timestamptz,
c date
);
');

$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt, %dts)',
new \DateTimeImmutable('2015-01-01 12:00:00'), // simple
new \DateTimeImmutable('2015-01-01 12:00:00') // 11:00 UTC
new \DateTimeImmutable('2015-01-01 12:00:00'), // 11:00 UTC
new \DateTimeImmutable('2015-01-01 00:00:00') // simple
);

$result = $connection->query('SELECT * FROM dates_write2');
Expand All @@ -80,11 +87,13 @@ class DateTimePostgreTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 13:00:00+02', $row->b);
Assert::same('2015-01-01', $row->c);

$connection->query('DELETE FROM dates_write2');
$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt)',
$connection->query('INSERT INTO dates_write2 VALUES (%dts, %dt, %dts)',
new \DateTimeImmutable('2015-01-01 12:00:00'), // 11:00 UTC
new \DateTimeImmutable('2015-01-01 12:00:00 Europe/Kiev') // 10:00 UTC
new \DateTimeImmutable('2015-01-01 12:00:00 Europe/Kiev'), // 10:00 UTC
new \DateTimeImmutable('2015-01-01 12:13:14') // simple
);

$result = $connection->query('SELECT * FROM dates_write2');
Expand All @@ -93,6 +102,7 @@ class DateTimePostgreTest extends IntegrationTestCase
$row = $result->fetch();
Assert::same('2015-01-01 12:00:00', $row->a);
Assert::same('2015-01-01 12:00:00+02', $row->b);
Assert::same('2015-01-01', $row->c);
}


Expand All @@ -103,21 +113,26 @@ class DateTimePostgreTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_read (
a timestamp,
b timestamptz
b timestamptz,
c date
);
');

$connection->query('INSERT INTO dates_read VALUES (%s, %s)',
$connection->query('INSERT INTO dates_read VALUES (%s, %s, %s)',
'2015-01-01 12:00:00', // simple
'2015-01-01 12:00:00' // 11:00 UTC
'2015-01-01 12:00:00', // 11:00 UTC
'2015-01-01'
);

$result = $connection->query('SELECT * FROM dates_read');

$row = $result->fetch();
Assert::type(DateTimeImmutable::class, $row->a);
Assert::type(DateTimeImmutable::class, $row->b);
Assert::type(DateTimeImmutable::class, $row->c);
Assert::same('2015-01-01T12:00:00+01:00', $row->a->format('c'));
Assert::same('2015-01-01T12:00:00+01:00', $row->b->format('c'));
Assert::same('2015-01-01T00:00:00+01:00', $row->c->format('c'));
}


Expand All @@ -130,21 +145,26 @@ class DateTimePostgreTest extends IntegrationTestCase
$connection->query('
CREATE TABLE dates_read2 (
a timestamp,
b timestamptz
b timestamptz,
c date
);
');

$connection->query('INSERT INTO dates_read2 VALUES (%s, %s)',
$connection->query('INSERT INTO dates_read2 VALUES (%s, %s, %s)',
'2015-01-01 12:00:00', // simple
'2015-01-01 12:00:00' // 10:00 UTC
'2015-01-01 12:00:00', // 10:00 UTC
'2015-01-01'
);

$result = $connection->query('SELECT * FROM dates_read2');

$row = $result->fetch();
Assert::type(DateTimeImmutable::class, $row->a);
Assert::type(DateTimeImmutable::class, $row->b);
Assert::type(DateTimeImmutable::class, $row->c);
Assert::same('2015-01-01T12:00:00+01:00', $row->a->format('c'));
Assert::same('2015-01-01T11:00:00+01:00', $row->b->format('c'));
Assert::same('2015-01-01T00:00:00+01:00', $row->c->format('c'));
}


Expand Down

0 comments on commit f00154c

Please sign in to comment.