Skip to content

Commit 72c6444

Browse files
committed
Merge master
2 parents e51ea71 + 11f0f83 commit 72c6444

18 files changed

+148
-118
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"illuminate/events": "4.2.x"
1717
},
1818
"require-dev": {
19-
"illuminate/cache": "4.2.x",
20-
"illuminate/auth": "4.2.x",
19+
"orchestra/testbench": "dev-master",
2120
"mockery/mockery": "*"
2221
},
2322
"autoload": {

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
<directory>tests/RelationsTest.php</directory>
4040
<directory>tests/MysqlRelationsTest.php</directory>
4141
</testsuite>
42+
<testsuite name="validation">
43+
<directory>tests/ValidationTest.php</directory>
44+
</testsuite>
4245
</testsuites>
4346
</phpunit>

src/Jenssegers/Mongodb/Auth/DatabaseReminderRepository.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class DatabaseReminderRepository extends \Illuminate\Auth\Reminders\DatabaseRemi
1010
*/
1111
protected function reminderExpired($reminder)
1212
{
13-
// Convert to object so that we can pass it to the parent method
14-
if (is_array($reminder))
13+
// Convert to array so that we can pass it to the parent method
14+
if (is_object($reminder))
1515
{
16-
$reminder = (object) $reminder;
16+
$reminder = (array) $reminder;
1717
}
1818

1919
// Convert the DateTime object that got saved to MongoDB
20-
if (is_array($reminder->created_at))
20+
if (is_array($reminder['created_at']))
2121
{
22-
$reminder->created_at = $reminder->created_at['date'] + $reminder->created_at['timezone'];
22+
$reminder['created_at'] = $reminder['created_at']['date'] + $reminder['created_at']['timezone'];
2323
}
2424

2525
return parent::reminderExpired($reminder);

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ protected function toCollection(array $results = array())
487487

488488
// Attatch the parent relation to the embedded model.
489489
$model->setRelation($this->foreignKey, $this->parent);
490+
$model->setHidden(array_merge($model->getHidden(), array($this->foreignKey)));
490491

491492
$models[] = $model;
492493
}

tests/CacheTest.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
<?php
22

3-
use Illuminate\Support\Facades\DB;
4-
5-
class CacheTest extends PHPUnit_Framework_TestCase {
6-
7-
protected $cache;
8-
9-
public function setUp()
10-
{
11-
global $app;
12-
$this->cache = $app['cache'];
13-
14-
User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
15-
User::create(array('name' => 'Jane Doe', 'age' => 33, 'title' => 'admin'));
16-
User::create(array('name' => 'Harry Hoe', 'age' => 13, 'title' => 'user'));
17-
}
3+
class CacheTest extends TestCase {
184

195
public function tearDown()
206
{
217
User::truncate();
22-
$this->cache->forget('db.users');
8+
Cache::forget('db.users');
239
}
2410

2511
public function testCache()
2612
{
13+
User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
14+
User::create(array('name' => 'Jane Doe', 'age' => 33, 'title' => 'admin'));
15+
User::create(array('name' => 'Harry Hoe', 'age' => 13, 'title' => 'user'));
16+
2717
$users = DB::collection('users')->where('age', '>', 10)->remember(10)->get();
2818
$this->assertEquals(3, count($users));
2919

@@ -33,7 +23,7 @@ public function testCache()
3323
$users = User::where('age', '>', 10)->remember(10, 'db.users')->get();
3424
$this->assertEquals(3, count($users));
3525

36-
$users = $this->cache->get('db.users');
26+
$users = Cache::get('db.users');
3727
$this->assertEquals(3, count($users));
3828
}
3929

tests/ConnectionTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<?php
2-
use Illuminate\Support\Facades\DB;
3-
use Jenssegers\Mongodb\Connection;
42

5-
class ConnectionTest extends PHPUnit_Framework_TestCase {
6-
7-
public function setUp() {}
8-
9-
public function tearDown() {}
3+
class ConnectionTest extends TestCase {
104

115
public function testConnection()
126
{
@@ -15,11 +9,11 @@ public function testConnection()
159

1610
$c1 = DB::connection('mongodb');
1711
$c2 = DB::connection('mongodb');
18-
$this->assertEquals($c1, $c2);
12+
$this->assertEquals(spl_object_hash($c1), spl_object_hash($c2));
1913

2014
$c1 = DB::connection('mongodb');
2115
$c2 = DB::reconnect('mongodb');
22-
$this->assertNotEquals($c1, $c2);
16+
$this->assertNotEquals(spl_object_hash($c1), spl_object_hash($c2));
2317
}
2418

2519
public function testDb()

tests/ModelTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22

3-
class ModelTest extends PHPUnit_Framework_TestCase {
4-
5-
public function setUp() {}
3+
class ModelTest extends TestCase {
64

75
public function tearDown()
86
{

tests/MysqlRelationsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3-
class MysqlRelationsTest extends PHPUnit_Framework_TestCase {
3+
class MysqlRelationsTest extends TestCase {
44

55
public function setUp()
66
{
7+
parent::setUp();
8+
79
MysqlUser::executeSchema();
810
MysqlBook::executeSchema();
911
MysqlRole::executeSchema();

tests/QueryBuilderTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
22

3-
use Illuminate\Support\Facades\DB;
4-
5-
class QueryBuilderTest extends PHPUnit_Framework_TestCase {
6-
7-
public function setUp() {}
3+
class QueryBuilderTest extends TestCase {
84

95
public function tearDown()
106
{
@@ -238,17 +234,25 @@ public function testPush()
238234
DB::collection('users')->where('_id', $id)->push('messages', $message);
239235
$user = DB::collection('users')->find($id);
240236
$this->assertTrue(is_array($user['messages']));
237+
$this->assertEquals(1, count($user['messages']));
241238
$this->assertEquals($message, $user['messages'][0]);
239+
240+
// Raw
241+
DB::collection('users')->where('_id', $id)->push(array('tags' => 'tag3', 'messages' => array('from' => 'Mark', 'body' => 'Hi John')));
242+
$user = DB::collection('users')->find($id);
243+
$this->assertEquals(4, count($user['tags']));
244+
$this->assertEquals(2, count($user['messages']));
242245
}
243246

244247
public function testPull()
245248
{
246-
$message = array('from' => 'Jane', 'body' => 'Hi John');
249+
$message1 = array('from' => 'Jane', 'body' => 'Hi John');
250+
$message2 = array('from' => 'Mark', 'body' => 'Hi John');
247251

248252
$id = DB::collection('users')->insertGetId(array(
249253
'name' => 'John Doe',
250254
'tags' => array('tag1', 'tag2', 'tag3', 'tag4'),
251-
'messages' => array($message)
255+
'messages' => array($message1, $message2)
252256
));
253257

254258
DB::collection('users')->where('_id', $id)->pull('tags', 'tag3');
@@ -258,10 +262,16 @@ public function testPull()
258262
$this->assertEquals(3, count($user['tags']));
259263
$this->assertEquals('tag4', $user['tags'][2]);
260264

261-
DB::collection('users')->where('_id', $id)->pull('messages', $message);
265+
DB::collection('users')->where('_id', $id)->pull('messages', $message1);
262266

263267
$user = DB::collection('users')->find($id);
264268
$this->assertTrue(is_array($user['messages']));
269+
$this->assertEquals(1, count($user['messages']));
270+
271+
// Raw
272+
DB::collection('users')->where('_id', $id)->pull(array('tags' => 'tag2', 'messages' => $message2));
273+
$user = DB::collection('users')->find($id);
274+
$this->assertEquals(2, count($user['tags']));
265275
$this->assertEquals(0, count($user['messages']));
266276
}
267277

tests/QueryTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

3-
class QueryTest extends PHPUnit_Framework_TestCase {
3+
class QueryTest extends TestCase {
44

55
protected static $started = false;
66

77
public function setUp()
88
{
9+
parent::setUp();
10+
11+
// only run this stuff once
912
if (self::$started) return;
1013

1114
User::create(array('name' => 'John Doe', 'age' => 35, 'title' => 'admin'));
@@ -188,8 +191,14 @@ public function testGroupBy()
188191
$this->assertEquals(33, $users[2]->age);
189192

190193
$users = User::groupBy('age')->skip(1)->take(2)->orderBy('age', 'desc')->get();
194+
$this->assertEquals(2, count($users));
191195
$this->assertEquals(35, $users[0]->age);
192196
$this->assertEquals(33, $users[1]->age);
197+
$this->assertNull($users[0]->name);
198+
199+
$users = User::select('name')->groupBy('age')->skip(1)->take(2)->orderBy('age', 'desc')->get();
200+
$this->assertEquals(2, count($users));
201+
$this->assertNotNull($users[0]->name);
193202
}
194203

195204
public function testCount()

0 commit comments

Comments
 (0)