Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ext-json": "*",
"ext-pdo": "*",
"cakephp/cakephp-codesniffer": "^5.0",
"cakephp/i18n": "^5.0",
"phpunit/phpunit": "^9.5.19",
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0|^7.0"
},
Expand Down
6 changes: 6 additions & 0 deletions src/Phinx/Db/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Cake\Database\Query\InsertQuery;
use Cake\Database\Query\SelectQuery;
use Cake\Database\Query\UpdateQuery;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use InvalidArgumentException;
use PDO;
use PDOException;
Expand Down Expand Up @@ -430,6 +432,10 @@ public function bulkinsert(Table $table, array $rows): void
foreach ($row as $v) {
if ($v instanceof Literal) {
continue;
} elseif ($v instanceof DateTime) {
$vals[] = $v->toDateTimeString();
} elseif ($v instanceof Date) {
$vals[] = $v->toDateString();
} elseif (is_bool($v)) {
$vals[] = $this->castToBool($v);
} else {
Expand Down
14 changes: 7 additions & 7 deletions tests/Phinx/Console/Command/SeedRunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testExecute()
$command = $application->find('seed:run');

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$this->config, $this->input, $this->output])
->getMock();
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testExecuteWithDsn()
]);

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$config, $this->input, $this->output])
->getMock();
Expand All @@ -127,7 +127,7 @@ public function testExecuteWithEnvironmentOption()
$command = $application->find('seed:run');

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$this->config, $this->input, $this->output])
->getMock();
Expand All @@ -153,7 +153,7 @@ public function testExecuteWithInvalidEnvironmentOption()
$command = $application->find('seed:run');

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$this->config, $this->input, $this->output])
->getMock();
Expand All @@ -180,7 +180,7 @@ public function testDatabaseNameSpecified()
$command = $application->find('seed:run');

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$this->config, $this->input, $this->output])
->getMock();
Expand All @@ -205,7 +205,7 @@ public function testExecuteMultipleSeeders()
$command = $application->find('seed:run');

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$this->config, $this->input, $this->output])
->getMock();
Expand Down Expand Up @@ -256,7 +256,7 @@ public function testSeedRunMemorySqlite()
$command = $application->find('seed:run');

// mock the manager class
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
/** @var \Phinx\Migration\Manager|\PHPUnit\Framework\MockObject\MockObject $managerStub */
$managerStub = $this->getMockBuilder('\Phinx\Migration\Manager')
->setConstructorArgs([$config, $this->input, $this->output])
->getMock();
Expand Down
26 changes: 26 additions & 0 deletions tests/Phinx/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Test\Phinx\Db\Adapter;

use Cake\Database\Query;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use InvalidArgumentException;
use PDO;
use PDOException;
Expand Down Expand Up @@ -2215,6 +2217,30 @@ public function testBulkInsertLiteral()
$this->assertEquals('2025-01-01 00:00:00', $rows[2]['column2']);
}

public function testBulkInsertDates()
{
$data = [
[
'name' => 'foo',
'created' => new Date(),
],
[
'name' => 'bar',
'created' => new DateTime(),
],
];
$table = new Table('table1', [], $this->adapter);
$table->addColumn('name', 'string')
->addColumn('created', 'datetime')
->insert($data)
->save();
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
$this->assertEquals('foo', $rows[0]['name']);
$this->assertEquals('bar', $rows[1]['name']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
}

public function testInsertData()
{
$data = [
Expand Down
26 changes: 26 additions & 0 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Test\Phinx\Db\Adapter;

use Cake\Database\Query;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use InvalidArgumentException;
use PDO;
use Phinx\Db\Adapter\AbstractAdapter;
Expand Down Expand Up @@ -2447,6 +2449,30 @@ public function testBulkInsertLiteral()
$this->assertEquals('2025-01-01 00:00:00', $rows[2]['column2']);
}

public function testBulkInsertDates()
{
$data = [
[
'name' => 'foo',
'created' => new Date(),
],
[
'name' => 'bar',
'created' => new DateTime(),
],
];
$table = new Table('table1', [], $this->adapter);
$table->addColumn('name', 'string')
->addColumn('created', 'datetime')
->insert($data)
->save();
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
$this->assertEquals('foo', $rows[0]['name']);
$this->assertEquals('bar', $rows[1]['name']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
}

public function testInsertData()
{
$table = new Table('table1', [], $this->adapter);
Expand Down
26 changes: 26 additions & 0 deletions tests/Phinx/Db/Adapter/SQLiteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use BadMethodCallException;
use Cake\Database\Query;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use Exception;
use InvalidArgumentException;
use PDO;
Expand Down Expand Up @@ -1901,6 +1903,30 @@ public function testBulkInsertDataEnum()
$this->assertEquals('c', $rows[0]['column3']);
}

public function testBulkInsertDates()
{
$data = [
[
'name' => 'foo',
'created' => new Date(),
],
[
'name' => 'bar',
'created' => new DateTime(),
],
];
$table = new Table('table1', [], $this->adapter);
$table->addColumn('name', 'string')
->addColumn('created', 'datetime')
->insert($data)
->save();
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
$this->assertEquals('foo', $rows[0]['name']);
$this->assertEquals('bar', $rows[1]['name']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $rows[0]['created']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
}

public function testNullWithoutDefaultValue()
{
$this->markTestSkipped('Skipping for now. See Github Issue #265.');
Expand Down
26 changes: 26 additions & 0 deletions tests/Phinx/Db/Adapter/SqlServerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use BadMethodCallException;
use Cake\Database\Query;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use InvalidArgumentException;
use PDO;
use Phinx\Db\Adapter\SqlServerAdapter;
Expand Down Expand Up @@ -1345,6 +1347,30 @@ public function testBulkInsertLiteral()
$this->assertEquals('2025-01-01 00:00:00.000', $rows[2]['column2']);
}

public function testBulkInsertDates()
{
$data = [
[
'name' => 'foo',
'created' => new Date(),
],
[
'name' => 'bar',
'created' => new DateTime(),
],
];
$table = new Table('table1', [], $this->adapter);
$table->addColumn('name', 'string')
->addColumn('created', 'datetime')
->insert($data)
->save();
$rows = $this->adapter->fetchAll('SELECT * FROM table1');
$this->assertEquals('foo', $rows[0]['name']);
$this->assertEquals('bar', $rows[1]['name']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[0]['created']);
$this->assertMatchesRegularExpression('/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $rows[1]['created']);
}

public function testInsertData()
{
$table = new Table('table1', [], $this->adapter);
Expand Down
2 changes: 2 additions & 0 deletions tests/Phinx/Migration/_files/seeds/UserSeeder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Cake\I18n\Date;
use Cake\I18n\DateTime;
use Phinx\Seed\AbstractSeed;

class UserSeeder extends AbstractSeed
Expand Down
Loading