Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

MongoDB 2.6: Ensure $in argument is a real BSON array #174

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Doctrine/MongoDB/Query/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function gte($value)
*/
public function in(array $values)
{
return $this->operator('$in', $values);
return $this->operator('$in', array_values($values));
}

/**
Expand Down Expand Up @@ -675,7 +675,7 @@ public function notEqual($value)
*/
public function notIn(array $values)
{
return $this->operator('$nin', $values);
return $this->operator('$nin', array_values($values));
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/Doctrine/MongoDB/Tests/Query/ExprTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,38 @@ private function getMockPolygon($json)

return $point;
}

public function testIn()
{
$expr = new Expr();

$this->assertSame($expr, $expr->in(array('value1', 'value2')));
$this->assertEquals(array('$in' => array('value1', 'value2')), $expr->getQuery());
}

public function testInSendsRealBSONArray()
{
$expr = new Expr();

$this->assertSame($expr, $expr->field('_id')->in(array(1 => 'value1', 'some' => 'value2')));
$this->assertEquals(array('_id' => array('$in' => array('value1', 'value2'))), $expr->getQuery());
}

public function testNotIn()
{
$expr = new Expr();

$this->assertSame($expr, $expr->notIn(array('value1', 'value2')));
$this->assertEquals(array('$nin' => array('value1', 'value2')), $expr->getQuery());
}

public function testNotInSendsRealBSONArray()
{
$expr = new Expr();

$this->assertSame($expr, $expr->field('_id')->notIn(array(1 => 'value1', 'some' => 'value2')));
$this->assertEquals(array('_id' => array('$nin' => array('value1', 'value2'))), $expr->getQuery());
}


}