Skip to content

Commit 675bb86

Browse files
committed
Fixed issue #42 and tweaked tests
1 parent 1e53349 commit 675bb86

11 files changed

+45
-29
lines changed

Diff for: .travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ branches:
44
only:
55
- master
66

7-
php:
7+
php:
88
- 5.3
99
- 5.4
1010
- 5.5
@@ -16,4 +16,4 @@ before_script:
1616
- composer self-update
1717
- composer install --dev --no-interaction
1818

19-
script: phpunit tests
19+
script: phpunit

Diff for: phpunit.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Laravel MongoDB Test Suite">
15+
<directory>tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

Diff for: src/Jenssegers/Mongodb/Builder.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function getFresh($columns = array('*'))
8989
}
9090
else
9191
{
92-
// If we don't use grouping, set the _id to null to prepare the pipeline for
92+
// If we don't use grouping, set the _id to null to prepare the pipeline for
9393
// other aggregation functions
9494
$group['_id'] = null;
9595
}
@@ -149,7 +149,7 @@ public function getFresh($columns = array('*'))
149149
$column = isset($this->columns[0]) ? $this->columns[0] : '_id';
150150
return $this->collection->distinct($column, $wheres);
151151
}
152-
152+
153153
// Normal query
154154
else
155155
{
@@ -282,7 +282,7 @@ public function insert(array $values)
282282
{
283283
// As soon as we find a value that is not an array we assume the user is
284284
// inserting a single document.
285-
if (!is_array($value))
285+
if (!is_array($value))
286286
{
287287
$batch = false; break;
288288
}
@@ -546,7 +546,7 @@ protected function performUpdate($query, array $options = array())
546546

547547
/**
548548
* Convert a key to MongoID if needed.
549-
*
549+
*
550550
* @param mixed $id
551551
* @return mixed
552552
*/
@@ -572,7 +572,7 @@ protected function compileWheres()
572572
// The new list of compiled wheres
573573
$wheres = array();
574574

575-
foreach ($this->wheres as $i => &$where)
575+
foreach ($this->wheres as $i => &$where)
576576
{
577577
// Convert id's
578578
if (isset($where['column']) && $where['column'] == '_id')
@@ -586,7 +586,7 @@ protected function compileWheres()
586586
}
587587
}
588588
// Single value
589-
else
589+
elseif (isset($where['value']))
590590
{
591591
$where['value'] = $this->convertKey($where['value']);
592592
}
@@ -715,4 +715,4 @@ public function __call($method, $parameters)
715715
return parent::__call($method, $parameters);
716716
}
717717

718-
}
718+
}

Diff for: tests/CacheTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
32

43
use Illuminate\Support\Facades\DB;
54

@@ -38,4 +37,4 @@ public function testCache()
3837
$this->assertEquals(3, count($users));
3938
}
4039

41-
}
40+
}

Diff for: tests/ConnectionTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
3-
42
use Illuminate\Support\Facades\DB;
53
use Jenssegers\Mongodb\Connection;
64

@@ -63,4 +61,4 @@ public function testMultipleConnections()
6361
$this->assertEquals(1, count($hosts));
6462
}
6563

66-
}
64+
}

Diff for: tests/ModelTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
32

43
class ModelTest extends PHPUnit_Framework_TestCase {
54

@@ -305,4 +304,4 @@ public function testUnset()
305304
$this->assertFalse(isset($user2->note2));
306305
}
307306

308-
}
307+
}

Diff for: tests/QueryBuilderTest.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
32

43
use Illuminate\Support\Facades\DB;
54

@@ -56,7 +55,7 @@ public function testInsert()
5655
$this->assertTrue(is_array($user['tags']));
5756
}
5857

59-
public function testInsertGetId()
58+
public function testInsertGetId()
6059
{
6160
$id = DB::collection('users')->insertGetId(array('name' => 'John Doe'));
6261

@@ -69,7 +68,7 @@ public function testBatchInsert()
6968
DB::collection('users')->insert(array(
7069
array(
7170
'tags' => array('tag1', 'tag2'),
72-
'name' => 'Jane Doe',
71+
'name' => 'Jane Doe',
7372
),
7473
array(
7574
'tags' => array('tag3'),
@@ -93,6 +92,12 @@ public function testFind()
9392
$this->assertEquals('John Doe', $user['name']);
9493
}
9594

95+
public function testFindNull()
96+
{
97+
$user = DB::collection('users')->find(null);
98+
$this->assertEquals(null, $user);
99+
}
100+
96101
public function testCount()
97102
{
98103
DB::collection('users')->insert(array(
@@ -201,14 +206,14 @@ public function testPush()
201206
));
202207

203208
DB::collection('users')->where('_id', $id)->push('tags', 'tag1');
204-
209+
205210
$user = DB::collection('users')->find($id);
206211
$this->assertTrue(is_array($user['tags']));
207212
$this->assertEquals(1, count($user['tags']));
208213
$this->assertEquals('tag1', $user['tags'][0]);
209214

210215
DB::collection('users')->where('_id', $id)->push('tags', 'tag2');
211-
216+
212217
$user = DB::collection('users')->find($id);
213218
$this->assertTrue(is_array($user['tags']));
214219
$this->assertEquals(2, count($user['tags']));
@@ -233,7 +238,7 @@ public function testPull()
233238
));
234239

235240
DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');
236-
241+
237242
$user = DB::collection('users')->find($id);
238243
$this->assertTrue(is_array($user['tags']));
239244
$this->assertEquals(3, count($user['tags']));
@@ -408,4 +413,4 @@ public function testUnset()
408413
$this->assertFalse(isset($user2['note2']));
409414
}
410415

411-
}
416+
}

Diff for: tests/QueryTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
32

43
class QueryTest extends PHPUnit_Framework_TestCase {
54

@@ -242,4 +241,4 @@ public function testRaw()
242241
$this->assertEquals(6, count($users));
243242
}
244243

245-
}
244+
}

Diff for: tests/RelationsTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
32

43
class RelationsTest extends PHPUnit_Framework_TestCase {
54

@@ -103,4 +102,4 @@ public function testWithHasOne()
103102
$this->assertEquals('admin', $role->type);
104103
}
105104

106-
}
105+
}

Diff for: tests/SchemaTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
require_once('tests/app.php');
32

43
use Illuminate\Support\Facades\DB;
54
use Illuminate\Support\Facades\Schema;
@@ -105,4 +104,4 @@ protected function getIndex($collection, $name)
105104
return false;
106105
}
107106

108-
}
107+
}

Diff for: tests/app.php renamed to tests/bootstrap.php

File renamed without changes.

0 commit comments

Comments
 (0)