Inital commit for unit test configuration
This commit is contained in:

committed by
Manish Verma

parent
2f0796e954
commit
e0436b7757
@@ -1,68 +1,50 @@
|
||||
<?php
|
||||
/*
|
||||
* 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;
|
||||
|
||||
use SQLite3;
|
||||
use SQLite3Result;
|
||||
use const SQLITE3_ASSOC;
|
||||
use const SQLITE3_BLOB;
|
||||
use const SQLITE3_TEXT;
|
||||
use function array_search;
|
||||
use function implode;
|
||||
use function serialize;
|
||||
use function sprintf;
|
||||
use function time;
|
||||
use function unserialize;
|
||||
|
||||
/**
|
||||
* SQLite3 cache provider.
|
||||
*
|
||||
* @since 1.4
|
||||
* @author Jake Bell <jake@theunraveler.com>
|
||||
*/
|
||||
class SQLite3Cache extends CacheProvider
|
||||
{
|
||||
/**
|
||||
* The ID field will store the cache key.
|
||||
*/
|
||||
const ID_FIELD = 'k';
|
||||
public const ID_FIELD = 'k';
|
||||
|
||||
/**
|
||||
* The data field will store the serialized PHP value.
|
||||
*/
|
||||
const DATA_FIELD = 'd';
|
||||
public const DATA_FIELD = 'd';
|
||||
|
||||
/**
|
||||
* The expiration field will store a date value indicating when the
|
||||
* cache entry should expire.
|
||||
*/
|
||||
const EXPIRATION_FIELD = 'e';
|
||||
public const EXPIRATION_FIELD = 'e';
|
||||
|
||||
/**
|
||||
* @var SQLite3
|
||||
*/
|
||||
/** @var SQLite3 */
|
||||
private $sqlite;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
/** @var string */
|
||||
private $table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Calling the constructor will ensure that the database file and table
|
||||
* exist and will create both if they don't.
|
||||
*
|
||||
* @param SQLite3 $sqlite
|
||||
* @param string $table
|
||||
*/
|
||||
public function __construct(SQLite3 $sqlite, $table)
|
||||
@@ -70,15 +52,20 @@ class SQLite3Cache extends CacheProvider
|
||||
$this->sqlite = $sqlite;
|
||||
$this->table = (string) $table;
|
||||
|
||||
list($id, $data, $exp) = $this->getFields();
|
||||
$this->ensureTableExists();
|
||||
}
|
||||
|
||||
return $this->sqlite->exec(sprintf(
|
||||
'CREATE TABLE IF NOT EXISTS %s(%s TEXT PRIMARY KEY NOT NULL, %s BLOB, %s INTEGER)',
|
||||
$table,
|
||||
$id,
|
||||
$data,
|
||||
$exp
|
||||
));
|
||||
private function ensureTableExists() : void
|
||||
{
|
||||
$this->sqlite->exec(
|
||||
sprintf(
|
||||
'CREATE TABLE IF NOT EXISTS %s(%s TEXT PRIMARY KEY NOT NULL, %s BLOB, %s INTEGER)',
|
||||
$this->table,
|
||||
static::ID_FIELD,
|
||||
static::DATA_FIELD,
|
||||
static::EXPIRATION_FIELD
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +75,7 @@ class SQLite3Cache extends CacheProvider
|
||||
{
|
||||
$item = $this->findById($id);
|
||||
|
||||
if (!$item) {
|
||||
if (! $item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,7 +87,7 @@ class SQLite3Cache extends CacheProvider
|
||||
*/
|
||||
protected function doContains($id)
|
||||
{
|
||||
return null !== $this->findById($id, false);
|
||||
return $this->findById($id, false) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +146,6 @@ class SQLite3Cache extends CacheProvider
|
||||
* Find a single row by ID.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param bool $includeData
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
@@ -167,7 +153,7 @@ class SQLite3Cache extends CacheProvider
|
||||
{
|
||||
list($idField) = $fields = $this->getFields();
|
||||
|
||||
if (!$includeData) {
|
||||
if (! $includeData) {
|
||||
$key = array_search(static::DATA_FIELD, $fields);
|
||||
unset($fields[$key]);
|
||||
}
|
||||
@@ -210,8 +196,6 @@ class SQLite3Cache extends CacheProvider
|
||||
* Check if the item is expired.
|
||||
*
|
||||
* @param array $item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isExpired(array $item) : bool
|
||||
{
|
||||
|
Reference in New Issue
Block a user