Skip to content

Commit 8ea8b96

Browse files
committed
Merge pull request #144 from neoxia/master-test-robustness
Make test cases more robust by not using natural ordering
2 parents b23b59e + f9f8f37 commit 8ea8b96

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

tests/ModelTest.php

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

106106
$this->assertEquals(2, count($all));
107-
$this->assertEquals('John Doe', $all[0]->name);
108-
$this->assertEquals('Jane Doe', $all[1]->name);
107+
$this->assertContains('John Doe', $all->lists('name'));
108+
$this->assertContains('Jane Doe', $all->lists('name'));
109109
}
110110

111111
public function testFind()

tests/QueryBuilderTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ public function testTake()
312312
array('name' => 'spoon', 'type' => 'round', 'amount' => 14)
313313
));
314314

315-
$items = DB::collection('items')->take(2)->get();
315+
$items = DB::collection('items')->orderBy('name')->take(2)->get();
316316
$this->assertEquals(2, count($items));
317-
$this->assertEquals('knife', $items[0]['name']);
317+
$this->assertEquals('fork', $items[0]['name']);
318318
}
319319

320320
public function testSkip()
@@ -352,8 +352,9 @@ public function testList()
352352
));
353353

354354
$list = DB::collection('items')->lists('name');
355+
sort($list);
355356
$this->assertEquals(4, count($list));
356-
$this->assertEquals(array('knife', 'fork', 'spoon', 'spoon'), $list);
357+
$this->assertEquals(array('fork', 'knife', 'spoon', 'spoon'), $list);
357358

358359
$list = DB::collection('items')->lists('type', 'name');
359360
$this->assertEquals(3, count($list));

tests/QueryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ public function testLike()
7070

7171
public function testSelect()
7272
{
73-
$user = User::select('name')->first();
73+
$user = User::where('name', 'John Doe')->select('name')->first();
7474

7575
$this->assertEquals('John Doe', $user->name);
7676
$this->assertEquals(null, $user->age);
7777

78-
$user = User::select('name', 'title')->first();
78+
$user = User::where('name', 'John Doe')->select('name', 'title')->first();
7979

8080
$this->assertEquals('John Doe', $user->name);
8181
$this->assertEquals('admin', $user->title);
8282
$this->assertEquals(null, $user->age);
8383

84-
$user = User::get(array('name'))->first();
84+
$user = User::where('name', 'John Doe')->get(array('name'))->first();
8585

8686
$this->assertEquals('John Doe', $user->name);
8787
$this->assertEquals(null, $user->age);

0 commit comments

Comments
 (0)