Skip to content

Commit 1c6c5b5

Browse files
Formatting
1 parent 5523028 commit 1c6c5b5

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/MockCollection.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
use MongoDB\BSON\ObjectID;
1111
use MongoDB\BSON\Regex;
1212
use MongoDB\Collection;
13-
use MongoDB\Model\BSONArray;
13+
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
1414
use MongoDB\Model\BSONDocument;
1515
use MongoDB\Model\IndexInfoIteratorIterator;
16-
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
1716
use MongoDB\Operation\FindOneAndUpdate;
1817
use PHPUnit\Framework\Constraint\Constraint;
1918

@@ -378,7 +377,7 @@ public function deleteOne($filter, array $options = [])
378377
$deletedIds = [];
379378
foreach ($this->documents as $i => $doc) {
380379
if ($matcher($doc)) {
381-
$deletedIds []= $doc['_id'];
380+
$deletedIds [] = $doc['_id'];
382381
unset($this->documents[$i]);
383382
$this->documents = array_values($this->documents);
384383
$count++;
@@ -393,7 +392,7 @@ public function distinct($fieldName, $filter = [], array $options = [])
393392
$values = [];
394393

395394
$matcher = $this->matcherFromQuery($filter);
396-
foreach ($this->documents as $document){
395+
foreach ($this->documents as $document) {
397396
if ($matcher($document) && isset($document[$fieldName])) {
398397
$values[] = $document[$fieldName];
399398
}
@@ -678,20 +677,19 @@ function ($acc, $op) use ($val) {
678677
$result = !$operand;
679678
}
680679
break;
681-
case '$regex':{
682-
if($operand instanceof \MongoDB\BSON\Regex){
683-
$regex = "/". $operand->getPattern() . "/". $operand->getFlags();
684-
$result = preg_match($regex,$val) === 1;
685-
}else if(is_string($operand)){
686-
if(@preg_match($operand, '') === false){
680+
case '$regex':
681+
if ($operand instanceof Regex) {
682+
$regex = "/" . $operand->getPattern() . "/" . $operand->getFlags();
683+
$result = preg_match($regex, $val) === 1;
684+
} else if (is_string($operand)) {
685+
if (@preg_match($operand, '') === false) {
687686
throw new Exception("Invalid constraint for operator '" . $type . "'");
688687
}
689-
$result = preg_match($operand,$val) === 1;
690-
}else{
688+
$result = preg_match($operand, $val) === 1;
689+
} else {
691690
throw new Exception("Invalid constraint for operator '" . $type . "'");
692691
}
693692
break;
694-
}
695693
// Custom operators
696694
case '$instanceOf':
697695
$result = is_a($val, $operand);

tests/MockCollectionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ public function testFindWithRegexFilter()
258258
$result = $this->col->count(['foo' => ['$regex' => "/(bar|BAZ)/i"]]);
259259
self::assertThat($result, self::equalTo(3));
260260

261-
$result = $this->col->count(['foo' => ['$regex' => new \MongoDB\BSON\Regex("FOOBAR","i")]]);
261+
$result = $this->col->count(['foo' => ['$regex' => new \MongoDB\BSON\Regex("FOOBAR", "i")]]);
262262
self::assertThat($result, self::equalTo(1));
263-
263+
264264
$this->expectException(Exception::class);
265265

266266
$result = $this->col->count(['foo' => ['$regex' => "[[[[foobar{"]]);
@@ -311,15 +311,15 @@ public function testDeleteOneDeletesJustOneObject()
311311
['foo' => 'bar', 'bar' => 1],
312312
['foo' => 'baz', 'bar' => 2],
313313
]);
314-
314+
315315
$deleteResult = $this->col->deleteOne(['bar' => 1]);
316316

317317
self::assertThat($this->col->count(['bar' => 1]), self::equalTo(1));
318318
self::assertThat($this->col->count(['bar' => 2]), self::equalTo(1));
319319

320320
self::assertInstanceOf(\Helmich\MongoMock\MockDeleteResult::class, $deleteResult);
321321

322-
self::assertEquals(1,$deleteResult->getDeletedCount());
322+
self::assertEquals(1, $deleteResult->getDeletedCount());
323323
}
324324

325325
/**

0 commit comments

Comments
 (0)