|
|
@@ -30,6 +30,8 @@ class QueryTest extends TestCase
|
|
|
|
|
|
public $fixtures = ['core.articles', 'core.authors', 'core.comments'];
|
|
|
|
|
|
+ public $autoFixtures = false;
|
|
|
+
|
|
|
const ARTICLE_COUNT = 3;
|
|
|
const AUTHOR_COUNT = 4;
|
|
|
const COMMENT_COUNT = 6;
|
|
|
@@ -111,6 +113,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectFieldsFromTable()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(['body', 'author_id'])->from('articles')->execute();
|
|
|
$this->assertEquals(['body' => 'First Article Body', 'author_id' => 1], $result->fetch('assoc'));
|
|
|
@@ -139,6 +142,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAliasedFieldsFromTable()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(['text' => 'comment', 'article_id'])->from('comments')->execute();
|
|
|
$this->assertEquals(['text' => 'First Comment for First Article', 'article_id' => 1], $result->fetch('assoc'));
|
|
|
@@ -176,6 +180,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAliasedTables()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(['text' => 'a.body', 'a.author_id'])
|
|
|
->from(['a' => 'articles'])->execute();
|
|
|
@@ -205,6 +210,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWithJoins()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title', 'name'])
|
|
|
@@ -238,6 +244,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWithJoinsConditions()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title', 'name'])
|
|
|
@@ -280,6 +287,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAliasedJoins()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title', 'name'])
|
|
|
@@ -322,6 +330,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectLeftJoin()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$time = new \DateTime('2007-03-18 10:45:23');
|
|
|
$types = ['created' => 'datetime'];
|
|
|
@@ -353,6 +362,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectInnerJoin()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$time = new \DateTime('2007-03-18 10:45:23');
|
|
|
$types = ['created' => 'datetime'];
|
|
|
@@ -372,6 +382,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectRightJoin()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$this->skipIf(
|
|
|
$this->connection->driver() instanceof \Cake\Database\Driver\Sqlite,
|
|
|
'SQLite does not support RIGHT joins'
|
|
|
@@ -399,6 +410,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectJoinWithCallback()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$types = ['created' => 'datetime'];
|
|
|
$result = $query
|
|
|
@@ -446,6 +458,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectSimpleWhere()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -472,6 +485,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorMoreThan()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['comment'])
|
|
|
@@ -490,6 +504,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorLessThan()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -508,6 +523,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorLessThanEqual()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -525,6 +541,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorMoreThanEqual()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -542,6 +559,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorNotEqual()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -560,6 +578,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorLike()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -578,6 +597,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorLikeExpansion()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -595,6 +615,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorNotLike()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -612,6 +633,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereUnary()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -635,6 +657,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereTypes()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -713,6 +736,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereArrayType()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -735,6 +759,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereArrayTypeEmpty()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -751,6 +776,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereArrayTypeEmptyWithExpression()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -768,6 +794,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrWhere()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -788,6 +815,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAndWhere()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -818,6 +846,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectExpressionNesting()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -854,6 +883,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrWhereNoPreviousCondition()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -874,6 +904,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAndWhereNoPreviousCondition()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -894,6 +925,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereUsingClosure()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -941,6 +973,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testTupleWithClosureExpression()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select(['id'])
|
|
|
->from('comments')
|
|
|
@@ -969,6 +1002,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAndWhereUsingClosure()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1003,6 +1037,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrWhereUsingClosure()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1041,6 +1076,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereUsingExpressionInField()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1063,6 +1099,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereOperatorMethods()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['title'])
|
|
|
@@ -1238,6 +1275,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInValueCast()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1304,6 +1342,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInValueCast2()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1373,6 +1412,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testWhereWithBetween()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1399,6 +1439,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testWhereWithBetweenComplex()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1427,6 +1468,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testWhereWithBetweenWithExpressionField()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1454,6 +1496,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testWhereWithBetweenWithExpressionParts()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1481,6 +1524,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectExpressionComposition()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1561,6 +1605,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWhereNot()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1619,6 +1664,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrderBy()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|
|
|
@@ -1683,6 +1729,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrderByString()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select(['id'])
|
|
|
->from('articles')
|
|
|
@@ -1701,6 +1748,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrderAsc()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select(['id'])
|
|
|
->from('articles')
|
|
|
@@ -1741,6 +1789,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrderDesc()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select(['id'])
|
|
|
->from('articles')
|
|
|
@@ -1781,6 +1830,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectGroup()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['total' => 'count(author_id)', 'author_id'])
|
|
|
@@ -1811,6 +1861,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectDistinct()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['author_id'])
|
|
|
@@ -1833,6 +1884,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectDistinctON()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id', 'author_id'])
|
|
|
@@ -1926,6 +1978,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectHaving()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['total' => 'count(author_id)', 'author_id'])
|
|
|
@@ -1958,6 +2011,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOrHaving()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['total' => 'count(author_id)', 'author_id'])
|
|
|
@@ -2005,6 +2059,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAndHaving()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['total' => 'count(author_id)', 'author_id'])
|
|
|
@@ -2049,6 +2104,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectLimit()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select('id')->from('articles')->limit(1)->execute();
|
|
|
$this->assertCount(1, $result);
|
|
|
@@ -2065,6 +2121,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectOffset()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select('id')->from('comments')
|
|
|
->limit(1)
|
|
|
@@ -2123,6 +2180,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectPage()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select('id')->from('comments')
|
|
|
->limit(1)
|
|
|
@@ -2164,6 +2222,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSubqueryInSelect()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$subquery = (new Query($this->connection))
|
|
|
->select('name')
|
|
|
@@ -2208,6 +2267,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSuqueryInFrom()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$subquery = (new Query($this->connection))
|
|
|
->select(['id', 'comment'])
|
|
|
@@ -2236,6 +2296,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSubqueryInWhere()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$subquery = (new Query($this->connection))
|
|
|
->select(['id'])
|
|
|
@@ -2280,6 +2341,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSubqueryInJoin()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$subquery = (new Query($this->connection))->select('*')->from('authors');
|
|
|
|
|
|
$query = new Query($this->connection);
|
|
|
@@ -2309,6 +2371,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUnion()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles', 'Comments');
|
|
|
$union = (new Query($this->connection))->select(['id', 'title'])->from(['a' => 'articles']);
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(['id', 'comment'])
|
|
|
@@ -2349,6 +2412,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUnionOrderBy()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Comments');
|
|
|
$this->skipIf(
|
|
|
($this->connection->driver() instanceof \Cake\Database\Driver\Sqlite ||
|
|
|
$this->connection->driver() instanceof \Cake\Database\Driver\Sqlserver),
|
|
|
@@ -2378,6 +2442,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUnionAll()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles', 'Comments');
|
|
|
$union = (new Query($this->connection))->select(['id', 'title'])->from(['a' => 'articles']);
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(['id', 'comment'])
|
|
|
@@ -2409,6 +2474,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDecorateResults()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id', 'title'])
|
|
|
@@ -2461,6 +2527,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDeleteWithFrom()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
|
|
|
$query->delete()
|
|
|
@@ -2483,6 +2550,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDeleteWithAliasedFrom()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
|
|
|
$query->delete()
|
|
|
@@ -2505,6 +2573,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDeleteNoFrom()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
|
|
|
$query->delete('authors')
|
|
|
@@ -2526,6 +2595,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectAndDeleteOnSameQuery()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select()
|
|
|
->delete('authors')
|
|
|
@@ -2543,6 +2613,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUpdateSimple()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->update('authors')
|
|
|
->set('name', 'mark')
|
|
|
@@ -2562,6 +2633,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUpdateMultipleFields()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->update('articles')
|
|
|
->set('title', 'mark', 'string')
|
|
|
@@ -2588,6 +2660,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUpdateMultipleFieldsArray()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->update('articles')
|
|
|
->set([
|
|
|
@@ -2616,6 +2689,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUpdateWithExpression()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
|
|
|
$expr = $query->newExpr()->equalFields('article_id', 'user_id');
|
|
|
@@ -2643,6 +2717,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUpdateArrayFields()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$date = new \DateTime;
|
|
|
$query->update('comments')
|
|
|
@@ -2673,6 +2748,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUpdateSetCallable()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$date = new \DateTime;
|
|
|
$query->update('comments')
|
|
|
@@ -2731,6 +2807,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertSimple()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->insert(['title', 'body'])
|
|
|
->into('articles')
|
|
|
@@ -2774,6 +2851,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertSparseRow()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->insert(['title', 'body'])
|
|
|
->into('articles')
|
|
|
@@ -2815,6 +2893,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertMultipleRowsSparse()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->insert(['title', 'body'])
|
|
|
->into('articles')
|
|
|
@@ -2859,6 +2938,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertFromSelect()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors', 'Articles');
|
|
|
$select = (new Query($this->connection))->select(['name', "'some text'", 99])
|
|
|
->from('authors')
|
|
|
->where(['id' => 1]);
|
|
|
@@ -2912,6 +2992,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertFailureMixingTypesArrayFirst()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->insert(['name'])
|
|
|
->into('articles')
|
|
|
@@ -2926,6 +3007,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertFailureMixingTypesQueryFirst()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->insert(['name'])
|
|
|
->into('articles')
|
|
|
@@ -2940,6 +3022,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testInsertExpressionValues()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles', 'Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->insert(['title', 'author_id'])
|
|
|
->into('articles')
|
|
|
@@ -3006,6 +3089,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSQLFunctions()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(
|
|
|
function ($q) {
|
|
|
@@ -3108,6 +3192,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDefaultTypes()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$this->assertEquals([], $query->defaultTypes());
|
|
|
$types = ['id' => 'integer', 'created' => 'datetime'];
|
|
|
@@ -3136,6 +3221,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testBind()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$results = $query->select(['id', 'comment'])
|
|
|
->from('comments')
|
|
|
@@ -3163,6 +3249,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testAppendSelect()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$sql = $query
|
|
|
->select(['id', 'title'])
|
|
|
@@ -3453,6 +3540,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testIsNullWithExpressions()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$query = new Query($this->connection);
|
|
|
$subquery = (new Query($this->connection))
|
|
|
->select(['id'])
|
|
|
@@ -3508,6 +3596,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDirectIsNull()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$sql = (new Query($this->connection))
|
|
|
->select(['name'])
|
|
|
->from(['authors'])
|
|
|
@@ -3532,6 +3621,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDirectIsNotNull()
|
|
|
{
|
|
|
+ $this->loadFixtures('Authors');
|
|
|
$sql = (new Query($this->connection))
|
|
|
->select(['name'])
|
|
|
->from(['authors'])
|
|
|
@@ -3555,6 +3645,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSqlCaseStatement()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$publishedCase = $query
|
|
|
->newExpr()
|
|
|
@@ -3642,6 +3733,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testUnbufferedQuery()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query->select(['body', 'author_id'])
|
|
|
->from('articles')
|
|
|
@@ -3677,6 +3769,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testDeepClone()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select(['id', 'title' => $query->func()->concat(['title' => 'literal', 'test'])])
|
|
|
->from('articles')
|
|
|
@@ -3729,6 +3822,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectTypeConversion()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$query
|
|
|
->select(['id', 'comment', 'the_date' => 'created'])
|
|
|
@@ -3782,6 +3876,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testRemoveJoin()
|
|
|
{
|
|
|
+ $this->loadFixtures('Articles');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select(['id', 'title'])
|
|
|
->from('articles')
|
|
|
@@ -3803,6 +3898,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testBetweenExpressionAndTypeMap()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$query->select('id')
|
|
|
->from('comments')
|
|
|
@@ -3932,6 +4028,7 @@ class QueryTest extends TestCase
|
|
|
*/
|
|
|
public function testSelectWithObjFetchType()
|
|
|
{
|
|
|
+ $this->loadFixtures('Comments');
|
|
|
$query = new Query($this->connection);
|
|
|
$result = $query
|
|
|
->select(['id'])
|