Commit 201b6ab6 authored by Katherine Walker's avatar Katherine Walker

PHPLIB-216: Use expectException() method instead of annotation in tests

parent 5d046bd2
...@@ -6,6 +6,7 @@ use MongoDB\Client; ...@@ -6,6 +6,7 @@ use MongoDB\Client;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
/** /**
* Unit tests for the Client class. * Unit tests for the Client class.
...@@ -20,11 +21,11 @@ class ClientTest extends TestCase ...@@ -20,11 +21,11 @@ class ClientTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorDriverOptions * @dataProvider provideInvalidConstructorDriverOptions
*/ */
public function testConstructorDriverOptionTypeChecks(array $driverOptions) public function testConstructorDriverOptionTypeChecks(array $driverOptions)
{ {
$this->expectException(InvalidArgumentException::class);
new Client($this->getUri(), [], $driverOptions); new Client($this->getUri(), [], $driverOptions);
} }
......
...@@ -8,6 +8,7 @@ use MongoDB\Driver\BulkWrite; ...@@ -8,6 +8,7 @@ use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\MapReduce; use MongoDB\Operation\MapReduce;
/** /**
...@@ -16,21 +17,21 @@ use MongoDB\Operation\MapReduce; ...@@ -16,21 +17,21 @@ use MongoDB\Operation\MapReduce;
class CollectionFunctionalTest extends FunctionalTestCase class CollectionFunctionalTest extends FunctionalTestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabaseAndCollectionNames * @dataProvider provideInvalidDatabaseAndCollectionNames
*/ */
public function testConstructorDatabaseNameArgument($databaseName) public function testConstructorDatabaseNameArgument($databaseName)
{ {
$this->expectException(InvalidArgumentException::class);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378) // TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Collection($this->manager, $databaseName, $this->getCollectionName()); new Collection($this->manager, $databaseName, $this->getCollectionName());
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabaseAndCollectionNames * @dataProvider provideInvalidDatabaseAndCollectionNames
*/ */
public function testConstructorCollectionNameArgument($collectionName) public function testConstructorCollectionNameArgument($collectionName)
{ {
$this->expectException(InvalidArgumentException::class);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378) // TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Collection($this->manager, $this->getDatabaseName(), $collectionName); new Collection($this->manager, $this->getDatabaseName(), $collectionName);
} }
...@@ -44,11 +45,11 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -44,11 +45,11 @@ class CollectionFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $options); new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $options);
} }
...@@ -111,11 +112,11 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -111,11 +112,11 @@ class CollectionFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @todo Move this to a unit test once Manager can be mocked * @todo Move this to a unit test once Manager can be mocked
*/ */
public function testDropIndexShouldNotAllowWildcardCharacter() public function testDropIndexShouldNotAllowWildcardCharacter()
{ {
$this->expectException(InvalidArgumentException::class);
$this->collection->dropIndex('*'); $this->collection->dropIndex('*');
} }
......
...@@ -7,6 +7,7 @@ use MongoDB\Driver\BulkWrite; ...@@ -7,6 +7,7 @@ use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
/** /**
* Functional tests for the Database class. * Functional tests for the Database class.
...@@ -14,11 +15,11 @@ use MongoDB\Driver\WriteConcern; ...@@ -14,11 +15,11 @@ use MongoDB\Driver\WriteConcern;
class DatabaseFunctionalTest extends FunctionalTestCase class DatabaseFunctionalTest extends FunctionalTestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabaseNames * @dataProvider provideInvalidDatabaseNames
*/ */
public function testConstructorDatabaseNameArgument($databaseName) public function testConstructorDatabaseNameArgument($databaseName)
{ {
$this->expectException(InvalidArgumentException::class);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378) // TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Database($this->manager, $databaseName); new Database($this->manager, $databaseName);
} }
...@@ -32,11 +33,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -32,11 +33,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Database($this->manager, $this->getDatabaseName(), $options); new Database($this->manager, $this->getDatabaseName(), $options);
} }
...@@ -115,11 +116,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -115,11 +116,11 @@ class DatabaseFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testCommandCommandArgumentTypeCheck($command) public function testCommandCommandArgumentTypeCheck($command)
{ {
$this->expectException(InvalidArgumentException::class);
$this->database->command($command); $this->database->command($command);
} }
......
...@@ -6,6 +6,7 @@ use MongoDB\Model\BSONArray; ...@@ -6,6 +6,7 @@ use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
/** /**
* Unit tests for utility functions. * Unit tests for utility functions.
...@@ -80,11 +81,11 @@ class FunctionsTest extends TestCase ...@@ -80,11 +81,11 @@ class FunctionsTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testGenerateIndexNameArgumentTypeCheck($document) public function testGenerateIndexNameArgumentTypeCheck($document)
{ {
$this->expectException(InvalidArgumentException::class);
\MongoDB\generate_index_name($document); \MongoDB\generate_index_name($document);
} }
...@@ -109,11 +110,11 @@ class FunctionsTest extends TestCase ...@@ -109,11 +110,11 @@ class FunctionsTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testIsFirstKeyOperatorArgumentTypeCheck($document) public function testIsFirstKeyOperatorArgumentTypeCheck($document)
{ {
$this->expectException(InvalidArgumentException::class);
\MongoDB\is_first_key_operator($document); \MongoDB\is_first_key_operator($document);
} }
......
...@@ -6,11 +6,13 @@ use MongoDB\BSON\Binary; ...@@ -6,11 +6,13 @@ use MongoDB\BSON\Binary;
use MongoDB\Driver\ReadConcern; use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\Bucket; use MongoDB\GridFS\Bucket;
use MongoDB\GridFS\Exception\FileNotFoundException; use MongoDB\GridFS\Exception\FileNotFoundException;
use MongoDB\Model\IndexInfo; use MongoDB\Model\IndexInfo;
use MongoDB\Operation\ListCollections; use MongoDB\Operation\ListCollections;
use MongoDB\Operation\ListIndexes; use MongoDB\Operation\ListIndexes;
use PHPUnit\Framework\Error\Warning;
/** /**
* Functional tests for the Bucket class. * Functional tests for the Bucket class.
...@@ -32,11 +34,11 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -32,11 +34,11 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Bucket($this->manager, $this->getDatabaseName(), $options); new Bucket($this->manager, $this->getDatabaseName(), $options);
} }
...@@ -71,12 +73,10 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -71,12 +73,10 @@ class BucketFunctionalTest extends FunctionalTestCase
return $options; return $options;
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage Expected "chunkSizeBytes" option to be >= 1, 0 given
*/
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive() public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected "chunkSizeBytes" option to be >= 1, 0 given');
new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 0]); new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 0]);
} }
...@@ -112,11 +112,9 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -112,11 +112,9 @@ class BucketFunctionalTest extends FunctionalTestCase
]; ];
} }
/**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
*/
public function testDeleteShouldRequireFileToExist() public function testDeleteShouldRequireFileToExist()
{ {
$this->expectException(FileNotFoundException::class);
$this->bucket->delete('nonexistent-id'); $this->bucket->delete('nonexistent-id');
} }
...@@ -140,21 +138,16 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -140,21 +138,16 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->assertCollectionCount($this->chunksCollection, 0); $this->assertCollectionCount($this->chunksCollection, 0);
} }
/**
* @expectedException PHPUnit\Framework\Error\Warning
*/
public function testDownloadingFileWithMissingChunk() public function testDownloadingFileWithMissingChunk()
{ {
$id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar")); $id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar"));
$this->chunksCollection->deleteOne(['files_id' => $id, 'n' => 0]); $this->chunksCollection->deleteOne(['files_id' => $id, 'n' => 0]);
$this->expectException(Warning::class);
stream_get_contents($this->bucket->openDownloadStream($id)); stream_get_contents($this->bucket->openDownloadStream($id));
} }
/**
* @expectedException PHPUnit\Framework\Error\Warning
*/
public function testDownloadingFileWithUnexpectedChunkIndex() public function testDownloadingFileWithUnexpectedChunkIndex()
{ {
$id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar")); $id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar"));
...@@ -164,12 +157,10 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -164,12 +157,10 @@ class BucketFunctionalTest extends FunctionalTestCase
['$set' => ['n' => 1]] ['$set' => ['n' => 1]]
); );
$this->expectException(Warning::class);
stream_get_contents($this->bucket->openDownloadStream($id)); stream_get_contents($this->bucket->openDownloadStream($id));
} }
/**
* @expectedException PHPUnit\Framework\Error\Warning
*/
public function testDownloadingFileWithUnexpectedChunkSize() public function testDownloadingFileWithUnexpectedChunkSize()
{ {
$id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar")); $id = $this->bucket->uploadFromStream("filename", $this->createStream("foobar"));
...@@ -179,6 +170,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -179,6 +170,7 @@ class BucketFunctionalTest extends FunctionalTestCase
['$set' => ['data' => new Binary('fooba', Binary::TYPE_GENERIC)]] ['$set' => ['data' => new Binary('fooba', Binary::TYPE_GENERIC)]]
); );
$this->expectException(Warning::class);
stream_get_contents($this->bucket->openDownloadStream($id)); stream_get_contents($this->bucket->openDownloadStream($id));
} }
...@@ -195,11 +187,11 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -195,11 +187,11 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidStreamValues * @dataProvider provideInvalidStreamValues
*/ */
public function testDownloadToStreamShouldRequireDestinationStream($destination) public function testDownloadToStreamShouldRequireDestinationStream($destination)
{ {
$this->expectException(InvalidArgumentException::class);
$this->bucket->downloadToStream('id', $destination); $this->bucket->downloadToStream('id', $destination);
} }
...@@ -208,11 +200,9 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -208,11 +200,9 @@ class BucketFunctionalTest extends FunctionalTestCase
return $this->wrapValuesForDataProvider($this->getInvalidStreamValues()); return $this->wrapValuesForDataProvider($this->getInvalidStreamValues());
} }
/**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
*/
public function testDownloadToStreamShouldRequireFileToExist() public function testDownloadToStreamShouldRequireFileToExist()
{ {
$this->expectException(FileNotFoundException::class);
$this->bucket->downloadToStream('nonexistent-id', $this->createStream()); $this->bucket->downloadToStream('nonexistent-id', $this->createStream());
} }
...@@ -252,16 +242,15 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -252,16 +242,15 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidStreamValues * @dataProvider provideInvalidStreamValues
*/ */
public function testDownloadToStreamByNameShouldRequireDestinationStream($destination) public function testDownloadToStreamByNameShouldRequireDestinationStream($destination)
{ {
$this->expectException(InvalidArgumentException::class);
$this->bucket->downloadToStreamByName('filename', $destination); $this->bucket->downloadToStreamByName('filename', $destination);
} }
/** /**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
* @dataProvider provideNonexistentFilenameAndRevision * @dataProvider provideNonexistentFilenameAndRevision
*/ */
public function testDownloadToStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision) public function testDownloadToStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision)
...@@ -270,6 +259,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -270,6 +259,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->bucket->uploadFromStream('filename', $this->createStream('bar')); $this->bucket->uploadFromStream('filename', $this->createStream('bar'));
$destination = $this->createStream(); $destination = $this->createStream();
$this->expectException(FileNotFoundException::class);
$this->bucket->downloadToStreamByName($filename, $destination, ['revision' => $revision]); $this->bucket->downloadToStreamByName($filename, $destination, ['revision' => $revision]);
} }
...@@ -430,11 +420,11 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -430,11 +420,11 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidGridFSStreamValues * @dataProvider provideInvalidGridFSStreamValues
*/ */
public function testGetFileDocumentForStreamShouldRequireGridFSStreamResource($stream) public function testGetFileDocumentForStreamShouldRequireGridFSStreamResource($stream)
{ {
$this->expectException(InvalidArgumentException::class);
$this->bucket->getFileDocumentForStream($stream); $this->bucket->getFileDocumentForStream($stream);
} }
...@@ -469,11 +459,11 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -469,11 +459,11 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidGridFSStreamValues * @dataProvider provideInvalidGridFSStreamValues
*/ */
public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream) public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream)
{ {
$this->expectException(InvalidArgumentException::class);
$this->bucket->getFileIdForStream($stream); $this->bucket->getFileIdForStream($stream);
} }
...@@ -516,19 +506,15 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -516,19 +506,15 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->assertEquals($input, $buffer); $this->assertEquals($input, $buffer);
} }
/**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
*/
public function testOpenDownloadStreamShouldRequireFileToExist() public function testOpenDownloadStreamShouldRequireFileToExist()
{ {
$this->expectException(FileNotFoundException::class);
$this->bucket->openDownloadStream('nonexistent-id'); $this->bucket->openDownloadStream('nonexistent-id');
} }
/**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
*/
public function testOpenDownloadStreamByNameShouldRequireFilenameToExist() public function testOpenDownloadStreamByNameShouldRequireFilenameToExist()
{ {
$this->expectException(FileNotFoundException::class);
$this->bucket->openDownloadStream('nonexistent-filename'); $this->bucket->openDownloadStream('nonexistent-filename');
} }
...@@ -548,7 +534,6 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -548,7 +534,6 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
* @dataProvider provideNonexistentFilenameAndRevision * @dataProvider provideNonexistentFilenameAndRevision
*/ */
public function testOpenDownloadStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision) public function testOpenDownloadStreamByNameShouldRequireFilenameAndRevisionToExist($filename, $revision)
...@@ -556,6 +541,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -556,6 +541,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->bucket->uploadFromStream('filename', $this->createStream('foo')); $this->bucket->uploadFromStream('filename', $this->createStream('foo'));
$this->bucket->uploadFromStream('filename', $this->createStream('bar')); $this->bucket->uploadFromStream('filename', $this->createStream('bar'));
$this->expectException(FileNotFoundException::class);
$this->bucket->openDownloadStream($filename, ['revision' => $revision]); $this->bucket->openDownloadStream($filename, ['revision' => $revision]);
} }
...@@ -617,11 +603,9 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -617,11 +603,9 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->assertStreamContents('foo', $this->bucket->openDownloadStreamByName('a')); $this->assertStreamContents('foo', $this->bucket->openDownloadStreamByName('a'));
} }
/**
* @expectedException MongoDB\GridFS\Exception\FileNotFoundException
*/
public function testRenameShouldRequireFileToExist() public function testRenameShouldRequireFileToExist()
{ {
$this->expectException(FileNotFoundException::class);
$this->bucket->rename('nonexistent-id', 'b'); $this->bucket->rename('nonexistent-id', 'b');
} }
...@@ -645,11 +629,11 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -645,11 +629,11 @@ class BucketFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidStreamValues * @dataProvider provideInvalidStreamValues
*/ */
public function testUploadFromStreamShouldRequireSourceStream($source) public function testUploadFromStreamShouldRequireSourceStream($source)
{ {
$this->expectException(InvalidArgumentException::class);
$this->bucket->uploadFromStream('filename', $source); $this->bucket->uploadFromStream('filename', $source);
} }
......
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
namespace MongoDB\Tests\GridFS; namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\CollectionWrapper; use MongoDB\GridFS\CollectionWrapper;
use MongoDB\GridFS\ReadableStream; use MongoDB\GridFS\ReadableStream;
use MongoDB\GridFS\Exception\CorruptFileException;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
...@@ -48,11 +50,11 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -48,11 +50,11 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException
* @dataProvider provideInvalidConstructorFileDocuments * @dataProvider provideInvalidConstructorFileDocuments
*/ */
public function testConstructorFileDocumentChecks($file) public function testConstructorFileDocumentChecks($file)
{ {
$this->expectException(CorruptFileException::class);
new ReadableStream($this->collectionWrapper, $file); new ReadableStream($this->collectionWrapper, $file);
} }
...@@ -134,10 +136,6 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -134,10 +136,6 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
} }
} }
/**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException
* @expectedExceptionMessage Chunk not found for index "2"
*/
public function testReadBytesWithMissingChunk() public function testReadBytesWithMissingChunk()
{ {
$this->chunksCollection->deleteOne(['files_id' => 'length-10', 'n' => 2]); $this->chunksCollection->deleteOne(['files_id' => 'length-10', 'n' => 2]);
...@@ -145,13 +143,11 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -145,13 +143,11 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$fileDocument = $this->collectionWrapper->findFileById('length-10'); $fileDocument = $this->collectionWrapper->findFileById('length-10');
$stream = new ReadableStream($this->collectionWrapper, $fileDocument); $stream = new ReadableStream($this->collectionWrapper, $fileDocument);
$this->expectException(CorruptFileException::class);
$this->expectExceptionMessage('Chunk not found for index "2"');
$stream->readBytes(10); $stream->readBytes(10);
} }
/**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException
* @expectedExceptionMessage Expected chunk to have index "1" but found "2"
*/
public function testReadBytesWithUnexpectedChunkIndex() public function testReadBytesWithUnexpectedChunkIndex()
{ {
$this->chunksCollection->deleteOne(['files_id' => 'length-10', 'n' => 1]); $this->chunksCollection->deleteOne(['files_id' => 'length-10', 'n' => 1]);
...@@ -159,13 +155,11 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -159,13 +155,11 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$fileDocument = $this->collectionWrapper->findFileById('length-10'); $fileDocument = $this->collectionWrapper->findFileById('length-10');
$stream = new ReadableStream($this->collectionWrapper, $fileDocument); $stream = new ReadableStream($this->collectionWrapper, $fileDocument);
$this->expectException(CorruptFileException::class);
$this->expectExceptionMessage('Expected chunk to have index "1" but found "2"');
$stream->readBytes(10); $stream->readBytes(10);
} }
/**
* @expectedException MongoDB\GridFS\Exception\CorruptFileException
* @expectedExceptionMessage Expected chunk to have size "2" but found "1"
*/
public function testReadBytesWithUnexpectedChunkSize() public function testReadBytesWithUnexpectedChunkSize()
{ {
$this->chunksCollection->updateOne( $this->chunksCollection->updateOne(
...@@ -176,17 +170,17 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -176,17 +170,17 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$fileDocument = $this->collectionWrapper->findFileById('length-10'); $fileDocument = $this->collectionWrapper->findFileById('length-10');
$stream = new ReadableStream($this->collectionWrapper, $fileDocument); $stream = new ReadableStream($this->collectionWrapper, $fileDocument);
$this->expectException(CorruptFileException::class);
$this->expectExceptionMessage('Expected chunk to have size "2" but found "1"');
$stream->readBytes(10); $stream->readBytes(10);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testReadBytesWithNegativeLength() public function testReadBytesWithNegativeLength()
{ {
$fileDocument = $this->collectionWrapper->findFileById('length-0'); $fileDocument = $this->collectionWrapper->findFileById('length-0');
$stream = new ReadableStream($this->collectionWrapper, $fileDocument); $stream = new ReadableStream($this->collectionWrapper, $fileDocument);
$this->expectException(InvalidArgumentException::class);
$stream->readBytes(-1); $stream->readBytes(-1);
} }
...@@ -199,15 +193,13 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase ...@@ -199,15 +193,13 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$this->assertSame('ij', $stream->readBytes(2)); $this->assertSame('ij', $stream->readBytes(2));
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $offset must be >= 0 and <= 10; given: 11
*/
public function testSeekOutOfRange() public function testSeekOutOfRange()
{ {
$fileDocument = $this->collectionWrapper->findFileById('length-10'); $fileDocument = $this->collectionWrapper->findFileById('length-10');
$stream = new ReadableStream($this->collectionWrapper, $fileDocument); $stream = new ReadableStream($this->collectionWrapper, $fileDocument);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$offset must be >= 0 and <= 10; given: 11');
$stream->seek(11); $stream->seek(11);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\GridFS; namespace MongoDB\Tests\GridFS;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\CollectionWrapper; use MongoDB\GridFS\CollectionWrapper;
use MongoDB\GridFS\WritableStream; use MongoDB\GridFS\WritableStream;
...@@ -32,11 +33,11 @@ class WritableStreamFunctionalTest extends FunctionalTestCase ...@@ -32,11 +33,11 @@ class WritableStreamFunctionalTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new WritableStream($this->collectionWrapper, 'filename', $options); new WritableStream($this->collectionWrapper, 'filename', $options);
} }
...@@ -55,12 +56,10 @@ class WritableStreamFunctionalTest extends FunctionalTestCase ...@@ -55,12 +56,10 @@ class WritableStreamFunctionalTest extends FunctionalTestCase
return $options; return $options;
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage Expected "chunkSizeBytes" option to be >= 1, 0 given
*/
public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive() public function testConstructorShouldRequireChunkSizeBytesOptionToBePositive()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected "chunkSizeBytes" option to be >= 1, 0 given');
new WritableStream($this->collectionWrapper, 'filename', ['chunkSizeBytes' => 0]); new WritableStream($this->collectionWrapper, 'filename', ['chunkSizeBytes' => 0]);
} }
......
...@@ -11,13 +11,13 @@ class CachingIteratorTest extends TestCase ...@@ -11,13 +11,13 @@ class CachingIteratorTest extends TestCase
/** /**
* Sanity check for all following tests. * Sanity check for all following tests.
* *
* @expectedException \Exception
* @expectedExceptionMessage Cannot traverse an already closed generator
*/ */
public function testTraversingGeneratorConsumesIt() public function testTraversingGeneratorConsumesIt()
{ {
$iterator = $this->getTraversable([1, 2, 3]); $iterator = $this->getTraversable([1, 2, 3]);
$this->assertSame([1, 2, 3], iterator_to_array($iterator)); $this->assertSame([1, 2, 3], iterator_to_array($iterator));
$this->expectException(Exception::class);
$this->expectExceptionMessage('Cannot traverse an already closed generator');
$this->assertSame([1, 2, 3], iterator_to_array($iterator)); $this->assertSame([1, 2, 3], iterator_to_array($iterator));
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Model; namespace MongoDB\Tests\Model;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Model\IndexInfo; use MongoDB\Model\IndexInfo;
use MongoDB\Tests\TestCase; use MongoDB\Tests\TestCase;
...@@ -111,10 +112,6 @@ class IndexInfoTest extends TestCase ...@@ -111,10 +112,6 @@ class IndexInfoTest extends TestCase
$this->assertSame('x_1', $info['name']); $this->assertSame('x_1', $info['name']);
} }
/**
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessage MongoDB\Model\IndexInfo is immutable
*/
public function testOffsetSetCannotBeCalled() public function testOffsetSetCannotBeCalled()
{ {
$info = new IndexInfo([ $info = new IndexInfo([
...@@ -124,13 +121,11 @@ class IndexInfoTest extends TestCase ...@@ -124,13 +121,11 @@ class IndexInfoTest extends TestCase
'ns' => 'foo.bar', 'ns' => 'foo.bar',
]); ]);
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('MongoDB\Model\IndexInfo is immutable');
$info['v'] = 2; $info['v'] = 2;
} }
/**
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessage MongoDB\Model\IndexInfo is immutable
*/
public function testOffsetUnsetCannotBeCalled() public function testOffsetUnsetCannotBeCalled()
{ {
$info = new IndexInfo([ $info = new IndexInfo([
...@@ -140,6 +135,8 @@ class IndexInfoTest extends TestCase ...@@ -140,6 +135,8 @@ class IndexInfoTest extends TestCase
'ns' => 'foo.bar', 'ns' => 'foo.bar',
]); ]);
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('MongoDB\Model\IndexInfo is immutable');
unset($info['v']); unset($info['v']);
} }
} }
...@@ -2,34 +2,31 @@ ...@@ -2,34 +2,31 @@
namespace MongoDB\Tests\Model; namespace MongoDB\Tests\Model;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\IndexInput; use MongoDB\Model\IndexInput;
use MongoDB\Tests\TestCase; use MongoDB\Tests\TestCase;
use stdClass; use stdClass;
class IndexInputTest extends TestCase class IndexInputTest extends TestCase
{ {
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireKey() public function testConstructorShouldRequireKey()
{ {
$this->expectException(InvalidArgumentException::class);
new IndexInput([]); new IndexInput([]);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireKeyToBeArrayOrObject() public function testConstructorShouldRequireKeyToBeArrayOrObject()
{ {
$this->expectException(InvalidArgumentException::class);
new IndexInput(['key' => 'foo']); new IndexInput(['key' => 'foo']);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidFieldOrderValues * @dataProvider provideInvalidFieldOrderValues
*/ */
public function testConstructorShouldRequireKeyFieldOrderToBeNumericOrString($order) public function testConstructorShouldRequireKeyFieldOrderToBeNumericOrString($order)
{ {
$this->expectException(InvalidArgumentException::class);
new IndexInput(['key' => ['x' => $order]]); new IndexInput(['key' => ['x' => $order]]);
} }
...@@ -38,27 +35,21 @@ class IndexInputTest extends TestCase ...@@ -38,27 +35,21 @@ class IndexInputTest extends TestCase
return $this->wrapValuesForDataProvider([true, [], new stdClass]); return $this->wrapValuesForDataProvider([true, [], new stdClass]);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireNamespace() public function testConstructorShouldRequireNamespace()
{ {
$this->expectException(InvalidArgumentException::class);
new IndexInput(['key' => ['x' => 1]]); new IndexInput(['key' => ['x' => 1]]);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireNamespaceToBeString() public function testConstructorShouldRequireNamespaceToBeString()
{ {
$this->expectException(InvalidArgumentException::class);
new IndexInput(['key' => ['x' => 1], 'ns' => 1]); new IndexInput(['key' => ['x' => 1], 'ns' => 1]);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testConstructorShouldRequireNameToBeString() public function testConstructorShouldRequireNameToBeString()
{ {
$this->expectException(InvalidArgumentException::class);
new IndexInput(['key' => ['x' => 1], 'ns' => 'foo.bar', 'name' => 1]); new IndexInput(['key' => ['x' => 1], 'ns' => 'foo.bar', 'name' => 1]);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Model; namespace MongoDB\Tests\Model;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Model\TypeMapArrayIterator; use MongoDB\Model\TypeMapArrayIterator;
use MongoDB\Tests\TestCase; use MongoDB\Tests\TestCase;
...@@ -59,8 +60,6 @@ class TypeMapArrayIteratorTest extends TestCase ...@@ -59,8 +60,6 @@ class TypeMapArrayIteratorTest extends TestCase
/** /**
* @dataProvider provideMutateMethods * @dataProvider provideMutateMethods
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessage MongoDB\Model\TypeMapArrayIterator is immutable
*/ */
public function testMutateMethodsCannotBeCalled($method, $args) public function testMutateMethodsCannotBeCalled($method, $args)
{ {
...@@ -79,6 +78,8 @@ class TypeMapArrayIteratorTest extends TestCase ...@@ -79,6 +78,8 @@ class TypeMapArrayIteratorTest extends TestCase
$iterator->rewind(); $iterator->rewind();
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('MongoDB\Model\TypeMapArrayIterator is immutable');
call_user_func_array([$iterator, $method], $args); call_user_func_array([$iterator, $method], $args);
} }
......
...@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Operation; ...@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Operation;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Operation\Aggregate; use MongoDB\Operation\Aggregate;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use ArrayIterator; use ArrayIterator;
...@@ -65,12 +66,10 @@ class AggregateFunctionalTest extends FunctionalTestCase ...@@ -65,12 +66,10 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this->assertEquals($expectedDocuments, $results); $this->assertEquals($expectedDocuments, $results);
} }
/**
* @expectedException MongoDB\Driver\Exception\RuntimeException
*/
public function testUnrecognizedPipelineState() public function testUnrecognizedPipelineState()
{ {
$operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [['$foo' => 1]]); $operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [['$foo' => 1]]);
$this->expectException(RuntimeException::class);
$operation->execute($this->getPrimaryServer()); $operation->execute($this->getPrimaryServer());
} }
......
...@@ -2,25 +2,24 @@ ...@@ -2,25 +2,24 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Aggregate; use MongoDB\Operation\Aggregate;
class AggregateTest extends TestCase class AggregateTest extends TestCase
{ {
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $pipeline is not a list (unexpected index: "1")
*/
public function testConstructorPipelineArgumentMustBeAList() public function testConstructorPipelineArgumentMustBeAList()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$pipeline is not a list (unexpected index: "1")');
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [1 => ['$match' => ['x' => 1]]]); new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [1 => ['$match' => ['x' => 1]]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [['$match' => ['x' => 1]]], $options); new Aggregate($this->getDatabaseName(), $this->getCollectionName(), [['$match' => ['x' => 1]]], $options);
} }
...@@ -91,12 +90,10 @@ class AggregateTest extends TestCase ...@@ -91,12 +90,10 @@ class AggregateTest extends TestCase
return $options; return $options;
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage "batchSize" option should not be used if "useCursor" is false
*/
public function testConstructorBatchSizeOptionRequiresUseCursor() public function testConstructorBatchSizeOptionRequiresUseCursor()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"batchSize" option should not be used if "useCursor" is false');
new Aggregate( new Aggregate(
$this->getDatabaseName(), $this->getDatabaseName(),
$this->getCollectionName(), $this->getCollectionName(),
......
...@@ -6,6 +6,8 @@ use MongoDB\BulkWriteResult; ...@@ -6,6 +6,8 @@ use MongoDB\BulkWriteResult;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Driver\BulkWrite as Bulk; use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Operation\BulkWrite; use MongoDB\Operation\BulkWrite;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
...@@ -161,82 +163,80 @@ class BulkWriteFunctionalTest extends FunctionalTestCase ...@@ -161,82 +163,80 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesDeletedCount(BulkWriteResult $result) public function testUnacknowledgedWriteConcernAccessesDeletedCount(BulkWriteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getDeletedCount(); $result->getDeletedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesInsertCount(BulkWriteResult $result) public function testUnacknowledgedWriteConcernAccessesInsertCount(BulkWriteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getInsertedCount(); $result->getInsertedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesMatchedCount(BulkWriteResult $result) public function testUnacknowledgedWriteConcernAccessesMatchedCount(BulkWriteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getMatchedCount(); $result->getMatchedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesModifiedCount(BulkWriteResult $result) public function testUnacknowledgedWriteConcernAccessesModifiedCount(BulkWriteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getModifiedCount(); $result->getModifiedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesUpsertedCount(BulkWriteResult $result) public function testUnacknowledgedWriteConcernAccessesUpsertedCount(BulkWriteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getUpsertedCount(); $result->getUpsertedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesUpsertedIds(BulkWriteResult $result) public function testUnacknowledgedWriteConcernAccessesUpsertedIds(BulkWriteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getUpsertedIds(); $result->getUpsertedIds();
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage Unknown operation type "foo" in $operations[0]
*/
public function testUnknownOperation() public function testUnknownOperation()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown operation type "foo" in $operations[0]');
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
['foo' => [['_id' => 1]]], ['foo' => [['_id' => 1]]],
]); ]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Missing (first|second) argument for \$operations\[\d+\]\["\w+\"]/
* @dataProvider provideOpsWithMissingArguments * @dataProvider provideOpsWithMissingArguments
*/ */
public function testMissingArguments(array $ops) public function testMissingArguments(array $ops)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Missing (first|second) argument for \$operations\[\d+\]\["\w+\"]/');
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), $ops); new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), $ops);
} }
...@@ -255,34 +255,28 @@ class BulkWriteFunctionalTest extends FunctionalTestCase ...@@ -255,34 +255,28 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
]; ];
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $operations[0]["updateOne"][1] is not an update operator
*/
public function testUpdateOneRequiresUpdateOperators() public function testUpdateOneRequiresUpdateOperators()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $operations[0]["updateOne"][1] is not an update operator');
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
['updateOne' => [['_id' => 1], ['x' => 1]]], ['updateOne' => [['_id' => 1], ['x' => 1]]],
]); ]);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $operations[0]["updateMany"][1] is not an update operator
*/
public function testUpdateManyRequiresUpdateOperators() public function testUpdateManyRequiresUpdateOperators()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $operations[0]["updateMany"][1] is not an update operator');
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
['updateMany' => [['_id' => ['$gt' => 1]], ['x' => 1]]], ['updateMany' => [['_id' => ['$gt' => 1]], ['x' => 1]]],
]); ]);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $operations[0]["replaceOne"][1] is an update operator
*/
public function testReplaceOneRequiresReplacementDocument() public function testReplaceOneRequiresReplacementDocument()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $operations[0]["replaceOne"][1] is an update operator');
new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [ new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), [
['replaceOne' => [['_id' => 1], ['$inc' => ['x' => 1]]]], ['replaceOne' => [['_id' => 1], ['$inc' => ['x' => 1]]]],
]); ]);
......
This diff is collapsed.
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Count; use MongoDB\Operation\Count;
class CountTest extends TestCase class CountTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new Count($this->getDatabaseName(), $this->getCollectionName(), $filter); new Count($this->getDatabaseName(), $this->getCollectionName(), $filter);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Count($this->getDatabaseName(), $this->getCollectionName(), [], $options); new Count($this->getDatabaseName(), $this->getCollectionName(), [], $options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\CreateCollection; use MongoDB\Operation\CreateCollection;
class CreateCollectionTest extends TestCase class CreateCollectionTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), $options); new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Model\IndexInfo; use MongoDB\Model\IndexInfo;
use MongoDB\Operation\CreateIndexes; use MongoDB\Operation\CreateIndexes;
use MongoDB\Operation\DropIndexes; use MongoDB\Operation\DropIndexes;
...@@ -113,9 +114,6 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase ...@@ -113,9 +114,6 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
}); });
} }
/**
* @expectedException MongoDB\Driver\Exception\RuntimeException
*/
public function testCreateConflictingIndexesWithCommand() public function testCreateConflictingIndexesWithCommand()
{ {
$indexes = [ $indexes = [
...@@ -124,6 +122,7 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase ...@@ -124,6 +122,7 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
]; ];
$operation = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes); $operation = new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), $indexes);
$this->expectException(RuntimeException::class);
$createdIndexNames = $operation->execute($this->getPrimaryServer()); $createdIndexNames = $operation->execute($this->getPrimaryServer());
} }
......
...@@ -2,25 +2,24 @@ ...@@ -2,25 +2,24 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\CreateIndexes; use MongoDB\Operation\CreateIndexes;
class CreateIndexesTest extends TestCase class CreateIndexesTest extends TestCase
{ {
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $indexes is not a list (unexpected index: "1")
*/
public function testConstructorIndexesArgumentMustBeAList() public function testConstructorIndexesArgumentMustBeAList()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$indexes is not a list (unexpected index: "1")');
new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [1 => ['key' => ['x' => 1]]]); new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [1 => ['key' => ['x' => 1]]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [['key' => ['x' => 1]]], $options); new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [['key' => ['x' => 1]]], $options);
} }
...@@ -43,21 +42,19 @@ class CreateIndexesTest extends TestCase ...@@ -43,21 +42,19 @@ class CreateIndexesTest extends TestCase
return $options; return $options;
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $indexes is empty
*/
public function testConstructorRequiresAtLeastOneIndex() public function testConstructorRequiresAtLeastOneIndex()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$indexes is empty');
new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), []); new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), []);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidIndexSpecificationTypes * @dataProvider provideInvalidIndexSpecificationTypes
*/ */
public function testConstructorRequiresIndexSpecificationsToBeAnArray($index) public function testConstructorRequiresIndexSpecificationsToBeAnArray($index)
{ {
$this->expectException(InvalidArgumentException::class);
new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [$index]); new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [$index]);
} }
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\DatabaseCommand; use MongoDB\Operation\DatabaseCommand;
class DatabaseCommandTest extends TestCase class DatabaseCommandTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorCommandArgumentTypeCheck($command) public function testConstructorCommandArgumentTypeCheck($command)
{ {
$this->expectException(InvalidArgumentException::class);
new DatabaseCommand($this->getDatabaseName(), $command); new DatabaseCommand($this->getDatabaseName(), $command);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new DatabaseCommand($this->getDatabaseName(), ['ping' => 1], $options); new DatabaseCommand($this->getDatabaseName(), ['ping' => 1], $options);
} }
......
...@@ -6,6 +6,7 @@ use MongoDB\DeleteResult; ...@@ -6,6 +6,7 @@ use MongoDB\DeleteResult;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Operation\Delete; use MongoDB\Operation\Delete;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
...@@ -99,11 +100,11 @@ class DeleteFunctionalTest extends FunctionalTestCase ...@@ -99,11 +100,11 @@ class DeleteFunctionalTest extends FunctionalTestCase
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesDeletedCount(DeleteResult $result) public function testUnacknowledgedWriteConcernAccessesDeletedCount(DeleteResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getDeletedCount(); $result->getDeletedCount();
} }
......
...@@ -2,26 +2,27 @@ ...@@ -2,26 +2,27 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Delete; use MongoDB\Operation\Delete;
class DeleteTest extends TestCase class DeleteTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0); new Delete($this->getDatabaseName(), $this->getCollectionName(), $filter, 0);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $limit must be 0 or 1
* @dataProvider provideInvalidLimitValues * @dataProvider provideInvalidLimitValues
*/ */
public function testConstructorLimitArgumentMustBeOneOrZero($limit) public function testConstructorLimitArgumentMustBeOneOrZero($limit)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$limit must be 0 or 1');
new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit); new Delete($this->getDatabaseName(), $this->getCollectionName(), [], $limit);
} }
...@@ -31,11 +32,11 @@ class DeleteTest extends TestCase ...@@ -31,11 +32,11 @@ class DeleteTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Delete($this->getDatabaseName(), $this->getCollectionName(), [], 1, $options); new Delete($this->getDatabaseName(), $this->getCollectionName(), [], 1, $options);
} }
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Distinct; use MongoDB\Operation\Distinct;
class DistinctTest extends TestCase class DistinctTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', $filter); new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', $filter);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', [], $options); new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'x', [], $options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
class DropCollectionTest extends TestCase class DropCollectionTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new DropCollection($this->getDatabaseName(), $this->getCollectionName(), $options); new DropCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\DropDatabase; use MongoDB\Operation\DropDatabase;
class DropDatabaseTest extends TestCase class DropDatabaseTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new DropDatabase($this->getDatabaseName(), $options); new DropDatabase($this->getDatabaseName(), $options);
} }
......
...@@ -2,24 +2,23 @@ ...@@ -2,24 +2,23 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\DropIndexes; use MongoDB\Operation\DropIndexes;
class DropIndexesTest extends TestCase class DropIndexesTest extends TestCase
{ {
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public function testDropIndexShouldNotAllowEmptyIndexName() public function testDropIndexShouldNotAllowEmptyIndexName()
{ {
$this->expectException(InvalidArgumentException::class);
new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), ''); new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), '');
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), '*', $options); new DropIndexes($this->getDatabaseName(), $this->getCollectionName(), '*', $options);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Count; use MongoDB\Operation\Count;
use MongoDB\Operation\Distinct; use MongoDB\Operation\Distinct;
use MongoDB\Operation\Explain; use MongoDB\Operation\Explain;
...@@ -9,12 +10,12 @@ use MongoDB\Operation\Explain; ...@@ -9,12 +10,12 @@ use MongoDB\Operation\Explain;
class ExplainTest extends TestCase class ExplainTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$explainable = $this->getMockBuilder('MongoDB\Operation\Explainable')->getMock(); $explainable = $this->getMockBuilder('MongoDB\Operation\Explainable')->getMock();
$this->expectException(InvalidArgumentException::class);
new Explain($this->getDatabaseName(), $explainable, $options); new Explain($this->getDatabaseName(), $explainable, $options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\FindAndModify; use MongoDB\Operation\FindAndModify;
class FindAndModifyTest extends TestCase class FindAndModifyTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), $options); new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), $options);
} }
...@@ -78,12 +79,10 @@ class FindAndModifyTest extends TestCase ...@@ -78,12 +79,10 @@ class FindAndModifyTest extends TestCase
return $options; return $options;
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage The "remove" option must be true or an "update" document must be specified, but not both
*/
public function testConstructorUpdateAndRemoveOptionsAreMutuallyExclusive() public function testConstructorUpdateAndRemoveOptionsAreMutuallyExclusive()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "remove" option must be true or an "update" document must be specified, but not both');
new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), ['remove' => true, 'update' => []]); new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), ['remove' => true, 'update' => []]);
} }
} }
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\FindOneAndDelete; use MongoDB\Operation\FindOneAndDelete;
class FindOneAndDeleteTest extends TestCase class FindOneAndDeleteTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), $filter); new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), $filter);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), [], $options); new FindOneAndDelete($this->getDatabaseName(), $this->getCollectionName(), [], $options);
} }
......
...@@ -2,43 +2,42 @@ ...@@ -2,43 +2,42 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\FindOneAndReplace; use MongoDB\Operation\FindOneAndReplace;
class FindOneAndReplaceTest extends TestCase class FindOneAndReplaceTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), $filter, []); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), $filter, []);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorReplacementArgumentTypeCheck($replacement) public function testConstructorReplacementArgumentTypeCheck($replacement)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], $replacement);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $replacement argument is an update operator
*/
public function testConstructorReplacementArgumentRequiresNoOperators() public function testConstructorReplacementArgumentRequiresNoOperators()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $replacement argument is an update operator');
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], ['$set' => ['x' => 1]]); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], ['$set' => ['x' => 1]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], [], $options); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], [], $options);
} }
...@@ -58,11 +57,11 @@ class FindOneAndReplaceTest extends TestCase ...@@ -58,11 +57,11 @@ class FindOneAndReplaceTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorReturnDocumentOptions * @dataProvider provideInvalidConstructorReturnDocumentOptions
*/ */
public function testConstructorReturnDocumentOption($returnDocument) public function testConstructorReturnDocumentOption($returnDocument)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], [], ['returnDocument' => $returnDocument]); new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), [], [], ['returnDocument' => $returnDocument]);
} }
......
...@@ -2,43 +2,42 @@ ...@@ -2,43 +2,42 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\FindOneAndUpdate; use MongoDB\Operation\FindOneAndUpdate;
class FindOneAndUpdateTest extends TestCase class FindOneAndUpdateTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), $filter, []); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), $filter, []);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentTypeCheck($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], $update); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], $update);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
*/
public function testConstructorUpdateArgumentRequiresOperators() public function testConstructorUpdateArgumentRequiresOperators()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $update argument is not an update operator');
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], []); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], []);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], ['$set' => ['x' => 1]], $options); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], ['$set' => ['x' => 1]], $options);
} }
...@@ -58,11 +57,11 @@ class FindOneAndUpdateTest extends TestCase ...@@ -58,11 +57,11 @@ class FindOneAndUpdateTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorReturnDocumentOptions * @dataProvider provideInvalidConstructorReturnDocumentOptions
*/ */
public function testConstructorReturnDocumentOption($returnDocument) public function testConstructorReturnDocumentOption($returnDocument)
{ {
$this->expectException(InvalidArgumentException::class);
new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], [], ['returnDocument' => $returnDocument]); new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), [], [], ['returnDocument' => $returnDocument]);
} }
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Find; use MongoDB\Operation\Find;
class FindTest extends TestCase class FindTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new Find($this->getDatabaseName(), $this->getCollectionName(), $filter); new Find($this->getDatabaseName(), $this->getCollectionName(), $filter);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Find($this->getDatabaseName(), $this->getCollectionName(), [], $options); new Find($this->getDatabaseName(), $this->getCollectionName(), [], $options);
} }
...@@ -133,11 +134,11 @@ class FindTest extends TestCase ...@@ -133,11 +134,11 @@ class FindTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorCursorTypeOptions * @dataProvider provideInvalidConstructorCursorTypeOptions
*/ */
public function testConstructorCursorTypeOption($cursorType) public function testConstructorCursorTypeOption($cursorType)
{ {
$this->expectException(InvalidArgumentException::class);
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['cursorType' => $cursorType]); new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['cursorType' => $cursorType]);
} }
......
...@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation; ...@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\InsertManyResult; use MongoDB\InsertManyResult;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Operation\InsertMany; use MongoDB\Operation\InsertMany;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
...@@ -90,11 +91,11 @@ class InsertManyFunctionalTest extends FunctionalTestCase ...@@ -90,11 +91,11 @@ class InsertManyFunctionalTest extends FunctionalTestCase
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertManyResult $result) public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertManyResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getInsertedCount(); $result->getInsertedCount();
} }
......
...@@ -2,44 +2,41 @@ ...@@ -2,44 +2,41 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\InsertMany; use MongoDB\Operation\InsertMany;
class InsertManyTest extends TestCase class InsertManyTest extends TestCase
{ {
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $documents is empty
*/
public function testConstructorDocumentsMustNotBeEmpty() public function testConstructorDocumentsMustNotBeEmpty()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$documents is empty');
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), []); new InsertMany($this->getDatabaseName(), $this->getCollectionName(), []);
} }
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $documents is not a list (unexpected index: "1")
*/
public function testConstructorDocumentsMustBeAList() public function testConstructorDocumentsMustBeAList()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$documents is not a list (unexpected index: "1")');
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [1 => ['x' => 1]]); new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [1 => ['x' => 1]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$documents\[0\] to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorDocumentsArgumentElementTypeChecks($document) public function testConstructorDocumentsArgumentElementTypeChecks($document)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Expected \$documents[0\] to have type "array or object" but found "[\w ]+"/');
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [$document]); new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [$document]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [['x' => 1]], $options); new InsertMany($this->getDatabaseName(), $this->getCollectionName(), [['x' => 1]], $options);
} }
......
...@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation; ...@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\InsertOneResult; use MongoDB\InsertOneResult;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Operation\InsertOne; use MongoDB\Operation\InsertOne;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
...@@ -105,11 +106,11 @@ class InsertOneFunctionalTest extends FunctionalTestCase ...@@ -105,11 +106,11 @@ class InsertOneFunctionalTest extends FunctionalTestCase
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertOneResult $result) public function testUnacknowledgedWriteConcernAccessesInsertedCount(InsertOneResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getInsertedCount(); $result->getInsertedCount();
} }
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\InsertOne; use MongoDB\Operation\InsertOne;
class InsertOneTest extends TestCase class InsertOneTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorDocumentArgumentTypeCheck($document) public function testConstructorDocumentArgumentTypeCheck($document)
{ {
$this->expectException(InvalidArgumentException::class);
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document); new InsertOne($this->getDatabaseName(), $this->getCollectionName(), $document);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $options); new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\ListCollections; use MongoDB\Operation\ListCollections;
class ListCollectionsTest extends TestCase class ListCollectionsTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new ListCollections($this->getDatabaseName(), $options); new ListCollections($this->getDatabaseName(), $options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\ListDatabases; use MongoDB\Operation\ListDatabases;
class ListDatabasesTest extends TestCase class ListDatabasesTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new ListDatabases($options); new ListDatabases($options);
} }
......
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\ListIndexes; use MongoDB\Operation\ListIndexes;
class ListIndexesTest extends TestCase class ListIndexesTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new ListIndexes($this->getDatabaseName(), $this->getCollectionName(), $options); new ListIndexes($this->getDatabaseName(), $this->getCollectionName(), $options);
} }
......
...@@ -4,13 +4,13 @@ namespace MongoDB\Tests\Operation; ...@@ -4,13 +4,13 @@ namespace MongoDB\Tests\Operation;
use MongoDB\BSON\Javascript; use MongoDB\BSON\Javascript;
use MongoDB\BSON\ObjectId; use MongoDB\BSON\ObjectId;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\MapReduce; use MongoDB\Operation\MapReduce;
use stdClass; use stdClass;
class MapReduceTest extends TestCase class MapReduceTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidOutValues * @dataProvider provideInvalidOutValues
*/ */
public function testConstructorOutArgumentTypeCheck($out) public function testConstructorOutArgumentTypeCheck($out)
...@@ -18,6 +18,7 @@ class MapReduceTest extends TestCase ...@@ -18,6 +18,7 @@ class MapReduceTest extends TestCase
$map = new Javascript('function() { emit(this.x, this.y); }'); $map = new Javascript('function() { emit(this.x, this.y); }');
$reduce = new Javascript('function(key, values) { return Array.sum(values); }'); $reduce = new Javascript('function(key, values) { return Array.sum(values); }');
$this->expectException(InvalidArgumentException::class);
new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out); new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out);
} }
...@@ -27,7 +28,6 @@ class MapReduceTest extends TestCase ...@@ -27,7 +28,6 @@ class MapReduceTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
...@@ -36,6 +36,7 @@ class MapReduceTest extends TestCase ...@@ -36,6 +36,7 @@ class MapReduceTest extends TestCase
$reduce = new Javascript('function(key, values) { return Array.sum(values); }'); $reduce = new Javascript('function(key, values) { return Array.sum(values); }');
$out = ['inline' => 1]; $out = ['inline' => 1];
$this->expectException(InvalidArgumentException::class);
new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, $options); new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, $options);
} }
......
...@@ -2,26 +2,27 @@ ...@@ -2,26 +2,27 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Operation\ReplaceOne; use MongoDB\Operation\ReplaceOne;
class ReplaceOneTest extends TestCase class ReplaceOneTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['y' => 1]); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['y' => 1]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorReplacementArgumentTypeCheck($replacement) public function testConstructorReplacementArgumentTypeCheck($replacement)
{ {
$this->expectException(InvalidArgumentException::class);
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
} }
...@@ -35,12 +36,12 @@ class ReplaceOneTest extends TestCase ...@@ -35,12 +36,12 @@ class ReplaceOneTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $replacement argument is an update operator
* @dataProvider provideUpdateDocuments * @dataProvider provideUpdateDocuments
*/ */
public function testConstructorReplacementArgumentRequiresNoOperators($replacement) public function testConstructorReplacementArgumentRequiresNoOperators($replacement)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $replacement argument is an update operator');
new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
} }
......
...@@ -6,6 +6,7 @@ use MongoDB\Collection; ...@@ -6,6 +6,7 @@ use MongoDB\Collection;
use MongoDB\UpdateResult; use MongoDB\UpdateResult;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\BadMethodCallException;
use MongoDB\Operation\Update; use MongoDB\Operation\Update;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
...@@ -165,41 +166,41 @@ class UpdateFunctionalTest extends FunctionalTestCase ...@@ -165,41 +166,41 @@ class UpdateFunctionalTest extends FunctionalTestCase
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesMatchedCount(UpdateResult $result) public function testUnacknowledgedWriteConcernAccessesMatchedCount(UpdateResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getMatchedCount(); $result->getMatchedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesModifiedCount(UpdateResult $result) public function testUnacknowledgedWriteConcernAccessesModifiedCount(UpdateResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getModifiedCount(); $result->getModifiedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesUpsertedCount(UpdateResult $result) public function testUnacknowledgedWriteConcernAccessesUpsertedCount(UpdateResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getUpsertedCount(); $result->getUpsertedCount();
} }
/** /**
* @depends testUnacknowledgedWriteConcern * @depends testUnacknowledgedWriteConcern
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessageRegExp /[\w:\\]+ should not be called for an unacknowledged write result/
*/ */
public function testUnacknowledgedWriteConcernAccessesUpsertedId(UpdateResult $result) public function testUnacknowledgedWriteConcernAccessesUpsertedId(UpdateResult $result)
{ {
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessageRegExp('/[\w:\\\\]+ should not be called for an unacknowledged write result/');
$result->getUpsertedId(); $result->getUpsertedId();
} }
......
...@@ -2,26 +2,27 @@ ...@@ -2,26 +2,27 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Operation\UpdateMany; use MongoDB\Operation\UpdateMany;
class UpdateManyTest extends TestCase class UpdateManyTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentTypeCheck($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
$this->expectException(InvalidArgumentException::class);
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
} }
...@@ -35,12 +36,12 @@ class UpdateManyTest extends TestCase ...@@ -35,12 +36,12 @@ class UpdateManyTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
* @dataProvider provideReplacementDocuments * @dataProvider provideReplacementDocuments
*/ */
public function testConstructorUpdateArgumentRequiresOperators($replacement) public function testConstructorUpdateArgumentRequiresOperators($replacement)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $update argument is not an update operator');
new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); new UpdateMany($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
} }
......
...@@ -2,26 +2,27 @@ ...@@ -2,26 +2,27 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Operation\UpdateOne; use MongoDB\Operation\UpdateOne;
class UpdateOneTest extends TestCase class UpdateOneTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentTypeCheck($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
$this->expectException(InvalidArgumentException::class);
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
} }
...@@ -35,12 +36,12 @@ class UpdateOneTest extends TestCase ...@@ -35,12 +36,12 @@ class UpdateOneTest extends TestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage First key in $update argument is not an update operator
* @dataProvider provideReplacementDocuments * @dataProvider provideReplacementDocuments
*/ */
public function testConstructorUpdateArgumentRequiresOperators($replacement) public function testConstructorUpdateArgumentRequiresOperators($replacement)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('First key in $update argument is not an update operator');
new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement); new UpdateOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $replacement);
} }
......
...@@ -2,36 +2,37 @@ ...@@ -2,36 +2,37 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Update; use MongoDB\Operation\Update;
class UpdateTest extends TestCase class UpdateTest extends TestCase
{ {
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$filter to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorFilterArgumentTypeCheck($filter) public function testConstructorFilterArgumentTypeCheck($filter)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Expected \$filter to have type "array or object" but found "[\w ]+"/');
new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]); new Update($this->getDatabaseName(), $this->getCollectionName(), $filter, ['$set' => ['x' => 1]]);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /Expected \$update to have type "array or object" but found "[\w ]+"/
* @dataProvider provideInvalidDocumentValues * @dataProvider provideInvalidDocumentValues
*/ */
public function testConstructorUpdateArgumentTypeCheck($update) public function testConstructorUpdateArgumentTypeCheck($update)
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Expected \$update to have type "array or object" but found "[\w ]+"/');
new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update); new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $update);
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['y' => 1], $options); new Update($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], ['y' => 1], $options);
} }
......
...@@ -8,6 +8,7 @@ use MongoDB\Driver\Manager; ...@@ -8,6 +8,7 @@ use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\ConnectionTimeoutException; use MongoDB\Driver\Exception\ConnectionTimeoutException;
use MongoDB\Exception\ResumeTokenException;
use MongoDB\Operation\DatabaseCommand; use MongoDB\Operation\DatabaseCommand;
use MongoDB\Operation\InsertOne; use MongoDB\Operation\InsertOne;
use MongoDB\Operation\Watch; use MongoDB\Operation\Watch;
...@@ -305,14 +306,13 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -305,14 +306,13 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->assertFalse($cursor->isDead()); $this->assertFalse($cursor->isDead());
} }
/**
* @expectedException MongoDB\Exception\ResumeTokenException
* @expectedExceptionMessage Resume token not found in change document
*/
public function testNextResumeTokenNotFound() public function testNextResumeTokenNotFound()
{ {
$pipeline = [['$project' => ['_id' => 0 ]]]; $pipeline = [['$project' => ['_id' => 0 ]]];
$this->expectException(ResumeTokenException::class);
$this->expectExceptionMessage('Resume token not found in change document');
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
...@@ -323,14 +323,13 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -323,14 +323,13 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream->next(); $changeStream->next();
} }
/**
* @expectedException MongoDB\Exception\ResumeTokenException
* @expectedExceptionMessage Resume token not found in change document
*/
public function testRewindResumeTokenNotFound() public function testRewindResumeTokenNotFound()
{ {
$pipeline = [['$project' => ['_id' => 0 ]]]; $pipeline = [['$project' => ['_id' => 0 ]]];
$this->expectException(ResumeTokenException::class);
$this->expectExceptionMessage('Resume token not found in change document');
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
...@@ -339,14 +338,13 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -339,14 +338,13 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream->rewind(); $changeStream->rewind();
} }
/**
* @expectedException MongoDB\Exception\ResumeTokenException
* @expectedExceptionMessage Expected resume token to have type "array or object" but found "string"
*/
public function testNextResumeTokenInvalidType() public function testNextResumeTokenInvalidType()
{ {
$pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]]; $pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]];
$this->expectException(ResumeTokenException::class);
$this->expectExceptionMessage('Expected resume token to have type "array or object" but found "string"');
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
...@@ -357,14 +355,13 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -357,14 +355,13 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream->next(); $changeStream->next();
} }
/**
* @expectedException MongoDB\Exception\ResumeTokenException
* @expectedExceptionMessage Expected resume token to have type "array or object" but found "string"
*/
public function testRewindResumeTokenInvalidType() public function testRewindResumeTokenInvalidType()
{ {
$pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]]; $pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]];
$this->expectException(ResumeTokenException::class);
$this->expectExceptionMessage('Expected resume token to have type "array or object" but found "string"');
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Operation\Watch; use MongoDB\Operation\Watch;
/** /**
...@@ -10,12 +11,11 @@ use MongoDB\Operation\Watch; ...@@ -10,12 +11,11 @@ use MongoDB\Operation\Watch;
*/ */
class WatchTest extends FunctionalTestCase class WatchTest extends FunctionalTestCase
{ {
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $pipeline is not a list (unexpected index: "foo")
*/
public function testConstructorPipelineArgumentMustBeAList() public function testConstructorPipelineArgumentMustBeAList()
{ {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('$pipeline is not a list (unexpected index: "foo")');
/* Note: Watch uses array_unshift() to prepend the $changeStream stage /* Note: Watch uses array_unshift() to prepend the $changeStream stage
* to the pipeline. Since array_unshift() reindexes numeric keys, we'll * to the pipeline. Since array_unshift() reindexes numeric keys, we'll
* use a string key to test for this exception. */ * use a string key to test for this exception. */
...@@ -23,11 +23,11 @@ class WatchTest extends FunctionalTestCase ...@@ -23,11 +23,11 @@ class WatchTest extends FunctionalTestCase
} }
/** /**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions * @dataProvider provideInvalidConstructorOptions
*/ */
public function testConstructorOptionTypeChecks(array $options) public function testConstructorOptionTypeChecks(array $options)
{ {
$this->expectException(InvalidArgumentException::class);
new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $options); new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $options);
} }
......
...@@ -11,6 +11,33 @@ use stdClass; ...@@ -11,6 +11,33 @@ use stdClass;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
public function expectException($exception)
{
if (method_exists(BaseTestCase::class, 'expectException')) {
parent::expectException($exception);
return;
}
parent::setExpectedException($exception);
}
public function expectExceptionMessage($exceptionMessage)
{
if (method_exists(BaseTestCase::class, 'expectExceptionMessage')) {
parent::expectExceptionMessage($exceptionMessage);
return;
}
parent::setExpectedException($this->getExpectedException(), $exceptionMessage);
}
public function expectExceptionMessageRegExp($exceptionMessageRegExp)
{
if (method_exists(BaseTestCase::class, 'expectExceptionMessageRegExp')) {
parent::expectExceptionMessageRegExp($exceptionMessageRegExp);
return;
}
parent::setExpectedExceptionRegExp($this->getExpectedException(), $exceptionMessageRegExp);
}
public function provideInvalidArrayValues() public function provideInvalidArrayValues()
{ {
return $this->wrapValuesForDataProvider($this->getInvalidArrayValues()); return $this->wrapValuesForDataProvider($this->getInvalidArrayValues());
......
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