Skip to content

Commit

Permalink
Properly set the document
Browse files Browse the repository at this point in the history
  • Loading branch information
kschroeder committed Dec 30, 2017
1 parent 5151a84 commit 98cf0c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/Config/Storage/Mongo.php
Expand Up @@ -46,9 +46,12 @@ public function setValue($path, $value, $context = ConfigurationRepository::CONT
]);
$paths = explode('/', $path);
if ($document === null) {
$document = [];
$document = [
'context' => $context,
'document'=> []
];
}
$document[$paths[0]][$paths[1]][$paths[2]] = $value;
$document['document'][$paths[0]][$paths[1]][$paths[2]] = $value;
if (isset($document['_id'])) {
$this->mongo->replaceOne(['_id' => $document['_id']], $document);
return;
Expand Down
12 changes: 9 additions & 3 deletions tests/Storage/MongoTest.php
Expand Up @@ -55,7 +55,10 @@ public function testSetOnNewDocument()
'context' => ConfigInterface::CONTEXT_DEFAULT
]);
$collection->expects(self::once())->method('insertOne')->willReturn(null)->with([
'a' => ['b' => ['c' => true]]
'context' => ConfigInterface::CONTEXT_DEFAULT,
'document' => [
'a' => ['b' => ['c' => true]]
]
]);
$mongo = new Mongo($collection);
$mongo->setValue('a/b/c', true);
Expand All @@ -65,10 +68,13 @@ public function testSetOnExistingDocument()
{
$storageDocument = new BSONDocument([
'_id' => new ObjectId(),
'a' => ['b' => ['c' => true]]
'context' => ConfigInterface::CONTEXT_DEFAULT,
'document' => [
'a' => ['b' => ['c' => true]]
]
]);
$storageDocumentTest = clone $storageDocument;
$storageDocumentTest['a']['b']['c'] = false;
$storageDocumentTest['document']['a']['b']['c'] = false;
$collection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()
->setMethods(['findOne', 'replaceOne'])->getMock();
$collection->expects(self::once())->method('findOne')->willReturn($storageDocument)->with(
Expand Down

0 comments on commit 98cf0c9

Please sign in to comment.