Commit 3bdebc4e authored by Jeremy Mikola's avatar Jeremy Mikola

Refactor unit tests for write operations

parent 694c2117
...@@ -64,10 +64,10 @@ class BulkWriteTest extends TestCase ...@@ -64,10 +64,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["insertOne"\]\[0\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["insertOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testInsertOneDocumentArgumentType($document) public function testInsertOneDocumentArgumentTypeCheck($document)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::INSERT_ONE => array($document)), array(BulkWrite::INSERT_ONE => array($document)),
...@@ -87,10 +87,10 @@ class BulkWriteTest extends TestCase ...@@ -87,10 +87,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteMany"\]\[0\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteMany"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testDeleteManyFilterArgumentType($document) public function testDeleteManyFilterArgumentTypeCheck($document)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::DELETE_MANY => array($document)), array(BulkWrite::DELETE_MANY => array($document)),
...@@ -110,10 +110,10 @@ class BulkWriteTest extends TestCase ...@@ -110,10 +110,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteOne"\]\[0\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["deleteOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testDeleteOneFilterArgumentType($document) public function testDeleteOneFilterArgumentTypeCheck($document)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::DELETE_ONE => array($document)), array(BulkWrite::DELETE_ONE => array($document)),
...@@ -133,10 +133,10 @@ class BulkWriteTest extends TestCase ...@@ -133,10 +133,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[0\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testReplaceOneFilterArgumentType($filter) public function testReplaceOneFilterArgumentTypeCheck($filter)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array($filter, array('y' => 1))), array(BulkWrite::REPLACE_ONE => array($filter, array('y' => 1))),
...@@ -156,10 +156,10 @@ class BulkWriteTest extends TestCase ...@@ -156,10 +156,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[1\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[1\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testReplaceOneReplacementArgumentType($replacement) public function testReplaceOneReplacementArgumentTypeCheck($replacement)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array(array('x' => 1), $replacement)), array(BulkWrite::REPLACE_ONE => array(array('x' => 1), $replacement)),
...@@ -179,10 +179,10 @@ class BulkWriteTest extends TestCase ...@@ -179,10 +179,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[2\]\["upsert"\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["replaceOne"\]\[2\]\["upsert"\] to have type "boolean" but found "[\w ]+"/
* @dataProvider provideInvalidBooleanArguments * @dataProvider provideInvalidBooleanValues
*/ */
public function testReplaceOneUpsertOptionType($upsert) public function testReplaceOneUpsertOptionTypeCheck($upsert)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::REPLACE_ONE => array(array('x' => 1), array('y' => 1), array('upsert' => $upsert))), array(BulkWrite::REPLACE_ONE => array(array('x' => 1), array('y' => 1), array('upsert' => $upsert))),
...@@ -202,10 +202,10 @@ class BulkWriteTest extends TestCase ...@@ -202,10 +202,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[0\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testUpdateManyFilterArgumentType($filter) public function testUpdateManyFilterArgumentTypeCheck($filter)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array($filter, array('$set' => array('x' => 1)))), array(BulkWrite::UPDATE_MANY => array($filter, array('$set' => array('x' => 1)))),
...@@ -225,10 +225,10 @@ class BulkWriteTest extends TestCase ...@@ -225,10 +225,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[1\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[1\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testUpdateManyUpdateArgumentType($update) public function testUpdateManyUpdateArgumentTypeCheck($update)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array(array('x' => 1), $update)), array(BulkWrite::UPDATE_MANY => array(array('x' => 1), $update)),
...@@ -248,10 +248,10 @@ class BulkWriteTest extends TestCase ...@@ -248,10 +248,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[2\]\["upsert"\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateMany"\]\[2\]\["upsert"\] to have type "boolean" but found "[\w ]+"/
* @dataProvider provideInvalidBooleanArguments * @dataProvider provideInvalidBooleanValues
*/ */
public function testUpdateManyUpsertOptionType($upsert) public function testUpdateManyUpsertOptionTypeCheck($upsert)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_MANY => array(array('x' => 1), array('$set' => array('x' => 1)), array('upsert' => $upsert))), array(BulkWrite::UPDATE_MANY => array(array('x' => 1), array('$set' => array('x' => 1)), array('upsert' => $upsert))),
...@@ -271,10 +271,10 @@ class BulkWriteTest extends TestCase ...@@ -271,10 +271,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[0\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testUpdateOneFilterArgumentType($filter) public function testUpdateOneFilterArgumentTypeCheck($filter)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array($filter, array('$set' => array('x' => 1)))), array(BulkWrite::UPDATE_ONE => array($filter, array('$set' => array('x' => 1)))),
...@@ -294,10 +294,10 @@ class BulkWriteTest extends TestCase ...@@ -294,10 +294,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[1\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[1\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testUpdateOneUpdateArgumentType($update) public function testUpdateOneUpdateArgumentTypeCheck($update)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array(array('x' => 1), $update)), array(BulkWrite::UPDATE_ONE => array(array('x' => 1), $update)),
...@@ -317,10 +317,10 @@ class BulkWriteTest extends TestCase ...@@ -317,10 +317,10 @@ class BulkWriteTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[2\]\["upsert"\] to have type "[\w ]+" but found "[\w ]+"/ * @expectedExceptionMessageRegExp /Expected \$operations\[0\]\["updateOne"\]\[2\]\["upsert"\] to have type "boolean" but found "[\w ]+"/
* @dataProvider provideInvalidBooleanArguments * @dataProvider provideInvalidBooleanValues
*/ */
public function testUpdateOneUpsertOptionType($upsert) public function testUpdateOneUpsertOptionTypeCheck($upsert)
{ {
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array( new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), array(
array(BulkWrite::UPDATE_ONE => array(array('x' => 1), array('$set' => array('x' => 1)), array('upsert' => $upsert))), array(BulkWrite::UPDATE_ONE => array(array('x' => 1), array('$set' => array('x' => 1)), array('upsert' => $upsert))),
......
...@@ -8,27 +8,45 @@ class DeleteTest extends TestCase ...@@ -8,27 +8,45 @@ class DeleteTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentType($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0); new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentArguments * @expectedExceptionMessage $limit must be 0 or 1
* @dataProvider provideInvalidLimitValues
*/ */
public function testConstructorLimitArgumentMustBeOneOrZero() public function testConstructorLimitArgumentMustBeOneOrZero($limit)
{ {
new Delete($this->getDatabaseName(), $this->getCollectionName(), array(), 2); new Delete($this->getDatabaseName(), $this->getCollectionName(), array(), $limit);
}
public function provideInvalidLimitValues()
{
return $this->wrapValuesForDataProvider(array_merge($this->getInvalidIntegerValues(), array(-1, 2)));
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorWriteConcernOptionType() public function testConstructorOptionTypeChecks(array $options)
{ {
new Delete($this->getDatabaseName(), $this->getCollectionName(), array(), 1, array('writeConcern' => null)); new Delete($this->getDatabaseName(), $this->getCollectionName(), array(), 1, $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
}
return $options;
} }
} }
...@@ -8,6 +8,7 @@ class InsertManyTest extends TestCase ...@@ -8,6 +8,7 @@ class InsertManyTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $documents is empty
*/ */
public function testConstructorDocumentsMustNotBeEmpty() public function testConstructorDocumentsMustNotBeEmpty()
{ {
...@@ -16,6 +17,7 @@ class InsertManyTest extends TestCase ...@@ -16,6 +17,7 @@ class InsertManyTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $documents is not a list (unexpected index: "1")
*/ */
public function testConstructorDocumentsMustBeAList() public function testConstructorDocumentsMustBeAList()
{ {
...@@ -24,27 +26,35 @@ class InsertManyTest extends TestCase ...@@ -24,27 +26,35 @@ class InsertManyTest extends TestCase
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @expectedExceptionMessageRegExp /Expected \$documents\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorDocumentsElementType($document) public function testConstructorDocumentsArgumentElementTypeChecks($document)
{ {
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array($document)); new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array($document));
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidBooleanArguments * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOrderedOptionType($ordered) public function testConstructorOptionTypeChecks(array $options)
{ {
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array(array('x' => 1)), array('ordered' => $ordered)); new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array(array('x' => 1)), $options);
} }
/** public function provideInvalidConstructorOptions()
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
*/
public function testConstructorWriteConcernOptionType()
{ {
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), array(array('x' => 1)), array('writeConcern' => null)); $options = array();
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('ordered' => $value);
}
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
}
return $options;
} }
} }
...@@ -8,18 +8,30 @@ class InsertOneTest extends TestCase ...@@ -8,18 +8,30 @@ class InsertOneTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorDocumentArgumentType($document) public function testConstructorDocumentArgumentTypeCheck($document)
{ {
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document); new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorWriteConcernOptionType() public function testConstructorOptionTypeChecks(array $options)
{ {
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('writeConcern' => null)); new InsertOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $options);
}
public function provideInvalidConstructorOptions()
{
$options = array();
foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = array('writeConcern' => $value);
}
return $options;
} }
} }
...@@ -8,24 +8,25 @@ class ReplaceOneTest extends TestCase ...@@ -8,24 +8,25 @@ class ReplaceOneTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentType($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, array('y' => 1)); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, array('y' => 1));
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorReplacementArgumentType($replacement) public function testConstructorReplacementArgumentTypeCheck($replacement)
{ {
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $replacement); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $replacement);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $replacement argument is an update operator
*/ */
public function testConstructorReplacementArgumentRequiresNoOperators() public function testConstructorReplacementArgumentRequiresNoOperators()
{ {
......
...@@ -10,24 +10,43 @@ use stdClass; ...@@ -10,24 +10,43 @@ use stdClass;
*/ */
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
public function provideInvalidDocumentArguments() public function provideInvalidDocumentValues()
{ {
return array( return $this->wrapValuesForDataProvider($this->getInvalidDocumentValues());
array(null),
array(123),
array('foo'),
array(true),
);
} }
public function provideInvalidBooleanArguments() public function provideInvalidBooleanValues()
{ {
return array( return $this->wrapValuesForDataProvider($this->getInvalidBooleanValues());
array(null), }
array(123),
array('foo'), protected function getInvalidBooleanValues()
array(array()), {
array(new stdClass()), return array(123, 3.14, 'foo', array(), new stdClass);
); }
protected function getInvalidDocumentValues()
{
return array(123, 3.14, 'foo', true);
}
protected function getInvalidIntegerValues()
{
return array(3.14, 'foo', true, array(), new stdClass);
}
protected function getInvalidStringValues()
{
return array(123, 3.14, true, array(), new stdClass);
}
protected function getInvalidWriteConcernValues()
{
return array(123, 3.14, 'foo', true, array(), new stdClass);
}
protected function wrapValuesForDataProvider(array $values)
{
return array_map(function($value) { return array($value); }, $values);
} }
} }
...@@ -8,24 +8,25 @@ class UpdateManyTest extends TestCase ...@@ -8,24 +8,25 @@ class UpdateManyTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentType($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1))); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1)));
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentType($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
*/ */
public function testConstructorUpdateArgumentRequiresOperators() public function testConstructorUpdateArgumentRequiresOperators()
{ {
......
...@@ -8,24 +8,25 @@ class UpdateOneTest extends TestCase ...@@ -8,24 +8,25 @@ class UpdateOneTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentType($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1))); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1)));
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentType($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException * @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
*/ */
public function testConstructorUpdateArgumentRequiresOperators() public function testConstructorUpdateArgumentRequiresOperators()
{ {
......
...@@ -8,45 +8,49 @@ class UpdateTest extends TestCase ...@@ -8,45 +8,49 @@ class UpdateTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @expectedExceptionMessageRegExp /Expected \$filter to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentType($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1))); new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, array('$set' => array('x' => 1)));
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentArguments * @expectedExceptionMessageRegExp /Expected \$update to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentType($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update); new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), $update);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException * @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidBooleanArguments * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorMultiOptionType($multi) public function testConstructorOptionTypeChecks(array $options)
{ {
new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1), array('multi' => $multi)); new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1), $options);
} }
/** public function provideInvalidConstructorOptions()
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidBooleanArguments
*/
public function testConstructorUpsertOptionType($upsert)
{ {
new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1), array('upsert' => $upsert)); $options = array();
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = array('multi' => $value);
} }
/** foreach ($this->getInvalidBooleanValues() as $value) {
* @expectedException MongoDB\Exception\InvalidArgumentTypeException $options[][] = array('upsert' => $value);
*/ }
public function testConstructorWriteConcernOptionType()
{ foreach ($this->getInvalidWriteConcernValues() as $value) {
new Update($this->getDatabaseName(), $this->getCollectionName(), array('x' => 1), array('y' => 1), array('writeConcern' => null)); $options[][] = array('writeConcern' => $value);
}
return $options;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment