Skip to content

Commit ac5fb10

Browse files
authored
Merge pull request #1906 from atishamte/subquery
SubQuery related test cases w.r.t #1775
2 parents 1c87d56 + 3e6e06e commit ac5fb10

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/system/Database/Live/WhereTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,42 @@ public function testWhereNotIn()
121121

122122
//--------------------------------------------------------------------
123123

124+
public function testSubQuery()
125+
{
126+
$subQuery = $this->db->table('job')
127+
->select('id')
128+
->where('name', 'Developer')
129+
->getCompiledSelect();
130+
131+
$jobs = $this->db->table('job')
132+
->where('id not in (' . $subQuery . ')', null, false)
133+
->get()
134+
->getResult();
135+
136+
$this->assertCount(3, $jobs);
137+
$this->assertEquals('Politician', $jobs[0]->name);
138+
$this->assertEquals('Accountant', $jobs[1]->name);
139+
$this->assertEquals('Musician', $jobs[2]->name);
140+
}
141+
142+
//--------------------------------------------------------------------
143+
144+
public function testSubQueryAnotherType()
145+
{
146+
$subQuery = $this->db->table('job')
147+
->select('id')
148+
->where('name', 'Developer')
149+
->getCompiledSelect();
150+
151+
$jobs = $this->db->table('job')
152+
->where('id = (' . $subQuery . ')', null, false)
153+
->get()
154+
->getResult();
155+
156+
$this->assertCount(1, $jobs);
157+
$this->assertEquals('Developer', $jobs[0]->name);
158+
}
159+
160+
//--------------------------------------------------------------------
161+
124162
}

0 commit comments

Comments
 (0)