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

Fixed incorrect variable usage in MongoDbResourceManager #128

Merged
merged 2 commits into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/Storage/Adapter/MongoDbResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public function setServer($id, $server)
{
$this->resources[$id]['server'] = (string)$server;

unset($this->resource[$id]['client_instance']);
unset($this->resource[$id]['db_instance']);
unset($this->resource[$id]['collection_instance']);
unset($this->resources[$id]['client_instance']);
unset($this->resources[$id]['db_instance']);
unset($this->resources[$id]['collection_instance']);
}

public function getServer($id)
Expand All @@ -135,9 +135,9 @@ public function setConnectionOptions($id, array $connectionOptions)
{
$this->resources[$id]['connection_options'] = $connectionOptions;

unset($this->resource[$id]['client_instance']);
unset($this->resource[$id]['db_instance']);
unset($this->resource[$id]['collection_instance']);
unset($this->resources[$id]['client_instance']);
unset($this->resources[$id]['db_instance']);
unset($this->resources[$id]['collection_instance']);
}

public function getConnectionOptions($id)
Expand All @@ -155,9 +155,9 @@ public function setDriverOptions($id, array $driverOptions)
{
$this->resources[$id]['driver_options'] = $driverOptions;

unset($this->resource[$id]['client_instance']);
unset($this->resource[$id]['db_instance']);
unset($this->resource[$id]['collection_instance']);
unset($this->resources[$id]['client_instance']);
unset($this->resources[$id]['db_instance']);
unset($this->resources[$id]['collection_instance']);
}

public function getDriverOptions($id)
Expand All @@ -173,8 +173,8 @@ public function setDatabase($id, $database)
{
$this->resources[$id]['db'] = (string)$database;

unset($this->resource[$id]['db_instance']);
unset($this->resource[$id]['collection_instance']);
unset($this->resources[$id]['db_instance']);
unset($this->resources[$id]['collection_instance']);
}

public function getDatabase($id)
Expand All @@ -190,7 +190,7 @@ public function setCollection($id, $collection)
{
$this->resources[$id]['collection'] = (string)$collection;

unset($this->resource[$id]['collection_instance']);
unset($this->resources[$id]['collection_instance']);
}

public function getCollection($id)
Expand Down
43 changes: 43 additions & 0 deletions test/Storage/Adapter/MongoDbResourceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,47 @@ public function testGetResourceUnknownServerThrowsException()
$this->setExpectedException('Zend\Cache\Exception\RuntimeException');
$this->object->getResource($id);
}

public function testSetOptionsClearsCollectionInstance()
{
$id = 'foo';
$server = getenv('TESTS_ZEND_CACHE_MONGODB_CONNECTSTRING');
$connectionOptions = ['connectTimeoutMS' => 500];
$database = getenv('TESTS_ZEND_CACHE_MONGODB_DATABASE');
$collection = getenv('TESTS_ZEND_CACHE_MONGODB_COLLECTION');

$collectionClearingCallbacks = [
function () use ($id, $collection) {
$this->object->setCollection($id, $collection);
},
function () use ($id, $connectionOptions) {
$this->object->setConnectionOptions($id, $connectionOptions);
},
function () use ($id, $server) {
$this->object->setServer($id, $server);
},
function () use ($id) {
$this->object->setDriverOptions($id, []);
},
function () use ($id, $database) {
$this->object->setDatabase($id, $database);
},
];

// Initialize the resource manager
array_walk($collectionClearingCallbacks, function (callable $callback) {
$callback();
});

$lastCollection = $this->object->getResource($id);

// Update options on the manager and check collection instances
foreach ($collectionClearingCallbacks as $callback) {
$callback();
$currentCollection = $this->object->getResource($id);

$this->assertNotSame($lastCollection, $currentCollection);
$lastCollection = $currentCollection;
}
}
}