Skip to content

Commit 25a258a

Browse files
author
Pooya Parsa
committed
5.3 UnitTests WIP
1 parent cd75b17 commit 25a258a

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

tests/EmbeddedRelationsTest.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testEmbedsManySave()
3131

3232
$this->assertNotNull($user->addresses);
3333
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->addresses);
34-
$this->assertEquals(['London'], $user->addresses->lists('city')->all());
34+
$this->assertEquals(['London'], $user->addresses->pluck('city')->all());
3535
$this->assertInstanceOf('DateTime', $address->created_at);
3636
$this->assertInstanceOf('DateTime', $address->updated_at);
3737
$this->assertNotNull($address->_id);
@@ -43,7 +43,7 @@ public function testEmbedsManySave()
4343
$address = $user->addresses()->save(new Address(['city' => 'Paris']));
4444

4545
$user = User::find($user->_id);
46-
$this->assertEquals(['London', 'Paris'], $user->addresses->lists('city')->all());
46+
$this->assertEquals(['London', 'Paris'], $user->addresses->pluck('city')->all());
4747

4848
$address->setEventDispatcher($events = Mockery::mock('Illuminate\Events\Dispatcher'));
4949
$events->shouldReceive('until')->once()->with('eloquent.saving: ' . get_class($address), $address)->andReturn(true);
@@ -59,10 +59,10 @@ public function testEmbedsManySave()
5959
$this->assertEquals(2, count($user->addresses()->get()));
6060
$this->assertEquals(2, $user->addresses->count());
6161
$this->assertEquals(2, $user->addresses()->count());
62-
$this->assertEquals(['London', 'New York'], $user->addresses->lists('city')->all());
62+
$this->assertEquals(['London', 'New York'], $user->addresses->pluck('city')->all());
6363

6464
$freshUser = User::find($user->_id);
65-
$this->assertEquals(['London', 'New York'], $freshUser->addresses->lists('city')->all());
65+
$this->assertEquals(['London', 'New York'], $freshUser->addresses->pluck('city')->all());
6666

6767
$address = $user->addresses->first();
6868
$this->assertEquals('London', $address->city);
@@ -73,15 +73,15 @@ public function testEmbedsManySave()
7373

7474
$user = User::find($user->_id);
7575
$user->addresses()->save(new Address(['city' => 'Bruxelles']));
76-
$this->assertEquals(['London', 'New York', 'Bruxelles'], $user->addresses->lists('city')->all());
76+
$this->assertEquals(['London', 'New York', 'Bruxelles'], $user->addresses->pluck('city')->all());
7777

7878
$address = $user->addresses[1];
7979
$address->city = "Manhattan";
8080
$user->addresses()->save($address);
81-
$this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $user->addresses->lists('city')->all());
81+
$this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $user->addresses->pluck('city')->all());
8282

8383
$freshUser = User::find($user->_id);
84-
$this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $freshUser->addresses->lists('city')->all());
84+
$this->assertEquals(['London', 'Manhattan', 'Bruxelles'], $freshUser->addresses->pluck('city')->all());
8585
}
8686

8787
// public function testEmbedsManySaveModel()
@@ -123,28 +123,28 @@ public function testEmbedsManyAssociate()
123123
$address = new Address(['city' => 'London']);
124124

125125
$user->addresses()->associate($address);
126-
$this->assertEquals(['London'], $user->addresses->lists('city')->all());
126+
$this->assertEquals(['London'], $user->addresses->pluck('city')->all());
127127
$this->assertNotNull($address->_id);
128128

129129
$freshUser = User::find($user->_id);
130-
$this->assertEquals([], $freshUser->addresses->lists('city')->all());
130+
$this->assertEquals([], $freshUser->addresses->pluck('city')->all());
131131

132132
$address->city = 'Londinium';
133133
$user->addresses()->associate($address);
134-
$this->assertEquals(['Londinium'], $user->addresses->lists('city')->all());
134+
$this->assertEquals(['Londinium'], $user->addresses->pluck('city')->all());
135135

