|
6 | 6 | use MongoDB\Driver\Cursor;
|
7 | 7 | use MongoDB\Driver\Manager;
|
8 | 8 | use MongoDB\Driver\ReadPreference;
|
| 9 | +use MongoDB\Driver\Server; |
9 | 10 | use stdClass;
|
10 | 11 | use UnexpectedValueException;
|
11 | 12 |
|
@@ -95,4 +96,41 @@ protected function getServerVersion(ReadPreference $readPreference = null)
|
95 | 96 |
|
96 | 97 | throw new UnexpectedValueException('Could not determine server version');
|
97 | 98 | }
|
| 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 | + } |
98 | 136 | }
|
0 commit comments