Skip to content

Commit 13075c7

Browse files
author
Dennis Heller
committed
Merge remote-tracking branch 'original/master'
2 parents 9cb4d7a + f12f766 commit 13075c7

File tree

11 files changed

+209
-183
lines changed

11 files changed

+209
-183
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ composer require jenssegers/mongodb
4141
5.2.x | 2.3.x or 3.0.x
4242
5.3.x | 3.1.x or 3.2.x
4343
5.4.x | 3.2.x
44+
5.5.x | 3.3.x
4445

4546
And add the service provider in `config/app.php`:
4647

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function hint($index)
198198
*/
199199
public function find($id, $columns = [])
200200
{
201-
return $this->where('_id', '=', $this->convertKey($id))->first($columns);
201+
return $this->where($this->getKeyName(), '=', $this->convertKey($id))->first($columns);
202202
}
203203

204204
/**

src/Jenssegers/Mongodb/Queue/MongoQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function releaseJobsThatHaveBeenReservedTooLong($queue)
117117
})->get();
118118

119119
foreach ($reserved as $job) {
120-
$attempts = $job['attempts'] + 1;
120+
$attempts = $job['attempts'];
121121
$this->releaseJob($job['_id'], $attempts);
122122
}
123123
}

src/Jenssegers/Mongodb/Schema/Builder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,36 @@ public function dropAllTables()
114114
$this->connection->getMongoDB()->drop();
115115
}
116116

117+
/**
118+
* @inheritdoc
119+
*/
120+
public function dropAllTables()
121+
{
122+
foreach ($this->getAllCollections() as $collection) {
123+
$this->drop($collection);
124+
}
125+
}
126+
117127
/**
118128
* @inheritdoc
119129
*/
120130
protected function createBlueprint($collection, Closure $callback = null)
121131
{
122132
return new Blueprint($this->connection, $collection);
123133
}
134+
135+
/**
136+
* Get all of the collections names for the database.
137+
*
138+
* @return array
139+
*/
140+
protected function getAllCollections()
141+
{
142+
$collections = [];
143+
foreach ($this->connection->getMongoDB()->listCollections() as $collection) {
144+
$collections[] = $collection->getName();
145+
}
146+
147+
return $collections;
148+
}
124149
}

tests/ConnectionTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testCollection()
4444
// public function testDynamic()
4545
// {
4646
// $dbs = DB::connection('mongodb')->listCollections();
47-
// $this->assertTrue(is_array($dbs));
47+
// $this->assertInternalType('array', $dbs);
4848
// }
4949

5050
// public function testMultipleConnections()
@@ -59,29 +59,29 @@ public function testCollection()
5959
// $mongoclient = $connection->getMongoClient();
6060

6161
// $hosts = $mongoclient->getHosts();
62-
// $this->assertEquals(1, count($hosts));
62+
// $this->assertCount(1, $hosts);
6363
// }
6464

6565
public function testQueryLog()
6666
{
6767
DB::enableQueryLog();
6868

69-
$this->assertEquals(0, count(DB::getQueryLog()));
69+
$this->assertCount(0, DB::getQueryLog());
7070

7171
DB::collection('items')->get();
72-
$this->assertEquals(1, count(DB::getQueryLog()));
72+
$this->assertCount(1, DB::getQueryLog());
7373

7474
DB::collection('items')->insert(['name' => 'test']);
75-
$this->assertEquals(2, count(DB::getQueryLog()));
75+
$this->assertCount(2, DB::getQueryLog());
7676

7777
DB::collection('items')->count();
78-
$this->assertEquals(3, count(DB::getQueryLog()));
78+
$this->assertCount(3, DB::getQueryLog());
7979

8080
DB::collection('items')->where('name', 'test')->update(['name' => 'test']);
81-
$this->assertEquals(4, count(DB::getQueryLog()));
81+
$this->assertCount(4, DB::getQueryLog());
8282

8383
DB::collection('items')->where('name', 'test')->delete();
84-
$this->assertEquals(5, count(DB::getQueryLog()));
84+
$this->assertCount(5, DB::getQueryLog());
8585
}
8686

8787
public function testSchemaBuilder()

tests/EmbeddedRelationsTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testEmbedsManySave()
3636
$this->assertInstanceOf('DateTime', $address->created_at);
3737
$this->assertInstanceOf('DateTime', $address->updated_at);
3838
$this->assertNotNull($address->_id);
39-
$this->assertTrue(is_string($address->_id));
39+
$this->assertInternalType('string', $address->_id);
4040

4141
$raw = $address->getAttributes();
4242
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
@@ -57,8 +57,8 @@ public function testEmbedsManySave()
5757
$user->addresses()->save($address);
5858
$address->unsetEventDispatcher();
5959

60-
$this->assertEquals(2, count($user->addresses));
61-
$this->assertEquals(2, count($user->addresses()->get()));
60+
$this->assertCount(2, $user->addresses);
61+
$this->assertCount(2, $user->addresses()->get());
6262
$this->assertEquals(2, $user->addresses->count());
6363
$this->assertEquals(2, $user->addresses()->count());
6464
$this->assertEquals(['London', 'New York'], $user->addresses->pluck('city')->all());
@@ -115,8 +115,8 @@ public function testEmbedsToArray()
115115
$user->addresses()->saveMany([new Address(['city' => 'London']), new Address(['city' => 'Bristol'])]);
116116

