Skip to content

Commit f4b5a6f

Browse files
committed
Merge pull request #563
2 parents 9813df1 + 602c12c commit f4b5a6f

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

tests/DocumentationExamplesTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,12 +1230,7 @@ private function updateEmployeeInfo1(\MongoDB\Client $client, \MongoDB\Driver\Se
12301230

12311231
public function testTransactions_intro_example_1()
12321232
{
1233-
if ($this->getPrimaryServer()->getType() === Server::TYPE_STANDALONE) {
1234-
$this->markTestSkipped('Transactions are not supported on standalone servers');
1235-
}
1236-
if (version_compare($this->getFeatureCompatibilityVersion(), '4.0', '<')) {
1237-
$this->markTestSkipped('Transactions are only supported on FCV 4.0 or higher');
1238-
}
1233+
$this->skipIfTransactionsAreNotSupported();
12391234

12401235
$client = new Client($this->getUri());
12411236

@@ -1395,12 +1390,7 @@ private function doUpdateEmployeeInfo(\MongoDB\Client $client)
13951390

13961391
public function testTransactions_retry_example_3()
13971392
{
1398-
if ($this->getPrimaryServer()->getType() === Server::TYPE_STANDALONE) {
1399-
$this->markTestSkipped('Transactions are not supported on standalone servers');
1400-
}
1401-
if (version_compare($this->getFeatureCompatibilityVersion(), '4.0', '<')) {
1402-
$this->markTestSkipped('Transactions are only supported on FCV 4.0 or higher');
1403-
}
1393+
$this->skipIfTransactionsAreNotSupported();
14041394

14051395
$client = new Client($this->getUri());
14061396

tests/FunctionalTestCase.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use MongoDB\Driver\Cursor;
77
use MongoDB\Driver\Manager;
88
use MongoDB\Driver\ReadPreference;
9+
use MongoDB\Driver\Server;
910
use stdClass;
1011
use UnexpectedValueException;
1112

@@ -95,4 +96,41 @@ protected function getServerVersion(ReadPreference $readPreference = null)
9596

9697
throw new UnexpectedValueException('Could not determine server version');
9798
}
99+
100+
protected function getServerStorageEngine(ReadPreference $readPreference = null)
101+
{
102+
$cursor = $this->manager->executeCommand(
103+
$this->getDatabaseName(),
104+
new Command(['serverStatus' => 1]),
105+
$readPreference ?: new ReadPreference('primary')
106+
);
107+
108+
$result = current($cursor->toArray());
109+
110+
if (isset($result->storageEngine->name) && is_string($result->storageEngine->name)) {
111+
return $result->storageEngine->name;
112+
}
113+
114+
throw new UnexpectedValueException('Could not determine server storage engine');
115+
}
116+
117+
protected function skipIfTransactionsAreNotSupported()
118+
{
119+
if ($this->getPrimaryServer()->getType() === Server::TYPE_STANDALONE) {
120+
$this->markTestSkipped('Transactions are not supported on standalone servers');
121+
}
122+
123+
// TODO: MongoDB 4.2 should support sharded clusters (see: PHPLIB-374)
124+
if ($this->getPrimaryServer()->getType() === Server::TYPE_MONGOS) {
125+
$this->markTestSkipped('Transactions are not supported on sharded clusters');
126+
}
127+
128+
if (version_compare($this->getFeatureCompatibilityVersion(), '4.0', '<')) {
129+
$this->markTestSkipped('Transactions are only supported on FCV 4.0 or higher');
130+
}
131+
132+
if ($this->getServerStorageEngine() !== 'wiredTiger') {
133+
$this->markTestSkipped('Transactions require WiredTiger storage engine');
134+
}
135+
}
98136
}

0 commit comments

Comments
 (0)