Commit 6cd31063 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-377: Use majority WC to drop test collections for transactions

parent 798d510a
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace MongoDB\Tests\Collection; namespace MongoDB\Tests\Collection;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Operation\DropCollection; use MongoDB\Driver\WriteConcern;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
/** /**
...@@ -18,8 +18,8 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -18,8 +18,8 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
parent::setUp(); parent::setUp();
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName()); $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
$operation->execute($this->getPrimaryServer()); $this->dropCollection();
} }
public function tearDown() public function tearDown()
...@@ -28,7 +28,15 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -28,7 +28,15 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
return; return;
} }
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); $this->dropCollection();
$operation->execute($this->getPrimaryServer()); }
private function dropCollection()
{
$options = version_compare($this->getServerVersion(), '3.4.0', '>=')
? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
: [];
$this->collection->drop($options);
} }
} }
...@@ -6,6 +6,7 @@ use MongoDB\Client; ...@@ -6,6 +6,7 @@ use MongoDB\Client;
use MongoDB\Database; use MongoDB\Database;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Driver\Server; use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
use MongoDB\Operation\DropDatabase; use MongoDB\Operation\DropDatabase;
...@@ -20,8 +21,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -20,8 +21,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
{ {
parent::setUp(); parent::setUp();
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); $this->dropCollection();
$operation->execute($this->getPrimaryServer());
} }
public function tearDown() public function tearDown()
...@@ -30,8 +30,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -30,8 +30,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
return; return;
} }
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); $this->dropCollection();
$operation->execute($this->getPrimaryServer());
} }
public function testExample_1_2() public function testExample_1_2()
...@@ -1429,4 +1428,14 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -1429,4 +1428,14 @@ class DocumentationExamplesTest extends FunctionalTestCase
{ {
$this->assertCollectionCount($this->getDatabaseName() . '.' . $this->getCollectionName(), $count); $this->assertCollectionCount($this->getDatabaseName() . '.' . $this->getCollectionName(), $count);
} }
private function dropCollection()
{
$options = version_compare($this->getServerVersion(), '3.4.0', '>=')
? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
: [];
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
$operation->execute($this->getPrimaryServer());
}
} }
...@@ -18,8 +18,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -18,8 +18,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
parent::setUp(); parent::setUp();
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); $this->dropCollection();
$operation->execute($this->getPrimaryServer());
} }
public function tearDown() public function tearDown()
...@@ -28,8 +27,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -28,8 +27,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
return; return;
} }
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName()); $this->dropCollection();
$operation->execute($this->getPrimaryServer());
} }
protected function createDefaultReadConcern() protected function createDefaultReadConcern()
...@@ -46,4 +44,14 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -46,4 +44,14 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
return $this->manager->startSession(); return $this->manager->startSession();
} }
private function dropCollection()
{
$options = version_compare($this->getServerVersion(), '3.4.0', '>=')
? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
: [];
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
$operation->execute($this->getPrimaryServer());
}
} }
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