Doctrine 1.2.4
Doctrine_Adapter_Mock Class Reference

Inherits Doctrine_Adapter_Interface, and Countable.

Public Member Functions

 __construct ($name=null)
 
 addQuery ($query)
 
 beginTransaction ()
 
 commit ()
 
 count ()
 
 exec ($statement)
 
 forceException ($name, $message= '', $code=0)
 
 forceLastInsertIdFail ($fail=true)
 
 getAll ()
 
 getName ()
 
 lastInsertId ()
 
 pop ()
 
 prepare ($query)
 
 query ($query)
 
 quote ($input)
 
 rollBack ()
 

Detailed Description

Definition at line 33 of file Mock.php.

Constructor & Destructor Documentation

Doctrine_Adapter_Mock::__construct (   $name = null)

Doctrine mock adapter constructor

$conn = new Doctrine_Adapter_Mock('mysql');

Parameters
string$name
Returns
void

Definition at line 73 of file Mock.php.

{
$this->_name = $name;
}

Member Function Documentation

Doctrine_Adapter_Mock::addQuery (   $query)

Add query to the stack of executed queries

Parameters
string$query
Returns
void

Definition at line 131 of file Mock.php.

{
$this->_queries[] = $query;
}
Doctrine_Adapter_Mock::beginTransaction ( )

Begin a transaction

Returns
void

Definition at line 251 of file Mock.php.

{
$this->_queries[] = 'BEGIN TRANSACTION';
}
Doctrine_Adapter_Mock::commit ( )

Commit a transaction

Returns
void

Definition at line 261 of file Mock.php.

{
$this->_queries[] = 'COMMIT';
}
Doctrine_Adapter_Mock::count ( )

Get the number of queries executed

Returns
integer $count

Definition at line 241 of file Mock.php.

{
return count($this->_queries);
}
Doctrine_Adapter_Mock::exec (   $statement)

Execute a raw sql statement

Parameters
string$statement
Returns
void

Definition at line 189 of file Mock.php.

{
$this->_queries[] = $statement;
$e = $this->_exception;
if ( ! empty($e)) {
$name = $e[0];
$this->_exception = array();
throw new $name($e[1], $e[2]);
}
return 0;
}
Doctrine_Adapter_Mock::forceException (   $name,
  $message = '',
  $code = 0 
)

Force an exception in to the array of exceptions

Parameters
string$nameName of exception
string$messageMessage for the exception
integer$codeCode of the exception
Returns
void

Definition at line 106 of file Mock.php.

{
$this->_exception = array($name, $message, $code);
}
Doctrine_Adapter_Mock::forceLastInsertIdFail (   $fail = true)

Force last insert to be failed

Parameters
boolean$fail
Returns
void

Definition at line 212 of file Mock.php.

{
if ($fail) {
$this->_lastInsertIdFail = true;
} else {
$this->_lastInsertIdFail = false;
}
}
Doctrine_Adapter_Mock::getAll ( )

Get all the executed queries

Returns
array $queries Array of all executed queries

Definition at line 167 of file Mock.php.

{
return $this->_queries;
}
Doctrine_Adapter_Mock::getName ( )

Get the name of the dbms used in this instance of the mock adapter

Returns
string $name Name of the dbms

Definition at line 83 of file Mock.php.

{
return $this->_name;
}
Doctrine_Adapter_Mock::lastInsertId ( )

Get the id of the last inserted record

Returns
integer $id

Definition at line 226 of file Mock.php.

{
$this->_queries[] = 'LAST_INSERT_ID()';
if ($this->_lastInsertIdFail) {
return null;
} else {
return 1;
}
}
Doctrine_Adapter_Mock::pop ( )

Pop the last executed query from the array of executed queries and return it

Returns
string $sql Last executed sql string

Definition at line 93 of file Mock.php.

{
return array_pop($this->_queries);
}
Doctrine_Adapter_Mock::prepare (   $query)

Prepare a query statement

Parameters
string$queryQuery to prepare
Returns
Doctrine_Adapter_Statement_Mock $mock Mock prepared statement

Definition at line 117 of file Mock.php.

{
$mock = new Doctrine_Adapter_Statement_Mock($this, $query);
$mock->queryString = $query;
return $mock;
}
Doctrine_Adapter_Mock::query (   $query)

Fake the execution of query and add it to the stack of executed queries

Parameters
string$query
Returns
Doctrine_Adapter_Statement_Mock $stmt

Definition at line 142 of file Mock.php.

{
$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;
}
Doctrine_Adapter_Mock::quote (   $input)

Quote a value for the dbms

Parameters
string$input
Returns
string $quoted

Definition at line 178 of file Mock.php.

{
return "'" . addslashes($input) . "'";
}
Doctrine_Adapter_Mock::rollBack ( )

Rollback a transaction

Returns
void

Definition at line 271 of file Mock.php.

{
$this->_queries[] = 'ROLLBACK';
}

The documentation for this class was generated from the following file: