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
14 changes: 7 additions & 7 deletions tests/system/Database/Builder/AliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testAlias(): void

$expectedSQL = 'SELECT * FROM "jobs" "j"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}

public function testTableName(): void
Expand All @@ -49,7 +49,7 @@ public function testTableName(): void

$expectedSQL = 'SELECT * FROM "jobs" "j"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}

public function testAliasSupportsArrayOfNames(): void
Expand All @@ -58,7 +58,7 @@ public function testAliasSupportsArrayOfNames(): void

$expectedSQL = 'SELECT * FROM "jobs" "j", "users" "u"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}

public function testAliasSupportsStringOfNames(): void
Expand All @@ -67,7 +67,7 @@ public function testAliasSupportsStringOfNames(): void

$expectedSQL = 'SELECT * FROM "jobs" "j", "users" "u"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}

/**
Expand All @@ -82,7 +82,7 @@ public function testAliasLeftJoinWithShortTableName(): void

$expectedSQL = 'SELECT * FROM "db_jobs" LEFT JOIN "db_users" as "u" ON "u"."id" = "db_jobs"."id"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}

/**
Expand All @@ -97,7 +97,7 @@ public function testAliasLeftJoinWithLongTableName(): void

$expectedSQL = 'SELECT * FROM "db_jobs" LEFT JOIN "db_users" as "u" ON "db_users"."id" = "db_jobs"."id"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}

/**
Expand All @@ -113,6 +113,6 @@ public function testAliasSimpleLikeWithDBPrefix(): void
$expectedSQL = <<<'SQL'
SELECT * FROM "db_jobs" "j" WHERE "j"."name" LIKE '%veloper%' ESCAPE '!'
SQL;
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}
}
20 changes: 10 additions & 10 deletions tests/system/Database/Builder/CountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testCountAllResults(): void

$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM "jobs" WHERE "id" > :id:';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

public function testCountAllResultsDoesNotUseLockForUpdate(): void
Expand All @@ -65,8 +65,8 @@ public function testCountAllResultsDoesNotUseLockForUpdate(): void

$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM "jobs" WHERE "id" > :id:';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame('SELECT * FROM "jobs" WHERE "id" > 3 FOR UPDATE', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT * FROM "jobs" WHERE "id" > 3 FOR UPDATE', $builder->getCompiledSelect(false));
}

public function testCountAllResultsWithSQLSRVDoesNotUseLockForUpdate(): void
Expand All @@ -80,8 +80,8 @@ public function testCountAllResultsWithSQLSRVDoesNotUseLockForUpdate(): void

$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM "test"."dbo"."jobs" WHERE "id" > :id:';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame('SELECT * FROM "test"."dbo"."jobs" WITH (UPDLOCK, ROWLOCK) WHERE "id" > 3', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT * FROM "test"."dbo"."jobs" WITH (UPDLOCK, ROWLOCK) WHERE "id" > 3', $builder->getCompiledSelect(false));
}

public function testCountAllResultsWithGroupBy(): void
Expand All @@ -94,7 +94,7 @@ public function testCountAllResultsWithGroupBy(): void

$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM ( SELECT * FROM "jobs" WHERE "id" > :id: GROUP BY "id" ) CI_count_all_results';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

/**
Expand All @@ -110,11 +110,11 @@ public function testCountAllResultsWithGroupByAndPrefix(): void
$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM ( SELECT "ci_jobs".* FROM "ci_jobs" WHERE "id" > :id: GROUP BY "id" ) CI_count_all_results';

$answer1 = $builder->countAllResults(false);
$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer1));
$this->assertSameSql($expectedSQL, $answer1);

// We run the query one more time to make sure the DBPrefix is added only once
$answer2 = $builder->countAllResults(false);
$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer2));
$this->assertSameSql($expectedSQL, $answer2);
}

public function testCountAllResultsWithGroupByAndHaving(): void
Expand All @@ -128,7 +128,7 @@ public function testCountAllResultsWithGroupByAndHaving(): void

$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM ( SELECT * FROM "jobs" WHERE "id" > :id: GROUP BY "id" HAVING 1 = 1 ) CI_count_all_results';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

public function testCountAllResultsWithHavingOnly(): void
Expand All @@ -141,6 +141,6 @@ public function testCountAllResultsWithHavingOnly(): void

$expectedSQL = 'SELECT COUNT(*) AS "numrows" FROM "jobs" WHERE "id" > :id: HAVING 1 = 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}
}
2 changes: 1 addition & 1 deletion tests/system/Database/Builder/DistinctTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public function testDelete(): void

$expectedSQL = 'SELECT DISTINCT "country" FROM "user"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
$this->assertSameSql($expectedSQL, $builder->getCompiledSelect());
}
}
2 changes: 1 addition & 1 deletion tests/system/Database/Builder/EmptyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public function testEmptyWithNoTable(): void

$expectedSQL = 'DELETE FROM "jobs"';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}
}
52 changes: 17 additions & 35 deletions tests/system/Database/Builder/ExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testExistsReturnsSqlInTestMode(): void

$expectedSQL = 'SELECT 1 FROM "jobs" WHERE "id" > :id: LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

public function testDoesntExistReturnsSqlInTestMode(): void
Expand All @@ -54,7 +54,7 @@ public function testDoesntExistReturnsSqlInTestMode(): void

$expectedSQL = 'SELECT 1 FROM "jobs" WHERE "id" > :id: LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

public function testExistsDoesNotUseOrderByOrLockForUpdate(): void
Expand All @@ -69,11 +69,8 @@ public function testExistsDoesNotUseOrderByOrLockForUpdate(): void

$expectedSQL = 'SELECT 1 FROM "jobs" WHERE "id" > :id: LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame(
'SELECT * FROM "jobs" WHERE "id" > 3 ORDER BY "id" DESC FOR UPDATE',
str_replace("\n", ' ', $builder->getCompiledSelect(false)),
);
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT * FROM "jobs" WHERE "id" > 3 ORDER BY "id" DESC FOR UPDATE', $builder->getCompiledSelect(false));
}

public function testExistsWithSQLSRVDoesNotUseOrderByOrLockForUpdate(): void
Expand All @@ -90,11 +87,8 @@ public function testExistsWithSQLSRVDoesNotUseOrderByOrLockForUpdate(): void

$expectedSQL = 'SELECT 1 FROM "test"."dbo"."jobs" WHERE "id" > :id: ORDER BY (SELECT NULL) OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame(
'SELECT * FROM "test"."dbo"."jobs" WITH (UPDLOCK, ROWLOCK) WHERE "id" > 3 ORDER BY "id" DESC',
str_replace("\n", ' ', $builder->getCompiledSelect(false)),
);
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT * FROM "test"."dbo"."jobs" WITH (UPDLOCK, ROWLOCK) WHERE "id" > 3 ORDER BY "id" DESC', $builder->getCompiledSelect(false));
}

public function testExistsHonorsExistingLimitAndOffset(): void
Expand All @@ -108,11 +102,8 @@ public function testExistsHonorsExistingLimitAndOffset(): void

$expectedSQL = 'SELECT 1 FROM ( SELECT * FROM "jobs" WHERE "id" > :id: LIMIT 20, 10 ) CI_exists LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame(
'SELECT * FROM "jobs" WHERE "id" > 3 LIMIT 20, 10',
str_replace("\n", ' ', $builder->getCompiledSelect(false)),
);
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT * FROM "jobs" WHERE "id" > 3 LIMIT 20, 10', $builder->getCompiledSelect(false));
}

public function testExistsHonorsLimitZero(): void
Expand All @@ -131,7 +122,7 @@ public function testExistsHonorsLimitZero(): void

$expectedSQL = 'SELECT 1 FROM "jobs" WHERE "id" > :id: LIMIT 0';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
} finally {
$config->limitZeroAsAll = $limitZeroAsAll;
}
Expand All @@ -150,11 +141,8 @@ public function testExistsWithGroupByAndHaving(): void

$expectedSQL = 'SELECT 1 FROM ( SELECT COUNT("id") AS "total" FROM "jobs" WHERE "id" > :id: GROUP BY "id" HAVING "total" > :total: ) CI_exists LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame(
'SELECT COUNT("id") AS "total" FROM "jobs" WHERE "id" > 3 GROUP BY "id" HAVING "total" > 1',
str_replace("\n", ' ', $builder->getCompiledSelect(false)),
);
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT COUNT("id") AS "total" FROM "jobs" WHERE "id" > 3 GROUP BY "id" HAVING "total" > 1', $builder->getCompiledSelect(false));
}

public function testExistsWithAggregateSelection(): void
Expand All @@ -168,11 +156,8 @@ public function testExistsWithAggregateSelection(): void

$expectedSQL = 'SELECT 1 FROM ( SELECT COUNT("id") AS "total" FROM "jobs" WHERE "id" > :id: ) CI_exists LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame(
'SELECT COUNT("id") AS "total" FROM "jobs" WHERE "id" > 3',
str_replace("\n", ' ', $builder->getCompiledSelect(false)),
);
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT COUNT("id") AS "total" FROM "jobs" WHERE "id" > 3', $builder->getCompiledSelect(false));
}

public function testExistsWithUnion(): void
Expand All @@ -184,11 +169,8 @@ public function testExistsWithUnion(): void

$expectedSQL = 'SELECT 1 FROM ( SELECT * FROM (SELECT * FROM "jobs") "uwrp0" UNION SELECT * FROM (SELECT * FROM "jobs") "uwrp1" ) CI_exists LIMIT 1';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSame(
'SELECT * FROM (SELECT * FROM "jobs") "uwrp0" UNION SELECT * FROM (SELECT * FROM "jobs") "uwrp1"',
str_replace("\n", ' ', $builder->getCompiledSelect(false)),
);
$this->assertSameSql($expectedSQL, $answer);
$this->assertSameSql('SELECT * FROM (SELECT * FROM "jobs") "uwrp0" UNION SELECT * FROM (SELECT * FROM "jobs") "uwrp1"', $builder->getCompiledSelect(false));
}

public function testExistsResetsByDefault(): void
Expand All @@ -198,7 +180,7 @@ public function testExistsResetsByDefault(): void

$builder->where('id >', 3)->exists();

$this->assertSame('SELECT * FROM "jobs"', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql('SELECT * FROM "jobs"', $builder->getCompiledSelect(false));
$this->assertSame([], $builder->getBinds());
}

Expand All @@ -209,7 +191,7 @@ public function testExistsHonorsResetFalse(): void

$builder->where('id >', 3)->exists(false);

$this->assertSame('SELECT * FROM "jobs" WHERE "id" > 3', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql('SELECT * FROM "jobs" WHERE "id" > 3', $builder->getCompiledSelect(false));
$this->assertSame([
'id' => [
3,
Expand Down
10 changes: 5 additions & 5 deletions tests/system/Database/Builder/ExplainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testExplainReturnsSqlInTestMode(): void

$expectedSQL = 'EXPLAIN SELECT * FROM "jobs" WHERE "id" > 3';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

public function testSQLiteExplainUsesQueryPlanInTestMode(): void
Expand All @@ -58,7 +58,7 @@ public function testSQLiteExplainUsesQueryPlanInTestMode(): void

$expectedSQL = 'EXPLAIN QUERY PLAN SELECT * FROM "jobs" WHERE "id" > 3';

$this->assertSame($expectedSQL, str_replace("\n", ' ', $answer));
$this->assertSameSql($expectedSQL, $answer);
}

public function testExplainResetsByDefault(): void
Expand All @@ -68,7 +68,7 @@ public function testExplainResetsByDefault(): void

$builder->where('id >', 3)->explain();

$this->assertSame('SELECT * FROM "jobs"', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql('SELECT * FROM "jobs"', $builder->getCompiledSelect(false));
$this->assertSame([], $builder->getBinds());
}

Expand All @@ -79,7 +79,7 @@ public function testExplainHonorsResetFalse(): void

$builder->where('id >', 3)->explain(false);

$this->assertSame('SELECT * FROM "jobs" WHERE "id" > 3', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql('SELECT * FROM "jobs" WHERE "id" > 3', $builder->getCompiledSelect(false));
$this->assertSame([
'id' => [
3,
Expand All @@ -96,7 +96,7 @@ public function testExplainReturnsFalseWhenQueryFails(): void
$builder = new BaseBuilder('jobs', $db);

$this->assertFalse($builder->where('id >', 3)->explain());
$this->assertSame('SELECT * FROM "jobs"', str_replace("\n", ' ', $builder->getCompiledSelect(false)));
$this->assertSameSql('SELECT * FROM "jobs"', $builder->getCompiledSelect(false));
$this->assertSame([], $builder->getBinds());
}

Expand Down
Loading
Loading