Skip to content

Commit 2b20dfa

Browse files
committed
Rename ChangeStream operation to Watch
This makes the operation consistent with the Collection method name and avoids the naming conflict with the ChangeStream iterator class.
1 parent 0e1516b commit 2b20dfa

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/Collection.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use MongoDB\BSON\JavascriptInterface;
2121
use MongoDB\BSON\Serializable;
22-
use MongoDB\ChangeStream as ChangeStreamResult;
22+
use MongoDB\ChangeStream;
2323
use MongoDB\Driver\Cursor;
2424
use MongoDB\Driver\Manager;
2525
use MongoDB\Driver\ReadConcern;
@@ -32,7 +32,6 @@
3232
use MongoDB\Model\IndexInfoIterator;
3333
use MongoDB\Operation\Aggregate;
3434
use MongoDB\Operation\BulkWrite;
35-
use MongoDB\Operation\ChangeStream;
3635
use MongoDB\Operation\CreateIndexes;
3736
use MongoDB\Operation\Count;
3837
use MongoDB\Operation\DeleteMany;
@@ -52,6 +51,7 @@
5251
use MongoDB\Operation\ReplaceOne;
5352
use MongoDB\Operation\UpdateMany;
5453
use MongoDB\Operation\UpdateOne;
54+
use MongoDB\Operation\Watch;
5555
use Traversable;
5656

5757
class Collection
@@ -939,14 +939,14 @@ public function updateOne($filter, $update, array $options = [])
939939
return $operation->execute($server);
940940
}
941941

942-
/*
943-
* ChangeStream outline
942+
/**
943+
* Create a change stream for watching changes to the collection.
944944
*
945-
* @see ChangeStream::__construct() for supported options
946-
* @param array $pipeline List of pipeline operations
947-
* @param array $options Command options
945+
* @see Watch::__construct() for supported options
946+
* @param array $pipeline List of pipeline operations
947+
* @param array $options Command options
948+
* @return ChangeStream
948949
* @throws InvalidArgumentException for parameter/option parsing errors
949-
* @return ChangeStreamResult
950950
*/
951951
public function watch(array $pipeline = [], array $options = [])
952952
{
@@ -960,7 +960,7 @@ public function watch(array $pipeline = [], array $options = [])
960960
$options['readConcern'] = $this->readConcern;
961961
}
962962

963-
$operation = new ChangeStream($this->databaseName, $this->collectionName, $pipeline, $options, $this->manager);
963+
$operation = new Watch($this->databaseName, $this->collectionName, $pipeline, $options, $this->manager);
964964

965965
return $operation->execute($server);
966966
}

src/Operation/ChangeStream.php renamed to src/Operation/Watch.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace MongoDB\Operation;
1919

20-
use MongoDB\ChangeStream as ChangeStreamResult;
20+
use MongoDB\ChangeStream;
2121
use MongoDB\Driver\Command;
2222
use MongoDB\Driver\Manager;
2323
use MongoDB\Driver\ReadConcern;
@@ -35,7 +35,7 @@
3535
* @see \MongoDB\Collection::changeStream()
3636
* @see http://docs.mongodb.org/manual/reference/command/changeStream/
3737
*/
38-
class ChangeStream implements Executable
38+
class Watch implements Executable
3939
{
4040
const FULL_DOCUMENT_DEFAULT = 'default';
4141
const FULL_DOCUMENT_UPDATE_LOOKUP = 'updateLookup';
@@ -131,7 +131,7 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
131131
*
132132
* @see Executable::execute()
133133
* @param Server $server
134-
* @return ChangeStreamResult
134+
* @return ChangeStream
135135
* @throws UnexpectedValueException if the command response was malformed
136136
* @throws UnsupportedException if collation, read concern, or write concern is used and unsupported
137137
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -142,7 +142,7 @@ public function execute(Server $server)
142142

143143
$cursor = $command->execute($server);
144144

145-
return new ChangeStreamResult($cursor, $this->createResumeCallable());
145+
return new ChangeStream($cursor, $this->createResumeCallable());
146146
}
147147

148148
private function createAggregateOptions()

tests/DocumentationExamplesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ public function testChangeStreamExample_1_4()
938938
$this->assertNull($current);
939939

940940
// Start Changestream Example 2
941-
$cursor = $db->inventory->watch([], ['fullDocument' => \MongoDB\Operation\ChangeStream::FULL_DOCUMENT_UPDATE_LOOKUP]);
941+
$cursor = $db->inventory->watch([], ['fullDocument' => \MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP]);
942942
$cursor->next();
943943
$current = $cursor->current();
944944
// End Changestream Example 2

tests/Operation/ChangeStreamFunctionalTest.php renamed to tests/Operation/WatchFunctionalTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use MongoDB\Collection;
77
use MongoDB\Operation\DatabaseCommand;
88

9-
class ChangeStreamFunctionalTest extends FunctionalTestCase
9+
class WatchFunctionalTest extends FunctionalTestCase
1010
{
1111
public function setUp()
1212
{
@@ -37,7 +37,7 @@ public function testResume()
3737
'_id' => $changeStreamResult->current()->_id,
3838
'operationType' => 'insert',
3939
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 2],
40-
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'ChangeStreamFunctionalTest.e68b9f01'],
40+
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'],
4141
'documentKey' => (object) ['_id' => $result->getInsertedId()]
4242
]);
4343
$this->assertEquals($changeStreamResult->current(), $expectedResult);
@@ -54,7 +54,7 @@ public function testResume()
5454
'_id' => $changeStreamResult->current()->_id,
5555
'operationType' => 'insert',
5656
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 3],
57-
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'ChangeStreamFunctionalTest.e68b9f01'],
57+
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'],
5858
'documentKey' => (object) ['_id' => $result->getInsertedId()]
5959
]);
6060
$this->assertEquals($changeStreamResult->current(), $expectedResult);
@@ -81,7 +81,7 @@ public function testNoChangeAfterResumeBeforeInsert()
8181
'_id' => $changeStreamResult->current()->_id,
8282
'operationType' => 'insert',
8383
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 2],
84-
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'ChangeStreamFunctionalTest.4a554985'],
84+
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'],
8585
'documentKey' => (object) ['_id' => $result->getInsertedId()]
8686
]);
8787
$this->assertEquals($changeStreamResult->current(), $expectedResult);
@@ -101,7 +101,7 @@ public function testNoChangeAfterResumeBeforeInsert()
101101
'_id' => $changeStreamResult->current()->_id,
102102
'operationType' => 'insert',
103103
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 3],
104-
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'ChangeStreamFunctionalTest.4a554985'],
104+
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'],
105105
'documentKey' => (object) ['_id' => $result->getInsertedId()]
106106
]);
107107
$this->assertEquals($changeStreamResult->current(), $expectedResult);
@@ -232,7 +232,7 @@ public function testConnectionException()
232232
'_id' => $changeStreamResult->current()->_id,
233233
'operationType' => 'insert',
234234
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 1],
235-
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'ChangeStreamFunctionalTest.226d95f1'],
235+
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.226d95f1'],
236236
'documentKey' => (object) ['_id' => $result->getInsertedId()]
237237
]);
238238
$this->assertEquals($changeStreamResult->current(), $expectedResult);

0 commit comments

Comments
 (0)