Inital commit for unit test configuration

This commit is contained in:
Manish Verma
2018-09-05 12:36:46 +05:30
committed by Manish Verma
parent 2f0796e954
commit e0436b7757
252 changed files with 3219 additions and 1631 deletions

View File

@@ -2,23 +2,6 @@
declare(strict_types=1);
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common\Cache;
@@ -28,6 +11,9 @@ use MongoDB\Collection;
use MongoDB\Database;
use MongoDB\Driver\Exception\Exception;
use MongoDB\Model\BSONDocument;
use function serialize;
use function time;
use function unserialize;
/**
* MongoDB cache provider for ext-mongodb
@@ -36,24 +22,16 @@ use MongoDB\Model\BSONDocument;
*/
class ExtMongoDBCache extends CacheProvider
{
/**
* @var Database
*/
/** @var Database */
private $database;
/**
* @var Collection
*/
/** @var Collection */
private $collection;
/**
* @var bool
*/
/** @var bool */
private $expirationIndexCreated = false;
/**
* Constructor.
*
* This provider will default to the write concern and read preference
* options set on the Database instance (or inherited from MongoDB or
* Client). Using an unacknowledged write concern (< 1) may make the return
@@ -62,13 +40,12 @@ class ExtMongoDBCache extends CacheProvider
*
* @see http://www.php.net/manual/en/mongo.readpreferences.php
* @see http://www.php.net/manual/en/mongo.writeconcerns.php
* @param Collection $collection
*/
public function __construct(Collection $collection)
{
// Ensure there is no typemap set - we want to use our own
$this->collection = $collection->withOptions(['typeMap' => null]);
$this->database = new Database($collection->getManager(), $collection->getDatabaseName());
$this->database = new Database($collection->getManager(), $collection->getDatabaseName());
}
/**
@@ -119,10 +96,12 @@ class ExtMongoDBCache extends CacheProvider
try {
$this->collection->updateOne(
['_id' => $id],
['$set' => [
MongoDBCache::EXPIRATION_FIELD => ($lifeTime > 0 ? new UTCDateTime((time() + $lifeTime) * 1000): null),
MongoDBCache::DATA_FIELD => new Binary(serialize($data), Binary::TYPE_GENERIC),
]],
[
'$set' => [
MongoDBCache::EXPIRATION_FIELD => ($lifeTime > 0 ? new UTCDateTime((time() + $lifeTime) * 1000): null),
MongoDBCache::DATA_FIELD => new Binary(serialize($data), Binary::TYPE_GENERIC),
],
],
['upsert' => true]
);
} catch (Exception $e) {
@@ -166,7 +145,7 @@ class ExtMongoDBCache extends CacheProvider
*/
protected function doGetStats()
{
$uptime = null;
$uptime = null;
$memoryUsage = null;
try {
@@ -177,12 +156,12 @@ class ExtMongoDBCache extends CacheProvider
'recordStats' => 0,
'repl' => 0,
])->toArray()[0];
$uptime = $serverStatus['uptime'] ?? null;
$uptime = $serverStatus['uptime'] ?? null;
} catch (Exception $e) {
}
try {
$collStats = $this->database->command(['collStats' => $this->collection->getCollectionName()])->toArray()[0];
$collStats = $this->database->command(['collStats' => $this->collection->getCollectionName()])->toArray()[0];
$memoryUsage = $collStats['size'] ?? null;
} catch (Exception $e) {
}
@@ -198,19 +177,15 @@ class ExtMongoDBCache extends CacheProvider
/**
* Check if the document is expired.
*
* @param BSONDocument $document
*
* @return bool
*/
private function isExpired(BSONDocument $document): bool
private function isExpired(BSONDocument $document) : bool
{
return isset($document[MongoDBCache::EXPIRATION_FIELD]) &&
$document[MongoDBCache::EXPIRATION_FIELD] instanceof UTCDateTime &&
$document[MongoDBCache::EXPIRATION_FIELD]->toDateTime() < new \DateTime();
}
private function createExpirationIndex(): void
private function createExpirationIndex() : void
{
if ($this->expirationIndexCreated) {
return;