136136
$freshUser = User::find($user->_id);
137-
$this->assertEquals([], $freshUser->addresses->lists('city')->all());
137+
$this->assertEquals([], $freshUser->addresses->pluck('city')->all());
138138
}
139139

140140
public function testEmbedsManySaveMany()
141141
{
142142
$user = User::create(['name' => 'John Doe']);
143143
$user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol'])]);
144-
$this->assertEquals(['London', 'Bristol'], $user->addresses->lists('city')->all());
144+
$this->assertEquals(['London', 'Bristol'], $user->addresses->pluck('city')->all());
145145

146146
$freshUser = User::find($user->id);
147-
$this->assertEquals(['London', 'Bristol'], $freshUser->addresses->lists('city')->all());
147+
$this->assertEquals(['London', 'Bristol'], $freshUser->addresses->pluck('city')->all());
148148
}
149149

150150
public function testEmbedsManyDuplicate()
@@ -154,19 +154,19 @@ public function testEmbedsManyDuplicate()
154154
$user->addresses()->save($address);
155155
$user->addresses()->save($address);
156156
$this->assertEquals(1, $user->addresses->count());
157-
$this->assertEquals(['London'], $user->addresses->lists('city')->all());
157+
$this->assertEquals(['London'], $user->addresses->pluck('city')->all());
158158

159159
$user = User::find($user->id);
160160
$this->assertEquals(1, $user->addresses->count());
161161

162162
$address->city = 'Paris';
163163
$user->addresses()->save($address);
164164
$this->assertEquals(1, $user->addresses->count());
165-
$this->assertEquals(['Paris'], $user->addresses->lists('city')->all());
165+
$this->assertEquals(['Paris'], $user->addresses->pluck('city')->all());
166166

167167
$user->addresses()->create(['_id' => $address->_id, 'city' => 'Bruxelles']);
168168
$this->assertEquals(1, $user->addresses->count());
169-
$this->assertEquals(['Bruxelles'], $user->addresses->lists('city')->all());
169+
$this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all());
170170
}
171171

172172
public function testEmbedsManyCreate()
@@ -175,13 +175,13 @@ public function testEmbedsManyCreate()
175175
$address = $user->addresses()->create(['city' => 'Bruxelles']);
176176
$this->assertInstanceOf('Address', $address);
177177
$this->assertTrue(is_string($address->_id));
178-
$this->assertEquals(['Bruxelles'], $user->addresses->lists('city')->all());
178+
$this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all());
179179

180180
$raw = $address->getAttributes();
181181
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
182182

183183
$freshUser = User::find($user->id);
184-
$this->assertEquals(['Bruxelles'], $freshUser->addresses->lists('city')->all());
184+
$this->assertEquals(['Bruxelles'], $freshUser->addresses->pluck('city')->all());
185185

186186
$user = User::create([]);
187187
$address = $user->addresses()->create(['_id' => '', 'city' => 'Bruxelles']);
@@ -197,10 +197,10 @@ public function testEmbedsManyCreateMany()
197197
list($bruxelles, $paris) = $user->addresses()->createMany([['city' => 'Bruxelles'], ['city' => 'Paris']]);
198198
$this->assertInstanceOf('Address', $bruxelles);
199199
$this->assertEquals('Bruxelles', $bruxelles->city);
200-
$this->assertEquals(['Bruxelles', 'Paris'], $user->addresses->lists('city')->all());
200+
$this->assertEquals(['Bruxelles', 'Paris'], $user->addresses->pluck('city')->all());
201201

202202
$freshUser = User::find($user->id);
203-
$this->assertEquals(['Bruxelles', 'Paris'], $freshUser->addresses->lists('city')->all());
203+
$this->assertEquals(['Bruxelles', 'Paris'], $freshUser->addresses->pluck('city')->all());
204204
}
205205

206206
public function testEmbedsManyDestroy()
@@ -215,30 +215,30 @@ public function testEmbedsManyDestroy()
215215
$events->shouldReceive('fire')->once()->with('eloquent.deleted: ' . get_class($address), Mockery::type('Address'));
216216

