Skip to content

Commit a2edc86

Browse files
authored
Merge pull request #2130 from pendexgabo/backport-2127-3.6-tree
Backport of issue #2127 to tree 3.6
2 parents 32ff280 + 4de23e1 commit a2edc86

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ protected function compileWhereBasic(array $where)
10621062

10631063
if (!isset($operator) || $operator == '=') {
10641064
if ($is_numeric) {
1065-
$query = ['$where' => '/^'.$value->getPattern().'/.test(this.'.$column.')'];
1065+
$query = ['$where' => '/^'.$value->getPattern().'/.test(this["'.$column.'"])'];
10661066
} else {
10671067
$query = [$column => $value];
10681068
}

tests/QueryTest.php

+18-14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function setUp(): void
1616
User::create(['name' => 'Brett Boe', 'age' => 35, 'title' => 'user']);
1717
User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']);
1818
User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']);
19+
User::create(['name' => 'John Smith', 'user-age' => 28, 'title' => 'member']);
1920
User::create(['name' => 'Error', 'age' => null, 'title' => null]);
2021
}
2122

@@ -41,10 +42,10 @@ public function testWhere(): void
4142
$this->assertCount(1, $users);
4243

4344
$users = User::where('age', '!=', 35)->get();
44-
$this->assertCount(6, $users);
45+
$this->assertCount(7, $users);
4546

4647
$users = User::where('age', '<>', 35)->get();
47-
$this->assertCount(6, $users);
48+
$this->assertCount(7, $users);
4849
}
4950

5051
public function testAndWhere(): void
@@ -78,21 +79,24 @@ public function testLike(): void
7879

7980
$users = User::where('age', 'like', '%3')->get();
8081
$this->assertCount(4, $users);
82+
83+
$users = User::where('user-age', 'like', '%28')->get();
84+
$this->assertCount(1, $users);
8185
}
8286

8387
public function testNotLike(): void
8488
{
8589
$users = User::where('name', 'not like', '%doe')->get();
86-
$this->assertCount(7, $users);
90+
$this->assertCount(8, $users);
8791

8892
$users = User::where('name', 'not like', '%y%')->get();
89-
$this->assertCount(6, $users);
93+
$this->assertCount(7, $users);
9094

9195
$users = User::where('name', 'not LIKE', '%y%')->get();
92-
$this->assertCount(6, $users);
96+
$this->assertCount(7, $users);
9397

9498
$users = User::where('name', 'not like', 't%')->get();
95-
$this->assertCount(8, $users);
99+
$this->assertCount(9, $users);
96100
}
97101

98102
public function testSelect(): void
@@ -152,7 +156,7 @@ public function testIn(): void
152156
$this->assertCount(6, $users);
153157

154158
$users = User::whereNotIn('age', [33, 35])->get();
155-
$this->assertCount(4, $users);
159+
$this->assertCount(5, $users);
156160

157161
$users = User::whereNotNull('age')
158162
->whereNotIn('age', [33, 35])->get();
@@ -162,7 +166,7 @@ public function testIn(): void
162166
public function testWhereNull(): void
163167
{
164168
$users = User::whereNull('age')->get();
165-
$this->assertCount(1, $users);
169+
$this->assertCount(2, $users);
166170
}
167171

168172
public function testWhereNotNull(): void
@@ -195,7 +199,7 @@ public function testOrder(): void
195199
public function testGroupBy(): void
196200
{
197201
$users = User::groupBy('title')->get();
198-
$this->assertCount(3, $users);
202+
$this->assertCount(4, $users);
199203

200204
$users = User::groupBy('age')->get();
201205
$this->assertCount(6, $users);
@@ -225,11 +229,11 @@ public function testGroupBy(): void
225229
public function testCount(): void
226230
{
227231
$count = User::where('age', '<>', 35)->count();
228-
$this->assertEquals(6, $count);
232+
$this->assertEquals(7, $count);
229233

230234
// Test for issue #165
231235
$count = User::select('_id', 'age', 'title')->where('age', '<>', 35)->count();
232-
$this->assertEquals(6, $count);
236+
$this->assertEquals(7, $count);
233237
}
234238

235239
public function testExists(): void
@@ -327,12 +331,12 @@ public function testPaginate(): void
327331
$results = User::paginate(2);
328332
$this->assertEquals(2, $results->count());
329333
$this->assertNotNull($results->first()->title);
330-
$this->assertEquals(9, $results->total());
334+
$this->assertEquals(10, $results->total());
331335

332336
$results = User::paginate(2, ['name', 'age']);
333337
$this->assertEquals(2, $results->count());
334338
$this->assertNull($results->first()->title);
335-
$this->assertEquals(9, $results->total());
339+
$this->assertEquals(10, $results->total());
336340
$this->assertEquals(1, $results->currentPage());
337341
}
338342

@@ -399,4 +403,4 @@ public function testMultipleSortOrder(): void
399403
$this->assertEquals('John Doe', $subset[1]->name);
400404
$this->assertEquals('Brett Boe', $subset[2]->name);
401405
}
402-
}
406+
}

0 commit comments

Comments
 (0)