|
4 | 4 |
|
5 | 5 | use Helmich\MongoMock\MockCollection;
|
6 | 6 | use Helmich\MongoMock\MockCursor;
|
| 7 | +use Helmich\MongoMock\Exception; |
7 | 8 | use MongoDB\BSON\ObjectID;
|
8 | 9 | use MongoDB\BSON\Regex;
|
9 | 10 | use MongoDB\Collection;
|
@@ -184,6 +185,9 @@ public function testFindWithInvertedFilter()
|
184 | 185 | $result = $find->toArray();
|
185 | 186 | self::assertThat(count($result), self::equalTo(1));
|
186 | 187 | self::assertThat($result[0]['foo'], self::equalTo('bar'));
|
| 188 | + |
| 189 | + $result = $this->col->count(['foo' => ['$not' => ['$regex' => "/bar/"]]]); |
| 190 | + self::assertThat($result, self::equalTo(1)); |
187 | 191 | }
|
188 | 192 |
|
189 | 193 | /**
|
@@ -237,6 +241,32 @@ public function testInsertOneKeepsIdIfSet()
|
237 | 241 | self::assertThat($find['foo'], self::equalTo('bar'));
|
238 | 242 | }
|
239 | 243 |
|
| 244 | + public function testFindWithRegexFilter() |
| 245 | + { |
| 246 | + $this->col->insertMany([ |
| 247 | + ['foo' => 'barbazbad'], |
| 248 | + ['foo' => 'bazbad'], |
| 249 | + ['foo' => 'foobarbaroof'] |
| 250 | + ]); |
| 251 | + |
| 252 | + $result = $this->col->count(['foo' => ['$regex' => "/barBar/"]]); |
| 253 | + self::assertThat($result, self::equalTo(0)); |
| 254 | + |
| 255 | + $result = $this->col->count(['foo' => ['$regex' => "/bar/"]]); |
| 256 | + self::assertThat($result, self::equalTo(2)); |
| 257 | + |
| 258 | + $result = $this->col->count(['foo' => ['$regex' => "/(bar|BAZ)/i"]]); |
| 259 | + self::assertThat($result, self::equalTo(3)); |
| 260 | + |
| 261 | + $result = $this->col->count(['foo' => ['$regex' => new \MongoDB\BSON\Regex("FOOBAR","i")]]); |
| 262 | + self::assertThat($result, self::equalTo(1)); |
| 263 | + |
| 264 | + $this->expectException(Exception::class); |
| 265 | + |
| 266 | + $result = $this->col->count(['foo' => ['$regex' => "[[[[foobar{"]]); |
| 267 | + |
| 268 | + } |
| 269 | + |
240 | 270 | public function testInsertManyInsertsDocuments()
|
241 | 271 | {
|
242 | 272 | $result = $this->col->insertMany([
|
|
0 commit comments