Commit fef149dd authored by zYne's avatar zYne

Doctrine_Db_* updates

parent 21cde0e7
...@@ -123,6 +123,10 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -123,6 +123,10 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this->listener = new Doctrine_DB_EventListener(); $this->listener = new Doctrine_DB_EventListener();
} }
public function nextQuerySequence() {
return ++$this->querySequence;
}
/** /**
* getQuerySequence * getQuerySequence
*/ */
...@@ -351,13 +355,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -351,13 +355,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function prepare($statement) { public function prepare($statement) {
$this->connect(); $this->connect();
$args = func_get_args(); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::PREPARE, $statement);
$this->listener->onPrePrepare($this, $statement, $args); $this->listener->onPrePrepare($event);
$stmt = $this->dbh->prepare($statement); $stmt = $this->dbh->prepare($statement);
$this->listener->onPrepare($this, $statement, $args, $this->querySequence); $this->listener->onPrepare($event);
$this->querySequence++; $this->querySequence++;
...@@ -373,14 +377,16 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -373,14 +377,16 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function query($statement, array $params = array()) { public function query($statement, array $params = array()) {
$this->connect(); $this->connect();
$this->listener->onPreQuery($this, $statement, $params); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::QUERY, $statement);
$this->listener->onPreQuery($event);
if( ! empty($params)) if( ! empty($params))
$stmt = $this->dbh->query($statement)->execute($params); $stmt = $this->dbh->query($statement)->execute($params);
else else
$stmt = $this->dbh->query($statement); $stmt = $this->dbh->query($statement);
$this->listener->onQuery($this, $statement, $params, $this->querySequence); $this->listener->onQuery($event);
$this->querySequence++; $this->querySequence++;
...@@ -410,11 +416,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -410,11 +416,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$args = func_get_args(); $args = func_get_args();
$this->listener->onPreExec($this, $statement, $args); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXEC, $statement);
$this->listener->onPreExec($event);
$rows = $this->dbh->exec($statement); $rows = $this->dbh->exec($statement);
$this->listener->onExec($this, $statement, $args); $this->listener->onExec($event);
return $rows; return $rows;
} }
...@@ -463,11 +471,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -463,11 +471,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return boolean * @return boolean
*/ */
public function beginTransaction() { public function beginTransaction() {
$this->listener->onPreBeginTransaction($this); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::BEGIN);
$this->listener->onPreBeginTransaction($event);
$return = $this->dbh->beginTransaction(); $return = $this->dbh->beginTransaction();
$this->listener->onBeginTransaction($this); $this->listener->onBeginTransaction($event);
return $return; return $return;
} }
...@@ -477,11 +487,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -477,11 +487,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return boolean * @return boolean
*/ */
public function commit() { public function commit() {
$this->listener->onPreCommit($this); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::COMMIT);
$this->listener->onPreCommit($event);
$return = $this->dbh->commit(); $return = $this->dbh->commit();
$this->listener->onCommit($this); $this->listener->onCommit($event);
return $return; return $return;
} }
...@@ -493,7 +505,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate { ...@@ -493,7 +505,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public function rollBack() { public function rollBack() {
$this->connect(); $this->connect();
$event = new Doctrine_Db_Event($this, Doctrine_Db_Event::ROLLBACK);
$this->listener->onPreRollback($event);
$this->dbh->rollBack(); $this->dbh->rollBack();
$this->listener->onRollback($event);
} }
/** /**
* getAttribute * getAttribute
......
...@@ -82,14 +82,14 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict { ...@@ -82,14 +82,14 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
} }
} }
/** /**
* Maps a native array description of a field to a MDB2 datatype and length * Maps a native array description of a field to a doctrine datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @throws Doctrine_DataDict_Oracle_Exception * @throws Doctrine_DataDict_Oracle_Exception
*/ */
function mapNativeDatatype($field) { public function mapNativeDatatype(array $field) {
$db_type = strtolower($field['type']); $db_type = strtolower($field['type']);
$type = array(); $type = array();
$length = $unsigned = $fixed = null; $length = $unsigned = $fixed = null;
......
...@@ -58,6 +58,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict { ...@@ -58,6 +58,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
case 'varchar':
case 'char':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : $db->options['default_text_field_length']; ? $field['length'] : $db->options['default_text_field_length'];
......
<?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>.
*/
/**
* Doctrine_Db_Event
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class Doctrine_Db_Event {
const QUERY = 1;
const EXEC = 2;
const EXECUTE = 4;
const PREPARE = 8;
const BEGIN = 16;
const COMMIT = 32;
const ROLLBACK = 64;
protected $invoker;
protected $query;
protected $type;
protected $startedMicrotime;
protected $endedMicrotime;
public function __construct($invoker, $type, $query = null) {
$this->invoker = $invoker;
$this->type = $type;
$this->query = $query;
}
public function getQuery() {
return $this->query;
}
public function getType() {
return $this->type;
}
public function start() {
$this->startedMicrotime = microtime(true);
}
public function hasEnded() {
return ($this->endedMicrotime != null);
}
public function end() {
$this->endedMicrotime = microtime(true);
}
public function getInvoker() {
return $this->invoker;
}
/**
* Get the elapsed time (in seconds) that the query ran. If the query has
* not yet ended, return false.
*
* @return mixed
*/
public function getElapsedSecs() {
if (is_null($this->endedMicrotime))
return false;
return ($this->endedMicrotime - $this->startedMicrotime);
}
}
...@@ -26,24 +26,24 @@ ...@@ -26,24 +26,24 @@
* @package Doctrine * @package Doctrine
*/ */
class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface { class Doctrine_Db_EventListener implements Doctrine_Db_EventListener_Interface {
public function onPreQuery(Doctrine_DB2 $dbh, $statement, array $args) { } public function onPreQuery(Doctrine_Db_Event $event) { }
public function onQuery(Doctrine_DB2 $dbh, $statement, array $args, $queryId) { } public function onQuery(Doctrine_Db_Event $event) { }
public function onPrePrepare(Doctrine_DB2 $dbh, $statement, array $args) { } public function onPrePrepare(Doctrine_Db_Event $event) { }
public function onPrepare(Doctrine_DB2 $dbh, $statement, array $args, $queryId) { } public function onPrepare(Doctrine_Db_Event $event) { }
public function onPreCommit(Doctrine_DB2 $dbh) { } public function onPreCommit(Doctrine_Db_Event $event) { }
public function onCommit(Doctrine_DB2 $dbh) { } public function onCommit(Doctrine_Db_Event $event) { }
public function onPreExec(Doctrine_DB2 $dbh, $statement, array $args) { } public function onPreExec(Doctrine_Db_Event $event) { }
public function onExec(Doctrine_DB2 $dbh, $statement, array $args) { } public function onExec(Doctrine_Db_Event $event) { }
public function onPreRollBack(Doctrine_DB2 $dbh) { } public function onPreRollBack(Doctrine_Db_Event $event) { }
public function onRollBack(Doctrine_DB2 $dbh) { } public function onRollBack(Doctrine_Db_Event $event) { }
public function onPreBeginTransaction(Doctrine_DB2 $dbh) { } public function onPreBeginTransaction(Doctrine_Db_Event $event) { }
public function onBeginTransaction(Doctrine_DB2 $dbh) { } public function onBeginTransaction(Doctrine_Db_Event $event) { }
public function onPreExecute(Doctrine_Db_Statement $stmt, array $params) { } public function onPreExecute(Doctrine_Db_Event $event) { }
public function onExecute(Doctrine_Db_Statement $stmt, array $params) { } public function onExecute(Doctrine_Db_Event $event) { }
} }
...@@ -56,32 +56,32 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin ...@@ -56,32 +56,32 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
public function onQuery(Doctrine_DB2 $dbh, $statement, array $args, $queryId) { public function onQuery(Doctrine_DB2 $dbh, $statement, array $args, $queryId) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreQuery($dbh, $args); $listener->onQuery($dbh, $args);
} }
} }
public function onPreQuery(Doctrine_DB2 $dbh, $statement, array $args) { public function onPreQuery(Doctrine_DB2 $dbh, $statement, array $args) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onQuery($dbh, $args); $listener->onPreQuery($dbh, $args);
} }
} }
public function onPreExec(Doctrine_DB2 $dbh, array $args) { public function onPreExec(Doctrine_DB2 $dbh, $statement, array $args) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPreExec($dbh, $args); $listener->onPreExec($dbh, $args);
} }
} }
public function onExec(Doctrine_DB2 $dbh, array $args) { public function onExec(Doctrine_DB2 $dbh, $statement, array $args) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onExec($dbh, $args); $listener->onExec($dbh, $args);
} }
} }
public function onPrePrepare(Doctrine_DB2 $dbh, array $args) { public function onPrePrepare(Doctrine_DB2 $dbh, $statement, array $args) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPrePrepare($dbh, $args); $listener->onPrePrepare($dbh, $args);
} }
} }
public function onPrepare(Doctrine_DB2 $dbh, array $args) { public function onPrepare(Doctrine_DB2 $dbh, $statement, array $args, $queryId) {
foreach($this->listeners as $listener) { foreach($this->listeners as $listener) {
$listener->onPrepare($dbh, $args); $listener->onPrepare($dbh, $args);
} }
......
...@@ -26,24 +26,24 @@ ...@@ -26,24 +26,24 @@
* @package Doctrine * @package Doctrine
*/ */
interface Doctrine_Db_EventListener_Interface { interface Doctrine_Db_EventListener_Interface {
public function onPreQuery(Doctrine_DB2 $dbh, $statement, array $args); public function onPreQuery(Doctrine_Db_Event $event);
public function onQuery(Doctrine_DB2 $dbh, $statement, array $args, $queryId); public function onQuery(Doctrine_Db_Event $event);
public function onPrePrepare(Doctrine_DB2 $dbh, $statement, array $args); public function onPrePrepare(Doctrine_Db_Event $event);
public function onPrepare(Doctrine_DB2 $dbh, $statement, array $args, $queryId); public function onPrepare(Doctrine_Db_Event $event);
public function onPreExec(Doctrine_DB2 $dbh, $statement, array $args); public function onPreExec(Doctrine_Db_Event $event);
public function onExec(Doctrine_DB2 $dbh, $statement, array $args); public function onExec(Doctrine_Db_Event $event);
public function onPreCommit(Doctrine_DB2 $dbh); public function onPreCommit(Doctrine_Db_Event $event);
public function onCommit(Doctrine_DB2 $dbh); public function onCommit(Doctrine_Db_Event $event);
public function onPreRollBack(Doctrine_DB2 $dbh); public function onPreRollBack(Doctrine_Db_Event $event);
public function onRollBack(Doctrine_DB2 $dbh); public function onRollBack(Doctrine_Db_Event $event);
public function onPreBeginTransaction(Doctrine_DB2 $dbh); public function onPreBeginTransaction(Doctrine_Db_Event $event);
public function onBeginTransaction(Doctrine_DB2 $dbh); public function onBeginTransaction(Doctrine_Db_Event $event);
public function onPreExecute(Doctrine_Db_Statement $stmt, array $params); public function onPreExecute(Doctrine_Db_Event $event);
public function onExecute(Doctrine_Db_Statement $stmt, array $params); public function onExecute(Doctrine_Db_Event $event);
} }
This diff is collapsed.
<?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>.
*/
Doctrine::autoload('Doctrine_Db_Exception');
/**
* Doctrine_Db_Exception
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class Doctrine_Db_Profiler_Exception extends Doctrine_Db_Exception { }
...@@ -58,14 +58,17 @@ class Doctrine_Db_Profiler_Query { ...@@ -58,14 +58,17 @@ class Doctrine_Db_Profiler_Query {
* *
* @param string $query * @param string $query
* @param int $queryType * @param int $queryType
* @return bool
*/ */
public function __construct($query, $prepareTime = null) public function __construct($query, $prepareTime = null) {
{
$this->query = $query; $this->query = $query;
if($prepareTime !== null) {
$this->prepareTime = $prepareTime; $this->prepareTime = $prepareTime;
} else {
$this->startedMicrotime = microtime(true);
}
}
public function start() {
$this->startedMicrotime = microtime(true); $this->startedMicrotime = microtime(true);
return true;
} }
/** /**
* The query has ended. Record the time so that the elapsed time can be determined later. * The query has ended. Record the time so that the elapsed time can be determined later.
......
...@@ -30,24 +30,41 @@ class Doctrine_Db_Statement extends PDOStatement { ...@@ -30,24 +30,41 @@ class Doctrine_Db_Statement extends PDOStatement {
protected $querySequence; protected $querySequence;
protected $baseSequence;
protected $executed = false;
protected function __construct($dbh) { protected function __construct($dbh) {
$this->dbh = $dbh; $this->dbh = $dbh;
$this->querySequence = $this->dbh->getQuerySequence(); $this->baseSequence = $this->querySequence = $this->dbh->getQuerySequence();
} }
public function getQuerySequence() { public function getQuerySequence() {
return $this->querySequence; return $this->querySequence;
} }
public function getBaseSequence() {
return $this->baseSequence;
}
public function getQuery() { public function getQuery() {
return $this->queryString; return $this->queryString;
} }
public function isExecuted($executed = null) {
if($executed === null)
return $this->executed;
$this->executed = (bool) $executed;
}
public function execute(array $params) { public function execute(array $params) {
$this->dbh->getListener()->onPreExecute($this, $params); $event = new Doctrine_Db_Event($this, Doctrine_Db_Event::EXECUTE, $this->queryString);
$this->dbh->getListener()->onPreExecute($event);
$ret = parent::execute($params); $ret = parent::execute($params);
$this->dbh->getListener()->onExecute($this, $params); $this->dbh->getListener()->onExecute($event);
return $this; return $this;
} }
......
...@@ -15,51 +15,56 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase { ...@@ -15,51 +15,56 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this->dbh->query('CREATE TABLE test (id INT)'); $this->dbh->query('CREATE TABLE test (id INT)');
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'CREATE TABLE test (id INT)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'CREATE TABLE test (id INT)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs())); $this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::QUERY);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 1); $this->assertEqual($this->dbh->count(), 1);
} }
public function testPrepareAndExecute() { public function testPrepareAndExecute() {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)');
$event = $this->profiler->lastEvent();
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($event->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertFalse($this->profiler->lastQuery()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs())); $this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt->execute(array(1)); $stmt->execute(array(1));
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs())); $this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 2); $this->assertEqual($this->dbh->count(), 2);
} }
public function testMultiplePrepareAndExecute() { public function testMultiplePrepareAndExecute() {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)');
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertFalse($this->profiler->lastQuery()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs())); $this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt2 = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt2 = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)');
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertFalse($this->profiler->lastQuery()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs())); $this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt->execute(array(1)); $stmt->execute(array(1));
$stmt2->execute(array(1)); $stmt2->execute(array(1));
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs())); $this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 4); $this->assertEqual($this->dbh->count(), 4);
} }
/**
public function testExecuteStatementMultipleTimes() { public function testExecuteStatementMultipleTimes() {
try { try {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)');
...@@ -67,15 +72,66 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase { ...@@ -67,15 +72,66 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$stmt->execute(array(1)); $stmt->execute(array(1));
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail();
$this->fail($e->__toString());
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
}
public function testTransactionRollback() {
try {
$this->dbh->beginTransaction();
$this->pass();
} catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString());
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::BEGIN);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
try {
$this->dbh->rollback();
$this->pass();
} catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString());
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::ROLLBACK);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
}
public function testTransactionCommit() {
try {
$this->dbh->beginTransaction();
$this->pass();
} catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString());
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::BEGIN);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
try {
$this->dbh->commit();
$this->pass();
} catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString());
}
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null);
$this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getType(), Doctrine_Db_Event::COMMIT);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
} }
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs()));
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs()));
} */
} }
?> ?>
...@@ -68,9 +68,9 @@ print '<pre>'; ...@@ -68,9 +68,9 @@ print '<pre>';
$test = new GroupTest('Doctrine Framework Unit Tests'); $test = new GroupTest('Doctrine Framework Unit Tests');
//$test->addTestCase(new Doctrine_Db_Profiler_TestCase()); $test->addTestCase(new Doctrine_Db_Profiler_TestCase());
/**
//$test->addTestCase(new Doctrine_DB_TestCase()); $test->addTestCase(new Doctrine_Db_TestCase());
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); $test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
...@@ -154,14 +154,15 @@ $test->addTestCase(new Doctrine_Query_Where_TestCase()); ...@@ -154,14 +154,15 @@ $test->addTestCase(new Doctrine_Query_Where_TestCase());
$test->addTestCase(new Doctrine_Query_From_TestCase()); $test->addTestCase(new Doctrine_Query_From_TestCase());
$test->addTestCase(new Doctrine_Query_Select_TestCase());
$test->addTestCase(new Doctrine_Query_Delete_TestCase()); $test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase()); $test->addTestCase(new Doctrine_Query_Update_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase());
*/
$test->addTestCase(new Doctrine_Query_Select_TestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment