Skip to content

Commit c49f601

Browse files
committed
PHPORM-216 Remove $collection setting from DocumentModel and Connection::collection(). Use $table and Connection::table() instead
1 parent a453f8a commit c49f601

File tree

5 files changed

+37
-89
lines changed

5 files changed

+37
-89
lines changed

src/Connection.php

-18
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
use function is_array;
2323
use function preg_match;
2424
use function str_contains;
25-
use function trigger_error;
2625

27-
use const E_USER_DEPRECATED;
2826
use const FILTER_FLAG_IPV6;
2927
use const FILTER_VALIDATE_IP;
3028

@@ -77,22 +75,6 @@ public function __construct(array $config)
7775
$this->useDefaultQueryGrammar();
7876
}
7977

80-
/**
81-
* Begin a fluent query against a database collection.
82-
*
83-
* @deprecated since mongodb/laravel-mongodb 4.8, use the function table() instead
84-
*
85-
* @param string $collection
86-
*
87-
* @return Query\Builder
88-
*/
89-
public function collection($collection)
90-
{
91-
@trigger_error('Since mongodb/laravel-mongodb 4.8, the method Connection::collection() is deprecated and will be removed in version 5.0. Use the table() method instead.', E_USER_DEPRECATED);
92-
93-
return $this->table($collection);
94-
}
95-
9678
/**
9779
* Begin a fluent query against a database collection.
9880
*

src/Eloquent/DocumentModel.php

-15
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@
4747
use function str_starts_with;
4848
use function strcmp;
4949
use function strlen;
50-
use function trigger_error;
5150
use function var_export;
5251

53-
use const E_USER_DEPRECATED;
54-
5552
trait DocumentModel
5653
{
5754
use HybridRelations;
@@ -140,18 +137,6 @@ public function freshTimestamp()
140137
return new UTCDateTime(Date::now());
141138
}
142139

143-
/** @inheritdoc */
144-
public function getTable()
145-
{
146-
if (isset($this->collection)) {
147-
trigger_error('Since mongodb/laravel-mongodb 4.8: Using "$collection" property is deprecated. Use "$table" instead.', E_USER_DEPRECATED);
148-
149-
return $this->collection;
150-
}
151-
152-
return parent::getTable();
153-
}
154-
155140
/** @inheritdoc */
156141
public function getAttribute($key)
157142
{

src/Schema/Builder.php

-19
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
use function iterator_to_array;
1818
use function sort;
1919
use function sprintf;
20-
use function trigger_error;
2120
use function usort;
2221

23-
use const E_USER_DEPRECATED;
24-
2522
class Builder extends \Illuminate\Database\Schema\Builder
2623
{
2724
/**
@@ -75,22 +72,6 @@ public function hasTable($table)
7572
return $this->hasCollection($table);
7673
}
7774

78-
/**
79-
* Modify a collection on the schema.
80-
*
81-
* @deprecated since mongodb/laravel-mongodb 4.8, use the function table() instead
82-
*
83-
* @param string $collection
84-
*
85-
* @return void
86-
*/
87-
public function collection($collection, Closure $callback)
88-
{
89-
@trigger_error('Since mongodb/laravel-mongodb 4.8, the method Schema\Builder::collection() is deprecated and will be removed in version 5.0. Use the function table() instead.', E_USER_DEPRECATED);
90-
91-
$this->table($collection, $callback);
92-
}
93-
9475
/** @inheritdoc */
9576
public function table($table, Closure $callback)
9677
{

tests/QueryBuilderTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1055,14 +1055,14 @@ public function testIncrementEach()
10551055
#[TestWith(['_id', 'id'])]
10561056
public function testIdAlias($insertId, $queryId): void
10571057
{
1058-
DB::collection('items')->insert([$insertId => 'abc', 'name' => 'Karting']);
1059-
$item = DB::collection('items')->where($queryId, '=', 'abc')->first();
1058+
DB::table('items')->insert([$insertId => 'abc', 'name' => 'Karting']);
1059+
$item = DB::table('items')->where($queryId, '=', 'abc')->first();
10601060
$this->assertNotNull($item);
10611061
$this->assertSame('abc', $item['id']);
10621062
$this->assertSame('Karting', $item['name']);
10631063

1064-
DB::collection('items')->where($insertId, '=', 'abc')->update(['name' => 'Bike']);
1065-
$item = DB::collection('items')->where($queryId, '=', 'abc')->first();
1064+
DB::table('items')->where($insertId, '=', 'abc')->update(['name' => 'Bike']);
1065+
$item = DB::table('items')->where($queryId, '=', 'abc')->first();
10661066
$this->assertSame('Bike', $item['name']);
10671067
}
10681068
}

tests/SchemaTest.php

+33-33
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testBluePrint(): void
6161
{
6262
$instance = $this;
6363

64-
Schema::collection('newcollection', function ($collection) use ($instance) {
64+
Schema::table('newcollection', function ($collection) use ($instance) {
6565
$instance->assertInstanceOf(Blueprint::class, $collection);
6666
});
6767

@@ -72,21 +72,21 @@ public function testBluePrint(): void
7272

7373
public function testIndex(): void
7474
{
75-
Schema::collection('newcollection', function ($collection) {
75+
Schema::table('newcollection', function ($collection) {
7676
$collection->index('mykey1');
7777
});
7878

7979
$index = $this->getIndex('newcollection', 'mykey1');
8080
$this->assertEquals(1, $index['key']['mykey1']);
8181

82-
Schema::collection('newcollection', function ($collection) {
82+
Schema::table('newcollection', function ($collection) {
8383
$collection->index(['mykey2']);
8484
});
8585

8686
$index = $this->getIndex('newcollection', 'mykey2');
8787
$this->assertEquals(1, $index['key']['mykey2']);
8888

89-
Schema::collection('newcollection', function ($collection) {
89+
Schema::table('newcollection', function ($collection) {
9090
$collection->string('mykey3')->index();
9191
});
9292

@@ -96,7 +96,7 @@ public function testIndex(): void
9696

9797
public function testPrimary(): void
9898
{
99-
Schema::collection('newcollection', function ($collection) {
99+
Schema::table('newcollection', function ($collection) {
100100
$collection->string('mykey', 100)->primary();
101101
});
102102

@@ -106,7 +106,7 @@ public function testPrimary(): void
106106

107107
public function testUnique(): void
108108
{
109-
Schema::collection('newcollection', function ($collection) {
109+
Schema::table('newcollection', function ($collection) {
110110
$collection->unique('uniquekey');
111111
});
112112

@@ -116,58 +116,58 @@ public function testUnique(): void
116116

117117
public function testDropIndex(): void
118118
{
119-
Schema::collection('newcollection', function ($collection) {
119+
Schema::table('newcollection', function ($collection) {
120120
$collection->unique('uniquekey');
121121
$collection->dropIndex('uniquekey_1');
122122
});
123123

124124
$index = $this->getIndex('newcollection', 'uniquekey');
125125
$this->assertEquals(null, $index);
126126

127-
Schema::collection('newcollection', function ($collection) {
127+
Schema::table('newcollection', function ($collection) {
128128
$collection->unique('uniquekey');
129129
$collection->dropIndex(['uniquekey']);
130130
});
131131

132132
$index = $this->getIndex('newcollection', 'uniquekey');
133133
$this->assertEquals(null, $index);
134134

135-
Schema::collection('newcollection', function ($collection) {
135+
Schema::table('newcollection', function ($collection) {
136136
$collection->index(['field_a', 'field_b']);
137137
});
138138

139139
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
140140
$this->assertNotNull($index);
141141

142-
Schema::collection('newcollection', function ($collection) {
142+
Schema::table('newcollection', function ($collection) {
143143
$collection->dropIndex(['field_a', 'field_b']);
144144
});
145145

146146
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
147147
$this->assertFalse($index);
148148

149-
Schema::collection('newcollection', function ($collection) {
149+
Schema::table('newcollection', function ($collection) {
150150
$collection->index(['field_a' => -1, 'field_b' => 1]);
151151
});
152152

153153
$index = $this->getIndex('newcollection', 'field_a_-1_field_b_1');
154154
$this->assertNotNull($index);
155155

156-
Schema::collection('newcollection', function ($collection) {
156+
Schema::table('newcollection', function ($collection) {
157157
$collection->dropIndex(['field_a' => -1, 'field_b' => 1]);
158158
});
159159

160160
$index = $this->getIndex('newcollection', 'field_a_-1_field_b_1');
161161
$this->assertFalse($index);
162162

163-
Schema::collection('newcollection', function ($collection) {
163+
Schema::table('newcollection', function ($collection) {
164164
$collection->index(['field_a', 'field_b'], 'custom_index_name');
165165
});
166166

167167
$index = $this->getIndex('newcollection', 'custom_index_name');
168168
$this->assertNotNull($index);
169169

170-
Schema::collection('newcollection', function ($collection) {
170+
Schema::table('newcollection', function ($collection) {
171171
$collection->dropIndex('custom_index_name');
172172
});
173173

@@ -177,44 +177,44 @@ public function testDropIndex(): void
177177

178178
public function testDropIndexIfExists(): void
179179
{
180-
Schema::collection('newcollection', function (Blueprint $collection) {
180+
Schema::table('newcollection', function (Blueprint $collection) {
181181
$collection->unique('uniquekey');
182182
$collection->dropIndexIfExists('uniquekey_1');
183183
});
184184

185185
$index = $this->getIndex('newcollection', 'uniquekey');
186186
$this->assertEquals(null, $index);
187187

188-
Schema::collection('newcollection', function (Blueprint $collection) {
188+
Schema::table('newcollection', function (Blueprint $collection) {
189189
$collection->unique('uniquekey');
190190
$collection->dropIndexIfExists(['uniquekey']);
191191
});
192192

193193
$index = $this->getIndex('newcollection', 'uniquekey');
194194
$this->assertEquals(null, $index);
195195

196-
Schema::collection('newcollection', function (Blueprint $collection) {
196+
Schema::table('newcollection', function (Blueprint $collection) {
197197
$collection->index(['field_a', 'field_b']);
198198
});
199199

200200
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
201201
$this->assertNotNull($index);
202202

203-
Schema::collection('newcollection', function (Blueprint $collection) {
203+
Schema::table('newcollection', function (Blueprint $collection) {
204204
$collection->dropIndexIfExists(['field_a', 'field_b']);
205205
});
206206

207207
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
208208
$this->assertFalse($index);
209209

210-
Schema::collection('newcollection', function (Blueprint $collection) {
210+
Schema::table('newcollection', function (Blueprint $collection) {
211211
$collection->index(['field_a', 'field_b'], 'custom_index_name');
212212
});
213213

214214
$index = $this->getIndex('newcollection', 'custom_index_name');
215215
$this->assertNotNull($index);
216216

217-
Schema::collection('newcollection', function (Blueprint $collection) {
217+
Schema::table('newcollection', function (Blueprint $collection) {
218218
$collection->dropIndexIfExists('custom_index_name');
219219
});
220220

@@ -226,19 +226,19 @@ public function testHasIndex(): void
226226
{
227227
$instance = $this;
228228

229-
Schema::collection('newcollection', function (Blueprint $collection) use ($instance) {
229+
Schema::table('newcollection', function (Blueprint $collection) use ($instance) {
230230
$collection->index('myhaskey1');
231231
$instance->assertTrue($collection->hasIndex('myhaskey1_1'));
232232
$instance->assertFalse($collection->hasIndex('myhaskey1'));
233233
});
234234

235-
Schema::collection('newcollection', function (Blueprint $collection) use ($instance) {
235+
Schema::table('newcollection', function (Blueprint $collection) use ($instance) {
236236
$collection->index('myhaskey2');
237237
$instance->assertTrue($collection->hasIndex(['myhaskey2']));
238238
$instance->assertFalse($collection->hasIndex(['myhaskey2_1']));
239239
});
240240

241-
Schema::collection('newcollection', function (Blueprint $collection) use ($instance) {
241+
Schema::table('newcollection', function (Blueprint $collection) use ($instance) {
242242
$collection->index(['field_a', 'field_b']);
243243
$instance->assertTrue($collection->hasIndex(['field_a_1_field_b']));
244244
$instance->assertFalse($collection->hasIndex(['field_a_1_field_b_1']));
@@ -247,7 +247,7 @@ public function testHasIndex(): void
247247

248248
public function testBackground(): void
249249
{
250-
Schema::collection('newcollection', function ($collection) {
250+
Schema::table('newcollection', function ($collection) {
251251
$collection->background('backgroundkey');
252252
});
253253

@@ -257,7 +257,7 @@ public function testBackground(): void
257257

258258
public function testSparse(): void
259259
{
260-
Schema::collection('newcollection', function ($collection) {
260+
Schema::table('newcollection', function ($collection) {
261261
$collection->sparse('sparsekey');
262262
});
263263

@@ -267,7 +267,7 @@ public function testSparse(): void
267267

268268
public function testExpire(): void
269269
{
270-
Schema::collection('newcollection', function ($collection) {
270+
Schema::table('newcollection', function ($collection) {
271271
$collection->expire('expirekey', 60);
272272
});
273273

@@ -277,11 +277,11 @@ public function testExpire(): void
277277

278278
public function testSoftDeletes(): void
279279
{
280-
Schema::collection('newcollection', function ($collection) {
280+
Schema::table('newcollection', function ($collection) {
281281
$collection->softDeletes();
282282
});
283283

284-
Schema::collection('newcollection', function ($collection) {
284+
Schema::table('newcollection', function ($collection) {
285285
$collection->string('email')->nullable()->index();
286286
});
287287

@@ -291,7 +291,7 @@ public function testSoftDeletes(): void
291291

292292
public function testFluent(): void
293293
{
294-
Schema::collection('newcollection', function ($collection) {
294+
Schema::table('newcollection', function ($collection) {
295295
$collection->string('email')->index();
296296
$collection->string('token')->index();
297297
$collection->timestamp('created_at');
@@ -306,7 +306,7 @@ public function testFluent(): void
306306

307307
public function testGeospatial(): void
308308
{
309-
Schema::collection('newcollection', function ($collection) {
309+
Schema::table('newcollection', function ($collection) {
310310
$collection->geospatial('point');
311311
$collection->geospatial('area', '2d');
312312
$collection->geospatial('continent', '2dsphere');
@@ -324,7 +324,7 @@ public function testGeospatial(): void
324324

325325
public function testDummies(): void
326326
{
327-
Schema::collection('newcollection', function ($collection) {
327+
Schema::table('newcollection', function ($collection) {
328328
$collection->boolean('activated')->default(0);
329329
$collection->integer('user_id')->unsigned();
330330
});
@@ -333,7 +333,7 @@ public function testDummies(): void
333333

334334
public function testSparseUnique(): void
335335
{
336-
Schema::collection('newcollection', function ($collection) {
336+
Schema::table('newcollection', function ($collection) {
337337
$collection->sparse_and_unique('sparseuniquekey');
338338
});
339339

@@ -361,7 +361,7 @@ public function testRenameColumn(): void
361361
$this->assertArrayNotHasKey('test', $check[2]);
362362
$this->assertArrayNotHasKey('newtest', $check[2]);
363363

364-
Schema::collection('newcollection', function (Blueprint $collection) {
364+
Schema::table('newcollection', function (Blueprint $collection) {
365365
$collection->renameColumn('test', 'newtest');
366366
});
367367

0 commit comments

Comments
 (0)