1
0
mirror of synced 2024-12-16 08:06:02 +03:00
doctrine2/lib/Doctrine/Adapter/Mock.php

163 lines
4.3 KiB
PHP
Raw Normal View History

2007-02-01 12:58:15 +03:00
<?php
/*
* $Id$
*
* 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 LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
2007-02-01 12:58:15 +03:00
/**
* Doctrine_Adapter_Mock
* This class is used for special testing purposes.
*
* @package Doctrine
* @subpackage Adapter
2007-02-01 12:58:15 +03:00
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
2007-02-05 15:04:56 +03:00
class Doctrine_Adapter_Mock implements Doctrine_Adapter_Interface, Countable
2007-02-01 12:58:15 +03:00
{
private $name;
private $queries = array();
private $exception = array();
private $lastInsertIdFail = false;
public function __construct($name = null)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function pop()
{
return array_pop($this->queries);
}
public function forceException($name, $message = '', $code = 0)
{
$this->exception = array($name, $message, $code);
}
public function prepare($query)
{
2007-02-05 15:04:56 +03:00
$mock = new Doctrine_Adapter_Statement_Mock($this, $query);
$mock->queryString = $query;
return $mock;
2007-02-01 12:58:15 +03:00
}
public function addQuery($query)
{
$this->queries[] = $query;
}
public function query($query)
{
$this->queries[] = $query;
$e = $this->exception;
if ( ! empty($e)) {
2007-02-01 12:58:15 +03:00
$name = $e[0];
$this->exception = array();
throw new $name($e[1], $e[2]);
}
2007-02-05 15:04:56 +03:00
$stmt = new Doctrine_Adapter_Statement_Mock($this, $query);
$stmt->queryString = $query;
return $stmt;
2007-02-01 12:58:15 +03:00
}
public function getAll()
{
return $this->queries;
}
public function quote($input)
{
return "'" . addslashes($input) . "'";
}
public function exec($statement)
{
$this->queries[] = $statement;
$e = $this->exception;
if ( ! empty($e)) {
2007-02-01 12:58:15 +03:00
$name = $e[0];
$this->exception = array();
throw new $name($e[1], $e[2]);
}
return 0;
}
public function forceLastInsertIdFail($fail = true)
{
if ($fail) {
$this->lastInsertIdFail = true;
} else {
$this->lastInsertIdFail = false;
}
}
public function lastInsertId()
{
$this->queries[] = 'LAST_INSERT_ID()';
if ($this->lastInsertIdFail) {
2007-02-01 12:58:15 +03:00
return null;
} else {
2007-02-01 12:58:15 +03:00
return 1;
}
}
2007-02-05 15:04:56 +03:00
public function count()
{
return count($this->queries);
2007-02-05 15:04:56 +03:00
}
2007-02-01 12:58:15 +03:00
public function beginTransaction()
{
$this->queries[] = 'BEGIN TRANSACTION';
}
public function commit()
{
$this->queries[] = 'COMMIT';
}
public function rollBack()
{
$this->queries[] = 'ROLLBACK';
}
public function errorCode()
{ }
public function errorInfo()
{ }
public function getAttribute($attribute)
{
if ($attribute == Doctrine::ATTR_DRIVER_NAME)
2007-02-01 12:58:15 +03:00
return strtolower($this->name);
}
public function setAttribute($attribute, $value)
{
2007-02-01 12:58:15 +03:00
}
2007-06-10 23:17:26 +04:00
public function sqliteCreateFunction()
{ }
2007-02-01 12:58:15 +03:00
}