217217
$user->addresses()->destroy($address->_id);
218-
$this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->lists('city')->all());
218+
$this->assertEquals(['Bristol', 'Bruxelles'], $user->addresses->pluck('city')->all());
219219

220220
$address->unsetEventDispatcher();
221221

222222
$address = $user->addresses->first();
223223
$user->addresses()->destroy($address);
224-
$this->assertEquals(['Bruxelles'], $user->addresses->lists('city')->all());
224+
$this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all());
225225

226226
$user->addresses()->create(['city' => 'Paris']);
227227
$user->addresses()->create(['city' => 'San Francisco']);
228228

229229
$freshUser = User::find($user->id);
230-
$this->assertEquals(['Bruxelles', 'Paris', 'San Francisco'], $freshUser->addresses->lists('city')->all());
230+
$this->assertEquals(['Bruxelles', 'Paris', 'San Francisco'], $freshUser->addresses->pluck('city')->all());
231231

232-
$ids = $user->addresses->lists('_id');
232+
$ids = $user->addresses->pluck('_id');
233233
$user->addresses()->destroy($ids);
234-
$this->assertEquals([], $user->addresses->lists('city')->all());
234+
$this->assertEquals([], $user->addresses->pluck('city')->all());
235235

236236
$freshUser = User::find($user->id);
237-
$this->assertEquals([], $freshUser->addresses->lists('city')->all());
237+
$this->assertEquals([], $freshUser->addresses->pluck('city')->all());
238238

239239
list($london, $bristol, $bruxelles) = $user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol']), new Address(['city' => 'Bruxelles'])]);
240240
$user->addresses()->destroy([$london, $bruxelles]);
241-
$this->assertEquals(['Bristol'], $user->addresses->lists('city')->all());
241+
$this->assertEquals(['Bristol'], $user->addresses->pluck('city')->all());
242242
}
243243

244244
public function testEmbedsManyDelete()
@@ -285,10 +285,10 @@ public function testEmbedsManyAliases()
285285
$address = new Address(['city' => 'London']);
286286

287287
$address = $user->addresses()->attach($address);
288-
$this->assertEquals(['London'], $user->addresses->lists('city')->all());
288+
$this->assertEquals(['London'], $user->addresses->pluck('city')->all());
289289

290290
$user->addresses()->detach($address);
291-
$this->assertEquals([], $user->addresses->lists('city')->all());
291+
$this->assertEquals([], $user->addresses->pluck('city')->all());
292292
}
293293

294294
public function testEmbedsManyCreatingEventReturnsFalse()
@@ -344,7 +344,7 @@ public function testEmbedsManyDeletingEventReturnsFalse()
344344
$events->shouldReceive('until')->once()->with('eloquent.deleting: ' . get_class($address), Mockery::mustBe($address))->andReturn(false);
345345

346346
$this->assertEquals(0, $user->addresses()->destroy($address));
347-
$this->assertEquals(['New York'], $user->addresses->lists('city')->all());
347+
$this->assertEquals(['New York'], $user->addresses->pluck('city')->all());
348348

349349
$address->unsetEventDispatcher();
350350
}
@@ -421,11 +421,11 @@ public function testEmbedsManyCollectionMethods()
421421
$user->addresses()->save(new Address(['city' => 'Brussels', 'country' => 'Belgium', 'visited' => 2, 'created_at' => new DateTime('4 days ago')]));
422422
$user->addresses()->save(new Address(['city' => 'Ghent', 'country' => 'Belgium', 'visited' => 13, 'created_at' => new DateTime('2 days ago')]));
423423

