Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Database extends Config
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'strictOn' => true,
'failover' => [],
'port' => 3306,
'foreignKeys' => true,
Expand Down
10 changes: 5 additions & 5 deletions tests/_support/Config/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Registrar
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'strictOn' => true,
'failover' => [],
'port' => 3306,
],
Expand All @@ -60,7 +60,7 @@ class Registrar
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
'failover' => [],
'port' => 5432,
],
Expand All @@ -79,7 +79,7 @@ class Registrar
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
'failover' => [],
'port' => 3306,
'foreignKeys' => true,
Expand All @@ -100,7 +100,7 @@ class Registrar
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
'failover' => [],
'port' => 1433,
],
Expand All @@ -119,7 +119,7 @@ class Registrar
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
'failover' => [],
],
];
Expand Down
36 changes: 21 additions & 15 deletions tests/_support/Database/Seeds/CITestSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class CITestSeeder extends Seeder
{
public function run(): void
{
// Job Data
$data = [
'user' => [
[
Expand Down Expand Up @@ -147,7 +146,8 @@ public function run(): void
],
];

// set SQL times to more correct format
// Normalize formats and remove unsupported types for each database driver

if ($this->db->DBDriver === 'SQLite3') {
$data['type_test'][0]['type_date'] = '2020/01/11';
$data['type_test'][0]['type_time'] = '15:22:00';
Expand All @@ -157,7 +157,15 @@ public function run(): void

if ($this->db->DBDriver === 'Postgre') {
$data['type_test'][0]['type_time'] = '15:22:00';
$data['type_test'][0]['type_boolean'] = true;
$data['type_test'][0]['type_boolean'] = true; // PostgreSQL has native boolean type

$data['ci_sessions'][] = [
'id' => 'ci_session:1f5o06b43phsnnf8if6bo33b635e4p2o',
'ip_address' => '127.0.0.1',
'timestamp' => '2021-06-25 21:54:14.991403+02',
'data' => '\x' . bin2hex('__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";'),
];

unset(
$data['type_test'][0]['type_enum'],
$data['type_test'][0]['type_set'],
Expand Down Expand Up @@ -185,6 +193,11 @@ public function run(): void
}

if ($this->db->DBDriver === 'MySQLi') {
$data['type_test'][0]['type_time'] = '15:22:00';
$data['type_test'][0]['type_date'] = '2020-01-11';
$data['type_test'][0]['type_datetime'] = '2020-06-18 05:12:24';
$data['type_test'][0]['type_timestamp'] = '2019-07-18 21:53:21';

$data['ci_sessions'][] = [
'id' => 'ci_session:1f5o06b43phsnnf8if6bo33b635e4p2o',
'ip_address' => '127.0.0.1',
Expand All @@ -193,29 +206,22 @@ public function run(): void
];
}

if ($this->db->DBDriver === 'Postgre') {
$data['ci_sessions'][] = [
'id' => 'ci_session:1f5o06b43phsnnf8if6bo33b635e4p2o',
'ip_address' => '127.0.0.1',
'timestamp' => '2021-06-25 21:54:14.991403+02',
'data' => '\x' . bin2hex('__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";'),
];
}

if ($this->db->DBDriver === 'OCI8') {
$this->db->query('alter session set NLS_DATE_FORMAT=?', ['YYYY-MM-DD HH24:MI:SS']);

$data['type_test'][0]['type_date'] = '2020-01-11 22:11:00';
$data['type_test'][0]['type_time'] = '2020-07-18 15:22:00';
$data['type_test'][0]['type_datetime'] = '2020-06-18 05:12:24';
$data['type_test'][0]['type_timestamp'] = '2020-06-18 21:53:21';

unset($data['type_test'][0]['type_blob']);
}

foreach ($data as $table => $dummyData) {
foreach ($data as $table => $seeds) {
$this->db->table($table)->truncate();

foreach ($dummyData as $singleDummyData) {
$this->db->table($table)->insert($singleDummyData);
foreach ($seeds as $seed) {
$this->db->table($table)->insert($seed);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,10 @@ public function testAddTextColumnWithConstraint(): void
$this->forge->addColumn('user', [
'text_with_constraint' => ['type' => 'nvarchar(max)', 'default' => ''],
]);
} elseif (in_array($this->db->DBDriver, ['MySQLi', 'Postgre', 'SQLite3'], true)) {
$this->forge->addColumn('user', [
'text_with_constraint' => ['type' => 'text'],
]);
} else {
$this->forge->addColumn('user', [
'text_with_constraint' => ['type' => 'text', 'constraint' => 255, 'default' => ''],
Expand Down
33 changes: 6 additions & 27 deletions tests/system/Database/Live/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ final class InsertTest extends CIUnitTestCase
{
use DatabaseTestTrait;

/**
* @var Forge
*/
public $forge;

protected $refresh = true;
protected $seed = CITestSeeder::class;
protected $seed = CITestSeeder::class;
private Forge $forge;

public function testInsert(): void
{
Expand Down Expand Up @@ -93,26 +88,10 @@ public function testInsertBatchFailed(): void
{
$this->expectException(DatabaseException::class);

$data = [
[
'name' => 'Grocery Sales',
],
[
'name' => null,
],
];

$db = $this->db;

if ($this->db->DBDriver === 'MySQLi') {
// strict mode is required for MySQLi to throw an exception here
$config = config('Database');
$config->tests['strictOn'] = true;

$db = Database::connect($config->tests);
}

$db->table('job')->insertBatch($data);
$this->db->table('job')->insertBatch([
['name' => 'Grocery Sales'],
['name' => null],
]);
}

public function testReplaceWithNoMatchingData(): void
Expand Down
Loading
Loading