Skip to content

Commit c9aca99

Browse files
committed
rework tests
Signed-off-by: Matthew Peveler <[email protected]>
1 parent b5ecfb7 commit c9aca99

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

tests/Phinx/Db/Adapter/MysqlAdapterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace Test\Phinx\Db\Adapter;
55

66
use Cake\Database\Query;
7+
use Cake\I18n\Date;
8+
use Cake\I18n\DateTime;
79
use InvalidArgumentException;
810
use PDO;
911
use PDOException;
@@ -2215,6 +2217,30 @@ public function testBulkInsertLiteral()
22152217
$this->assertEquals('2025-01-01 00:00:00', $rows[2]['column2']);
22162218
}
22172219

2220+
public function testBulkInsertDates()
2221+
{
2222+
$data = [
2223+
[
2224+
'name' => 'foo',
2225+
'created' => new Date(),
2226+
],
2227+
[
2228+
'name' => 'bar',
2229+
'created' => new DateTime(),
2230+
],
2231+
];
2232+
$table = new Table('table1', [], $this->adapter);
2233+
$table->addColumn('name', 'string')
2234+
->addColumn('created', 'datetime')
2235+
->insert($data)
2236+
->save();
2237+
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
2238+
$this->assertEquals('foo', $rows[0]['name']);
2239+
$this->assertEquals('bar', $rows[1]['name']);
2240+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
2241+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
2242+
}
2243+
22182244
public function testInsertData()
22192245
{
22202246
$data = [

tests/Phinx/Db/Adapter/PostgresAdapterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace Test\Phinx\Db\Adapter;
55

66
use Cake\Database\Query;
7+
use Cake\I18n\Date;
8+
use Cake\I18n\DateTime;
79
use InvalidArgumentException;
810
use PDO;
911
use Phinx\Db\Adapter\AbstractAdapter;
@@ -2447,6 +2449,30 @@ public function testBulkInsertLiteral()
24472449
$this->assertEquals('2025-01-01 00:00:00', $rows[2]['column2']);
24482450
}
24492451

2452+
public function testBulkInsertDates()
2453+
{
2454+
$data = [
2455+
[
2456+
'name' => 'foo',
2457+
'created' => new Date(),
2458+
],
2459+
[
2460+
'name' => 'bar',
2461+
'created' => new DateTime(),
2462+
],
2463+
];
2464+
$table = new Table('table1', [], $this->adapter);
2465+
$table->addColumn('name', 'string')
2466+
->addColumn('created', 'datetime')
2467+
->insert($data)
2468+
->save();
2469+
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
2470+
$this->assertEquals('foo', $rows[0]['name']);
2471+
$this->assertEquals('bar', $rows[1]['name']);
2472+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
2473+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
2474+
}
2475+
24502476
public function testInsertData()
24512477
{
24522478
$table = new Table('table1', [], $this->adapter);

tests/Phinx/Db/Adapter/SQLiteAdapterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use BadMethodCallException;
77
use Cake\Database\Query;
8+
use Cake\I18n\Date;
9+
use Cake\I18n\DateTime;
810
use Exception;
911
use InvalidArgumentException;
1012
use PDO;
@@ -1901,6 +1903,30 @@ public function testBulkInsertDataEnum()
19011903
$this->assertEquals('c', $rows[0]['column3']);
19021904
}
19031905

1906+
public function testBulkInsertDates()
1907+
{
1908+
$data = [
1909+
[
1910+
'name' => 'foo',
1911+
'created' => new Date(),
1912+
],
1913+
[
1914+
'name' => 'bar',
1915+
'created' => new DateTime(),
1916+
],
1917+
];
1918+
$table = new Table('table1', [], $this->adapter);
1919+
$table->addColumn('name', 'string')
1920+
->addColumn('created', 'datetime')
1921+
->insert($data)
1922+
->save();
1923+
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
1924+
$this->assertEquals('foo', $rows[0]['name']);
1925+
$this->assertEquals('bar', $rows[1]['name']);
1926+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
1927+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
1928+
}
1929+
19041930
public function testNullWithoutDefaultValue()
19051931
{
19061932
$this->markTestSkipped('Skipping for now. See Github Issue #265.');

tests/Phinx/Db/Adapter/SqlServerAdapterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use BadMethodCallException;
77
use Cake\Database\Query;
8+
use Cake\I18n\Date;
9+
use Cake\I18n\DateTime;
810
use InvalidArgumentException;
911
use PDO;
1012
use Phinx\Db\Adapter\SqlServerAdapter;
@@ -1345,6 +1347,30 @@ public function testBulkInsertLiteral()
13451347
$this->assertEquals('2025-01-01 00:00:00.000', $rows[2]['column2']);
13461348
}
13471349

1350+
public function testBulkInsertDates()
1351+
{
1352+
$data = [
1353+
[
1354+
'name' => 'foo',
1355+
'created' => new Date(),
1356+
],
1357+
[
1358+
'name' => 'bar',
1359+
'created' => new DateTime(),
1360+
],
1361+
];
1362+
$table = new Table('table1', [], $this->adapter);
1363+
$table->addColumn('name', 'string')
1364+
->addColumn('created', 'datetime')
1365+
->insert($data)
1366+
->save();
1367+
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
1368+
$this->assertEquals('foo', $rows[0]['name']);
1369+
$this->assertEquals('bar', $rows[1]['name']);
1370+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
1371+
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
1372+
}
1373+
13481374
public function testInsertData()
13491375
{
13501376
$table = new Table('table1', [], $this->adapter);

tests/Phinx/Migration/_files/seeds/UserSeeder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public function run(): void
1111
$data = [
1212
[
1313
'name' => 'foo',
14-
'created' => new Date(),
14+
'created' => date('Y-m-d H:i:s'),
1515
],
1616
[
1717
'name' => 'bar',
18-
'created' => new DateTime(),
18+
'created' => date('Y-m-d H:i:s'),
1919
],
2020
];
2121

0 commit comments

Comments
 (0)