424-
$this->assertEquals(['Paris', 'Bruges', 'Brussels', 'Ghent'], $user->addresses()->lists('city')->all());
425-
$this->assertEquals(['Bruges', 'Brussels', 'Ghent', 'Paris'], $user->addresses()->sortBy('city')->lists('city')->all());
426-
$this->assertEquals([], $user->addresses()->where('city', 'New York')->lists('city')->all());
427-
$this->assertEquals(['Bruges', 'Brussels', 'Ghent'], $user->addresses()->where('country', 'Belgium')->lists('city')->all());
428-
$this->assertEquals(['Bruges', 'Brussels', 'Ghent'], $user->addresses()->where('country', 'Belgium')->sortBy('city')->lists('city')->all());
424+
$this->assertEquals(['Paris', 'Bruges', 'Brussels', 'Ghent'], $user->addresses()->pluck('city')->all());
425+
$this->assertEquals(['Bruges', 'Brussels', 'Ghent', 'Paris'], $user->addresses()->sortBy('city')->pluck('city')->all());
426+
$this->assertEquals([], $user->addresses()->where('city', 'New York')->pluck('city')->all());
427+
$this->assertEquals(['Bruges', 'Brussels', 'Ghent'], $user->addresses()->where('country', 'Belgium')->pluck('city')->all());
428+
$this->assertEquals(['Bruges', 'Brussels', 'Ghent'], $user->addresses()->where('country', 'Belgium')->sortBy('city')->pluck('city')->all());
429429

430430
$results = $user->addresses->first();
431431
$this->assertInstanceOf('Address', $results);

tests/ModelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public function testAll()
156156
$all = User::all();
157157

158158
$this->assertEquals(2, count($all));
159-
$this->assertContains('John Doe', $all->lists('name'));
160-
$this->assertContains('Jane Doe', $all->lists('name'));
159+
$this->assertContains('John Doe', $all->pluck('name'));
160+
$this->assertContains('Jane Doe', $all->pluck('name'));
161161
}
162162

163163
public function testFind()

tests/QueryBuilderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testGet()
2929

3030
public function testNoDocument()
3131
{
32-
$items = DB::collection('items')->where('name', 'nothing')->get();
32+
$items = DB::collection('items')->where('name', 'nothing')->get()->toArray();
3333
$this->assertEquals([], $items);
3434

3535
$item = DB::collection('items')->where('name', 'nothing')->first();
@@ -288,12 +288,12 @@ public function testDistinct()
288288
['name' => 'spoon', 'type' => 'round'],
289289
]);
290290

291-
$items = DB::collection('items')->distinct('name')->get();
291+
$items = DB::collection('items')->distinct('name')->get()->toArray();
292292
sort($items);
293293
$this->assertEquals(3, count($items));
294294
$this->assertEquals(['fork', 'knife', 'spoon'], $items);
295295

296-
$types = DB::collection('items')->distinct('type')->get();
296+
$types = DB::collection('items')->distinct('type')->get()->toArray();
297297
sort($types);
298298
$this->assertEquals(2, count($types));
299299
$this->assertEquals(['round', 'sharp'], $types);
@@ -357,7 +357,7 @@ public function testPluck()
357357
['name' => 'John Doe', 'age' => 25],
358358
]);
359359

360-
$age = DB::collection('users')->where('name', 'John Doe')->pluck('age');
360+
$age = DB::collection('users')->where('name', 'John Doe')->pluck('age')->toArray();
361361
$this->assertEquals([25], $age);
362362
}
363363

@@ -370,16 +370,16 @@ public function testList()
370370
['name' => 'spoon', 'type' => 'round', 'amount' => 14],
371371
]);
372372

373-
$list = DB::collection('items')->lists('name');
373+
$list = DB::collection('items')->pluck('name')->toArray();
374374
sort($list);
375375
$this->assertEquals(4, count($list));
376376
$this->assertEquals(['fork', 'knife', 'spoon', 'spoon'], $list);
377377

378-
$list = DB::collection('items')->lists('type', 'name');
378+
$list = DB::collection('items')->pluck('type', 'name')->toArray();
379379
$this->assertEquals(3, count($list));
380380
$this->assertEquals(['knife' => 'sharp', 'fork' => 'sharp', 'spoon' => 'round'], $list);
381381

382-
$list = DB::collection('items')->lists('name', '_id');
382+
$list = DB::collection('items')->pluck('name', '_id')->toArray();
383383
$this->assertEquals(4, count($list));
384384
$this->assertEquals(24, strlen(key($list)));
385385
}

0 commit comments

Comments
 (0)