Skip to content

Commit f02d2cc

Browse files
committed
Attempt at fixing JoinTest
1 parent 39378b6 commit f02d2cc

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

tests/Functional/JoinTest.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ public function testInnerJoinT1()
4141
function ($r1, $r2) {
4242
return $r1('other')->eq($r2('id'));
4343
}
44-
)->run($this->conn);
44+
)
45+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
46+
->run($this->conn);
4547

46-
$this->assertEquals($excpected, $this->orderArrayByLeftId($res));
48+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
4749
}
4850

4951
public function testInnerJoinT2()
@@ -65,9 +67,11 @@ public function testInnerJoinT2()
6567
function ($r1, $r2) {
6668
return $r1('other')->eq($r2('id'));
6769
}
68-
)->run($this->conn);
70+
)
71+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
72+
->run($this->conn);
6973

70-
$this->assertEquals($excpected, $this->orderArrayByLeftId($res));
74+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
7175
}
7276

7377
public function testOuterJoinT1()
@@ -93,9 +97,11 @@ public function testOuterJoinT1()
9397
function ($r1, $r2) {
9498
return $r1('other')->eq($r2('id'));
9599
}
96-
)->run($this->conn);
100+
)
101+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
102+
->run($this->conn);
97103

98-
$this->assertEquals($excpected, $this->orderArrayByLeftId($res));
104+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
99105
}
100106

101107
public function testOuterJoinT2()
@@ -118,9 +124,11 @@ public function testOuterJoinT2()
118124
function ($r1, $r2) {
119125
return $r1('other')->eq($r2('id'));
120126
}
121-
)->run($this->conn);
127+
)
128+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
129+
->run($this->conn);
122130

123-
$this->assertEquals($excpected, $this->orderArrayByLeftId($res));
131+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
124132
}
125133

126134
public function testEqJoinOther()
@@ -142,9 +150,10 @@ public function testEqJoinOther()
142150

143151
$res = $this->db()->table('t1')
144152
->eqJoin('other', $this->db()->table('t2'))
153+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
145154
->run($this->conn);
146155

147-
$this->assertEquals($excpected, $this->orderArrayByLeftId($res));
156+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
148157
}
149158

150159
public function testEqJoinId()
@@ -162,9 +171,10 @@ public function testEqJoinId()
162171

163172
$res = $this->db()->table('t1')
164173
->eqJoin('id', $this->db()->table('t2'), array('index' => 'other'))
174+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
165175
->run($this->conn);
166176

167-
$this->assertEquals($excpected, $this->toArray($res->toArray()));
177+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
168178
}
169179

170180
public function testEqJoinFunc()
@@ -188,9 +198,10 @@ public function testEqJoinFunc()
188198
->eqJoin(function ($x) {
189199
return $x('other');
190200
}, $this->db()->table('t2'))
201+
->orderBy(array(r\row("left")->getField("id"), r\row("right")->getField("id")))
191202
->run($this->conn);
192203

193-
$this->assertEquals($excpected, $this->orderArrayByLeftId($res));
204+
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
194205
}
195206

196207
public function testEqJoinZip()
@@ -203,15 +214,19 @@ public function testEqJoinZip()
203214
$res = $this->db()->table('t1')
204215
->eqJoin('id', $this->db()->table('t2'), array('index' => 'other'))
205216
->zip()
217+
->orderBy("id")
206218
->run($this->conn);
207219

208220
$this->assertEquals($excpected, $this->orderArrayById($res));
209221
}
210222

211-
protected function orderArrayByLeftId($data)
223+
protected function orderArrayByLeftAndRightId($data)
212224
{
213-
$data = $this->toArray($data->toArray());
225+
$data = $this->toArray($data);
214226
usort($data, function ($a, $b) {
227+
if ($a['left']['id'] == $b['left']['id']) {
228+
return $a['right']['id'] > $b['right']['id'];
229+
}
215230
return $a['left']['id'] > $b['left']['id'];
216231
});
217232

@@ -220,7 +235,7 @@ protected function orderArrayByLeftId($data)
220235

221236
protected function orderArrayById($data)
222237
{
223-
$data = $this->toArray($data->toArray());
238+
$data = $this->toArray($data);
224239
usort($data, function ($a, $b) {
225240
return strcmp($a['id'], $b['id']);
226241
});

0 commit comments

Comments
 (0)