Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored and Ocramius committed Jul 28, 2014
1 parent bfab3bd commit 98a5f68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/SaveHandler/MongoDBOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public function setSaveOptions(array $saveOptions)
*/
public function getSaveOptions()
{
if ($this->saveOptions == array('w' => 1) && version_compare(phpversion('mongo'), '1.3.0', '<')) {
$this->saveOptions = array('safe' => true);
}
return $this->saveOptions;
}

Expand Down
13 changes: 8 additions & 5 deletions test/SaveHandler/MongoDBOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function testDefaults()
$options = new MongoDBOptions();
$this->assertNull($options->getDatabase());
$this->assertNull($options->getCollection());
$this->assertEquals(array('w' => true), $options->getSaveOptions());
$defaultSaveOptions = version_compare(phpversion('mongo'), '1.3.0', '<') ? array('safe' => true) : array('w' => true);
$this->assertEquals($defaultSaveOptions, $options->getSaveOptions());
$this->assertEquals('name', $options->getNameField());
$this->assertEquals('data', $options->getDataField());
$this->assertEquals('lifetime', $options->getLifetimeField());
Expand All @@ -31,10 +32,11 @@ public function testDefaults()

public function testSetConstructor()
{
$defaultSaveOptions = version_compare(phpversion('mongo'), '1.3.0', '<') ? array('safe' => 2) : array('w' => 2);
$options = new MongoDBOptions(array(
'database' => 'testDatabase',
'collection' => 'testCollection',
'saveOptions' => array('w' => 2),
'saveOptions' => $defaultSaveOptions,
'nameField' => 'testName',
'dataField' => 'testData',
'lifetimeField' => 'testLifetime',
Expand All @@ -43,7 +45,7 @@ public function testSetConstructor()

$this->assertEquals('testDatabase', $options->getDatabase());
$this->assertEquals('testCollection', $options->getCollection());
$this->assertEquals(array('w' => 2), $options->getSaveOptions());
$this->assertEquals($defaultSaveOptions, $options->getSaveOptions());
$this->assertEquals('testName', $options->getNameField());
$this->assertEquals('testData', $options->getDataField());
$this->assertEquals('testLifetime', $options->getLifetimeField());
Expand All @@ -52,18 +54,19 @@ public function testSetConstructor()

public function testSetters()
{
$defaultSaveOptions = version_compare(phpversion('mongo'), '1.3.0', '<') ? array('safe' => 2) : array('w' => 2);
$options = new MongoDBOptions();
$options->setDatabase('testDatabase')
->setCollection('testCollection')
->setSaveOptions(array('w' => 2))
->setSaveOptions($defaultSaveOptions)
->setNameField('testName')
->setDataField('testData')
->setLifetimeField('testLifetime')
->setModifiedField('testModified');

$this->assertEquals('testDatabase', $options->getDatabase());
$this->assertEquals('testCollection', $options->getCollection());
$this->assertEquals(array('w' => 2), $options->getSaveOptions());
$this->assertEquals($defaultSaveOptions, $options->getSaveOptions());
$this->assertEquals('testName', $options->getNameField());
$this->assertEquals('testData', $options->getDataField());
$this->assertEquals('testLifetime', $options->getLifetimeField());
Expand Down

0 comments on commit 98a5f68

Please sign in to comment.