117117
$array = $user->toArray();
118-
$this->assertFalse(array_key_exists('_addresses', $array));
119-
$this->assertTrue(array_key_exists('addresses', $array));
118+
$this->assertArrayNotHasKey('_addresses', $array);
119+
$this->assertArrayHasKey('addresses', $array);
120120
}
121121

122122
public function testEmbedsManyAssociate()
@@ -176,7 +176,7 @@ public function testEmbedsManyCreate()
176176
$user = User::create([]);
177177
$address = $user->addresses()->create(['city' => 'Bruxelles']);
178178
$this->assertInstanceOf('Address', $address);
179-
$this->assertTrue(is_string($address->_id));
179+
$this->assertInternalType('string', $address->_id);
180180
$this->assertEquals(['Bruxelles'], $user->addresses->pluck('city')->all());
181181

182182
$raw = $address->getAttributes();
@@ -187,7 +187,7 @@ public function testEmbedsManyCreate()
187187

188188
$user = User::create([]);
189189
$address = $user->addresses()->create(['_id' => '', 'city' => 'Bruxelles']);
190-
$this->assertTrue(is_string($address->_id));
190+
$this->assertInternalType('string', $address->_id);
191191

192192
$raw = $address->getAttributes();
193193
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
@@ -385,16 +385,16 @@ public function testEmbedsManyEagerLoading()
385385

386386
$user = User::find($user1->id);
387387
$relations = $user->getRelations();
388-
$this->assertFalse(array_key_exists('addresses', $relations));
388+
$this->assertArrayNotHasKey('addresses', $relations);
389389
$this->assertArrayHasKey('addresses', $user->toArray());
390-
$this->assertTrue(is_array($user->toArray()['addresses']));
390+
$this->assertInternalType('array', $user->toArray()['addresses']);
391391

392392
$user = User::with('addresses')->get()->first();
393393
$relations = $user->getRelations();
394-
$this->assertTrue(array_key_exists('addresses', $relations));
394+
$this->assertArrayHasKey('addresses', $relations);
395395
$this->assertEquals(2, $relations['addresses']->count());
396396
$this->assertArrayHasKey('addresses', $user->toArray());
397-
$this->assertTrue(is_array($user->toArray()['addresses']));
397+
$this->assertInternalType('array', $user->toArray()['addresses']);
398398
}
399399

400400
public function testEmbedsManyDeleteAll()
@@ -466,7 +466,7 @@ public function testEmbedsOne()
466466
$this->assertInstanceOf('DateTime', $father->created_at);
467467
$this->assertInstanceOf('DateTime', $father->updated_at);
468468
$this->assertNotNull($father->_id);
469-
$this->assertTrue(is_string($father->_id));
469+
$this->assertInternalType('string', $father->_id);
470470

471471
$raw = $father->getAttributes();
472472
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $raw['_id']);
@@ -541,7 +541,7 @@ public function testEmbedsManyToArray()
541541

542542
$array = $user->toArray();
543543
$this->assertArrayHasKey('addresses', $array);
544-
$this->assertTrue(is_array($array['addresses']));
544+
$this->assertInternalType('array', $array['addresses']);
545545
}
546546

547547
public function testEmbeddedSave()

tests/HybridRelationsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function testMysqlRelations()
2727
// Mysql User
2828
$user->name = "John Doe";
2929
$user->save();
30-
$this->assertTrue(is_int($user->id));
30+
$this->assertInternalType('int', $user->id);
3131

3232
// SQL has many
3333
$book = new Book(['title' => 'Game of Thrones']);
3434
$user->books()->save($book);
3535
$user = MysqlUser::find($user->id); // refetch
36-
$this->assertEquals(1, count($user->books));
36+
$this->assertCount(1, $user->books);
3737

3838
// MongoDB belongs to
3939
$book = $user->books()->first(); // refetch
@@ -58,7 +58,7 @@ public function testMysqlRelations()
5858
$book = new MysqlBook(['title' => 'Game of Thrones']);
5959
$user->mysqlBooks()->save($book);
6060
$user = User::find($user->_id); // refetch
61-
$this->assertEquals(1, count($user->mysqlBooks));
61+
$this->assertCount(1, $user->mysqlBooks);
6262

6363
// SQL belongs to
6464
$book = $user->mysqlBooks()->first(); // refetch
@@ -93,8 +93,8 @@ public function testHybridWhereHas()
9393
$otherUser->id = 3;
9494
$otherUser->save();
9595
// Make sure they are created
96-
$this->assertTrue(is_int($user->id));
97-
$this->assertTrue(is_int($otherUser->id));
96+
$this->assertInternalType('int', $user->id);
97+
$this->assertInternalType('int', $otherUser->id);
9898
// Clear to start
9999
$user->books()->truncate();
100100
$otherUser->books()->truncate();
@@ -147,8 +147,8 @@ public function testHybridWith()
147147
$otherUser->id = 3;
148148
$otherUser->save();
149149
// Make sure they are created
150-
$this->assertTrue(is_int($user->id));
151-
$this->assertTrue(is_int($otherUser->id));
150+
$this->assertInternalType('int', $user->id);
151+
$this->assertInternalType('int', $otherUser->id);
152152
// Clear to start
153153
Book::truncate();
154154
MysqlBook::truncate();

0 commit comments

Comments
 (0)