Skip to content

Commit 5076ff1

Browse files
committed
Do not check modifiedCount for updates on 2.4
nModified is not provided for legacy write ops, so we should not check for it. Once PHPC-278 is implemented, we can change these assertions to check for null exactly.
1 parent 4e22eb2 commit 5076ff1

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

tests/Collection/CrudSpec/ReplaceOneFunctionalTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
*/
1010
class ReplaceOneFunctionalTest extends FunctionalTestCase
1111
{
12+
private $omitModifiedCount;
13+
1214
public function setUp()
1315
{
1416
parent::setUp();
1517

1618
$this->createFixtures(3);
19+
20+
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
1721
}
1822

1923
public function testReplaceOneWhenManyDocumentsMatch()
@@ -23,7 +27,7 @@ public function testReplaceOneWhenManyDocumentsMatch()
2327

2428
$result = $this->collection->replaceOne($filter, $replacement);
2529
$this->assertSame(1, $result->getMatchedCount());
26-
$this->assertSame(1, $result->getModifiedCount());
30+
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
2731

2832
$expected = array(
2933
array('_id' => 1, 'x' => 11),
@@ -41,7 +45,7 @@ public function testReplaceOneWhenOneDocumentMatches()
4145

4246
$result = $this->collection->replaceOne($filter, $replacement);
4347
$this->assertSame(1, $result->getMatchedCount());
44-
$this->assertSame(1, $result->getModifiedCount());
48+
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
4549

4650
$expected = array(
4751
array('_id' => 1, 'x' => 111),
@@ -59,7 +63,7 @@ public function testReplaceOneWhenNoDocumentsMatch()
5963

6064
$result = $this->collection->replaceOne($filter, $replacement);
6165
$this->assertSame(0, $result->getMatchedCount());
62-
$this->assertSame(0, $result->getModifiedCount());
66+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
6367

6468
$expected = array(
6569
array('_id' => 1, 'x' => 11),
@@ -78,7 +82,7 @@ public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithAnIdSpecified()
7882

7983
$result = $this->collection->replaceOne($filter, $replacement, $options);
8084
$this->assertSame(0, $result->getMatchedCount());
81-
$this->assertSame(0, $result->getModifiedCount());
85+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
8286
$this->assertSame(4, $result->getUpsertedId());
8387

8488
$expected = array(
@@ -100,7 +104,7 @@ public function testReplaceOneWithUpsertWhenNoDocumentsMatchWithoutAnIdSpecified
100104

101105
$result = $this->collection->replaceOne($filter, $replacement, $options);
102106
$this->assertSame(0, $result->getMatchedCount());
103-
$this->assertSame(0, $result->getModifiedCount());
107+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
104108
$this->assertSame(4, $result->getUpsertedId());
105109

106110
$expected = array(

tests/Collection/CrudSpec/UpdateManyFunctionalTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
*/
1010
class UpdateManyFunctionalTest extends FunctionalTestCase
1111
{
12+
private $omitModifiedCount;
13+
1214
public function setUp()
1315
{
1416
parent::setUp();
1517

1618
$this->createFixtures(3);
19+
20+
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
1721
}
1822

1923
public function testUpdateManyWhenManyDocumentsMatch()
@@ -23,7 +27,7 @@ public function testUpdateManyWhenManyDocumentsMatch()
2327

2428
$result = $this->collection->updateMany($filter, $update);
2529
$this->assertSame(2, $result->getMatchedCount());
26-
$this->assertSame(2, $result->getModifiedCount());
30+
$this->omitModifiedCount or $this->assertSame(2, $result->getModifiedCount());
2731

2832
$expected = array(
2933
array('_id' => 1, 'x' => 11),
@@ -41,7 +45,7 @@ public function testUpdateManyWhenOneDocumentMatches()
4145

4246
$result = $this->collection->updateMany($filter, $update);
4347
$this->assertSame(1, $result->getMatchedCount());
44-
$this->assertSame(1, $result->getModifiedCount());
48+
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
4549

4650
$expected = array(
4751
array('_id' => 1, 'x' => 12),
@@ -59,7 +63,7 @@ public function testUpdateManyWhenNoDocumentsMatch()
5963

6064
$result = $this->collection->updateMany($filter, $update);
6165
$this->assertSame(0, $result->getMatchedCount());
62-
$this->assertSame(0, $result->getModifiedCount());
66+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
6367

6468
$expected = array(
6569
array('_id' => 1, 'x' => 11),
@@ -78,7 +82,7 @@ public function testUpdateManyWithUpsertWhenNoDocumentsMatch()
7882

7983
$result = $this->collection->updateMany($filter, $update, $options);
8084
$this->assertSame(0, $result->getMatchedCount());
81-
$this->assertSame(0, $result->getModifiedCount());
85+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
8286
$this->assertSame(4, $result->getUpsertedId());
8387

8488
$expected = array(

tests/Collection/CrudSpec/UpdateOneFunctionalTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
*/
1010
class UpdateOneFunctionalTest extends FunctionalTestCase
1111
{
12+
private $omitModifiedCount;
13+
1214
public function setUp()
1315
{
1416
parent::setUp();
1517

1618
$this->createFixtures(3);
19+
20+
$this->omitModifiedCount = version_compare($this->getServerVersion(), '2.6.0', '<');
1721
}
1822

1923
public function testUpdateOneWhenManyDocumentsMatch()
@@ -23,7 +27,7 @@ public function testUpdateOneWhenManyDocumentsMatch()
2327

2428
$result = $this->collection->updateOne($filter, $update);
2529
$this->assertSame(1, $result->getMatchedCount());
26-
$this->assertSame(1, $result->getModifiedCount());
30+
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
2731

2832
$expected = array(
2933
array('_id' => 1, 'x' => 11),
@@ -41,7 +45,7 @@ public function testUpdateOneWhenOneDocumentMatches()
4145

4246
$result = $this->collection->updateOne($filter, $update);
4347
$this->assertSame(1, $result->getMatchedCount());
44-
$this->assertSame(1, $result->getModifiedCount());
48+
$this->omitModifiedCount or $this->assertSame(1, $result->getModifiedCount());
4549

4650
$expected = array(
4751
array('_id' => 1, 'x' => 12),
@@ -59,7 +63,7 @@ public function testUpdateOneWhenNoDocumentsMatch()
5963

6064
$result = $this->collection->updateOne($filter, $update);
6165
$this->assertSame(0, $result->getMatchedCount());
62-
$this->assertSame(0, $result->getModifiedCount());
66+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
6367

6468
$expected = array(
6569
array('_id' => 1, 'x' => 11),
@@ -78,7 +82,7 @@ public function testUpdateOneWithUpsertWhenNoDocumentsMatch()
7882

7983
$result = $this->collection->updateOne($filter, $update, $options);
8084
$this->assertSame(0, $result->getMatchedCount());
81-
$this->assertSame(0, $result->getModifiedCount());
85+
$this->omitModifiedCount or $this->assertSame(0, $result->getModifiedCount());
8286
$this->assertSame(4, $result->getUpsertedId());
8387

8488
$expected = array(

tests/FunctionalTestCase.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace MongoDB\Tests;
44

55
use MongoDB\Driver\Command;
6-
use MongoDB\Driver\Manager;
76
use MongoDB\Driver\Cursor;
7+
use MongoDB\Driver\Manager;
8+
use MongoDB\Driver\ReadPreference;
89

910
abstract class FunctionalTestCase extends TestCase
1011
{
@@ -32,4 +33,17 @@ protected function assertCommandSucceeded(Cursor $cursor)
3233
$this->assertArrayHasKey('ok', $document);
3334
$this->assertEquals(1, $document['ok']);
3435
}
36+
37+
protected function getServerVersion(ReadPreference $readPreference = null)
38+
{
39+
$cursor = $this->manager->executeCommand(
40+
$this->getDatabaseName(),
41+
new Command(array('buildInfo' => 1)),
42+
$readPreference ?: new ReadPreference(ReadPreference::RP_PRIMARY)
43+
);
44+
45+
$document = current($cursor->toArray());
46+
47+
return $document['version'];
48+
}
3549
}

0 commit comments

Comments
 (0)