Skip to content

Commit

Permalink
tests: newDateTime enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 7, 2024
1 parent 8c89b9d commit 57fa78c
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tests/Database/Explorer/Selection.fetchPairs().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test('', function () use ($explorer) {
$explorer->table('author')->get(12)->update(['born' => new DateTime('2002-02-02')]);
$list = $explorer->table('author')->where('born IS NOT NULL')->order('born')->fetchPairs('born', 'name');
Assert::same([
'2002-02-02 00:00:00' => 'David Grudl',
'2002-02-20 00:00:00' => 'Jakub Vrana',
'2002-02-02 00:00:00.000000' => 'David Grudl',
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
], $list);
});
2 changes: 1 addition & 1 deletion tests/Database/Explorer/Selection.insert().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $book = $explorer->table('author')->insert([
// id = 14

Assert::equal('eddard stark', $book->name);
Assert::equal(new Nette\Utils\DateTime('2011-11-11'), $book->born);
Assert::equal(new Nette\Database\DateTime('2011-11-11'), $book->born);


$books = $explorer->table('book');
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Explorer/bugs/bug216.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ $book = $explorer->table('author')->insert([

Assert::type(Nette\Database\Table\ActiveRow::class, $book);
Assert::equal('eddard stark', $book->name);
Assert::equal(new Nette\Utils\DateTime('2011-11-11'), $book->born);
Assert::equal(new Nette\Database\DateTime('2011-11-11'), $book->born);
4 changes: 2 additions & 2 deletions tests/Database/ResultSet.fetchAssoc().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('', function () use ($connection) {
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchAssoc('born=name');
Assert::same([
'2002-02-02 00:00:00' => 'David Grudl',
'2002-02-20 00:00:00' => 'Jakub Vrana',
'2002-02-02 00:00:00.000000' => 'David Grudl',
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
], $pairs);
});
8 changes: 4 additions & 4 deletions tests/Database/ResultSet.fetchPairs().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ test('', function () use ($connection) {
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
Assert::same([
'2002-02-02 00:00:00' => 'David Grudl',
'2002-02-20 00:00:00' => 'Jakub Vrana',
'2002-02-02 00:00:00.000000' => 'David Grudl',
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
], $pairs);
});

Expand Down Expand Up @@ -125,8 +125,8 @@ $pairs = $connection->query('UPDATE author SET born = ? WHERE id = 11', new Date
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
Assert::same([
'2002-02-02 00:00:00' => 'David Grudl',
'2002-02-20 00:00:00' => 'Jakub Vrana',
'2002-02-02 00:00:00.000000' => 'David Grudl',
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
], $pairs);


Expand Down
2 changes: 1 addition & 1 deletion tests/Database/ResultSet.normalizeRow.mysql.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

declare(strict_types=1);

use Nette\Utils\DateTime;
use Nette\Database\DateTime;
use Tester\Assert;

require __DIR__ . '/connect.inc.php'; // create $connection
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/ResultSet.normalizeRow.postgre.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

declare(strict_types=1);

use Nette\Utils\DateTime;
use Nette\Database\DateTime;
use Tester\Assert;

require __DIR__ . '/connect.inc.php'; // create $connection
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/ResultSet.normalizeRow.sqlite.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

declare(strict_types=1);

use Nette\Utils\DateTime;
use Nette\Database\DateTime;
use Tester\Assert;

require __DIR__ . '/connect.inc.php'; // create $connection
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/ResultSet.normalizeRow.sqlsrv.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

declare(strict_types=1);

use Nette\Utils\DateTime;
use Nette\Database\DateTime;
use Tester\Assert;

require __DIR__ . '/connect.inc.php'; // create $connection
Expand Down Expand Up @@ -131,13 +131,13 @@ function isTimestamp($str)


$row = (array) $connection->query('SELECT [datetimeoffset], CAST([sql_variant] AS int) AS [sql_variant], [timestamp] FROM types2 WHERE id = 1')->fetch();
Assert::type('DateTime', $row['datetimeoffset']);
Assert::type(DateTime::class, $row['datetimeoffset']);
Assert::same($row['datetimeoffset']->format('Y-m-d H:i:s P'), '2012-10-13 10:10:10 +02:00');
Assert::same($row['sql_variant'], 123456);
Assert::true(isTimestamp($row['timestamp']));

$row = (array) $connection->query('SELECT [datetimeoffset], CAST([sql_variant] AS varchar) AS [sql_variant], [timestamp] FROM types2 WHERE id = 2')->fetch();
Assert::type('DateTime', $row['datetimeoffset']);
Assert::type(DateTime::class, $row['datetimeoffset']);
Assert::same($row['datetimeoffset']->format('Y-m-d H:i:s P'), '0001-01-01 00:00:00 +00:00');
Assert::same($row['sql_variant'], 'abcd');
Assert::true(isTimestamp($row['timestamp']));
Expand Down
6 changes: 6 additions & 0 deletions tests/databases.github.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@ dsn = "mysql:host=127.0.0.1;port=3306;dbname=nette_test"
user = root
password = root
options[supportBooleans] = yes
options[newDateTime] = yes

[mysql 8.0]
dsn = "mysql:host=127.0.0.1;port=3307;dbname=nette_test"
user = root
password = root
options[supportBooleans] = yes
options[newDateTime] = yes

[postgresql 9.6]
dsn = "pgsql:host=127.0.0.1;port=5432;dbname=nette_test"
user = postgres
password = postgres
options[newDateTime] = yes

[postgresql 13]
dsn = "pgsql:host=127.0.0.1;port=5433;dbname=nette_test"
user = postgres
password = postgres
options[newDateTime] = yes

[sqlsrv]
dsn = "sqlsrv:Server=localhost,1433;Database=nette_test"
user = SA
password = "YourStrong!Passw0rd"
options[newDateTime] = yes

[sqlite]
dsn = "sqlite::memory:"
options[newDateTime] = yes
1 change: 1 addition & 0 deletions tests/databases.sqlite.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[sqlite]
dsn = "sqlite::memory:"
options[newDateTime] = yes

0 comments on commit 57fa78c

Please sign in to comment.