Skip to content

Commit 996d752

Browse files
committed
JoinTest now passing (and simplified)
1 parent 510ebfd commit 996d752

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

tests/Functional/JoinTest.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function tearDown()
2020

2121
public function testInnerJoinT1()
2222
{
23-
$excpected = array(
23+
$expected = array(
2424
array(
2525
'left' => array('id' => 1, 'other' => 'a'),
2626
'right' => array('id' => 'a', 'other' => 1 )
@@ -42,15 +42,14 @@ function ($r1, $r2) {
4242
return $r1('other')->eq($r2('id'));
4343
}
4444
)
45-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
4645
->run($this->conn);
4746

48-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
47+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
4948
}
5049

5150
public function testInnerJoinT2()
5251
{
53-
$excpected = array(
52+
$expected = array(
5453
array(
5554
'right' => array('id' => 1, 'other' => 'a'),
5655
'left' => array('id' => 'a', 'other' => 1 )
@@ -68,15 +67,14 @@ function ($r1, $r2) {
6867
return $r1('other')->eq($r2('id'));
6968
}
7069
)
71-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
7270
->run($this->conn);
7371

74-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
72+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
7573
}
7674

7775
public function testOuterJoinT1()
7876
{
79-
$excpected = array(
77+
$expected = array(
8078
array(
8179
'left' => array('id' => 1, 'other' => 'a'),
8280
'right' => array('id' => 'a', 'other' => 1 )
@@ -98,15 +96,14 @@ function ($r1, $r2) {
9896
return $r1('other')->eq($r2('id'));
9997
}
10098
)
101-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
10299
->run($this->conn);
103100

104-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
101+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
105102
}
106103

107104
public function testOuterJoinT2()
108105
{
109-
$excpected = array(
106+
$expected = array(
110107
array(
111108
'right' => array('id' => 1, 'other' => 'a'),
112109
'left' => array('id' => 'a', 'other' => 1 )
@@ -125,15 +122,14 @@ function ($r1, $r2) {
125122
return $r1('other')->eq($r2('id'));
126123
}
127124
)
128-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
129125
->run($this->conn);
130126

131-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
127+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
132128
}
133129

134130
public function testEqJoinOther()
135131
{
136-
$excpected = array(
132+
$expected = array(
137133
array(
138134
'left' => array('id' => 1, 'other' => 'a'),
139135
'right' => array('id' => 'a', 'other' => 1 )
@@ -150,15 +146,14 @@ public function testEqJoinOther()
150146

151147
$res = $this->db()->table('t1')
152148
->eqJoin('other', $this->db()->table('t2'))
153-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
154149
->run($this->conn);
155150

156-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
151+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
157152
}
158153

159154
public function testEqJoinId()
160155
{
161-
$excpected = array(
156+
$expected = array(
162157
array(
163158
'left' => array('id' => 1, 'other' => 'a'),
164159
'right' => array('id' => 'a', 'other' => 1 )
@@ -171,15 +166,14 @@ public function testEqJoinId()
171166

172167
$res = $this->db()->table('t1')
173168
->eqJoin('id', $this->db()->table('t2'), array('index' => 'other'))
174-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
175169
->run($this->conn);
176170

177-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
171+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
178172
}
179173

180174
public function testEqJoinFunc()
181175
{
182-
$excpected = array(
176+
$expected = array(
183177
array(
184178
'left' => array('id' => 1, 'other' => 'a'),
185179
'right' => array('id' => 'a', 'other' => 1 )
@@ -198,31 +192,29 @@ public function testEqJoinFunc()
198192
->eqJoin(function ($x) {
199193
return $x('other');
200194
}, $this->db()->table('t2'))
201-
->orderBy(array(function($x) { return $x("left")->getField("id"); }, function($x) { return $x("right")->getField("id"); }))
202195
->run($this->conn);
203196

204-
$this->assertEquals($excpected, $this->orderArrayByLeftAndRightId($res));
197+
$this->assertEquals($expected, $this->orderArrayByLeftAndRightId($res));
205198
}
206199

207200
public function testEqJoinZip()
208201
{
209-
$excpected = array(
202+
$expected = array(
210203
array('id' => 'a', 'other' => 1 ),
211204
array('id' => 'b', 'other' => 1 )
212205
);
213206

214207
$res = $this->db()->table('t1')
215208
->eqJoin('id', $this->db()->table('t2'), array('index' => 'other'))
216209
->zip()
217-
->orderBy("id")
218210
->run($this->conn);
219211

220-
$this->assertEquals($excpected, $this->orderArrayById($res));
212+
$this->assertEquals($expected, $this->orderArrayById($res));
221213
}
222214

223215
protected function orderArrayByLeftAndRightId($data)
224216
{
225-
$data = $this->toArray($data);
217+
$data = $this->toArray($data->toArray());
226218
usort($data, function ($a, $b) {
227219
if ($a['left']['id'] == $b['left']['id']) {
228220
return $a['right']['id'] > $b['right']['id'];
@@ -235,7 +227,7 @@ protected function orderArrayByLeftAndRightId($data)
235227

236228
protected function orderArrayById($data)
237229
{
238-
$data = $this->toArray($data);
230+
$data = $this->toArray($data->toArray());
239231
usort($data, function ($a, $b) {
240232
return strcmp($a['id'], $b['id']);
241233
});

0 commit comments

Comments
 (0)