. */ /** * Doctrine_Adapter_Mock * This class is used for special testing purposes. * * @package Doctrine * @subpackage Doctrine_Adapter * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 * @version $Revision$ */ class Doctrine_Adapter_Mock implements Doctrine_Adapter_Interface, Countable { 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) { $mock = new Doctrine_Adapter_Statement_Mock($this, $query); $mock->queryString = $query; return $mock; } public function addQuery($query) { $this->queries[] = $query; } public function query($query) { $this->queries[] = $query; $e = $this->exception; if( ! empty($e)) { $name = $e[0]; $this->exception = array(); throw new $name($e[1], $e[2]); } $stmt = new Doctrine_Adapter_Statement_Mock($this, $query); $stmt->queryString = $query; return $stmt; } 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)) { $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) { return null; } else { return 1; } } public function count() { return count($this->queries); } 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 == PDO::ATTR_DRIVER_NAME) return strtolower($this->name); } public function setAttribute($attribute, $value) { } public function sqliteCreateFunction() { } }