1
0
Fork 0
mirror of synced 2025-03-30 11:40:15 +03:00
This commit is contained in:
zYne 2007-06-19 22:26:41 +00:00
parent b525df802e
commit 5a15afc6cb
2 changed files with 193 additions and 143 deletions

View file

@ -1,31 +1,47 @@
<?php <?php
require_once("../draft/DB.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>.
*/
class Doctrine_Db_TestLogger implements Doctrine_Overloadable { /**
private $messages = array(); * Doctrine_Db_TestCase
*
public function __call($m, $a) { * @package Doctrine
$this->messages[] = $m; * @subpackage Doctrine_Db
} * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
public function pop() { * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
return array_pop($this->messages); * @category Object Relational Mapping
} * @link www.phpdoctrine.com
public function getAll() { * @since 1.0
return $this->messages; * @version $Revision$
} */
} class Doctrine_Db_TestCase extends Doctrine_UnitTestCase
class Doctrine_Db_TestValidListener extends Doctrine_Db_EventListener { } {
class Doctrine_Db_TestInvalidListener { }
class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
protected $dbh; protected $dbh;
public function prepareData() { } public function prepareData() { }
public function prepareTables() { } public function prepareTables() { }
public function init() { } public function init() { }
public function testInitialize() { public function testInitialize()
$this->dbh = new Doctrine_Db('sqlite::memory:'); {
$this->dbh = Doctrine_Manager::getInstance()->openConnection(array('sqlite::memory:'));
$this->dbh->exec('CREATE TABLE entity (id INTEGER, name TEXT)'); $this->dbh->exec('CREATE TABLE entity (id INTEGER, name TEXT)');
$this->dbh->exec("INSERT INTO entity (id, name) VALUES (1, 'zYne')"); $this->dbh->exec("INSERT INTO entity (id, name) VALUES (1, 'zYne')");
@ -35,60 +51,62 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($this->dbh->getAttribute(Doctrine::ATTR_DRIVER_NAME), 'sqlite'); $this->assertEqual($this->dbh->getAttribute(Doctrine::ATTR_DRIVER_NAME), 'sqlite');
} }
public function testAddValidEventListener() { public function testAddValidEventListener()
$this->dbh->setListener(new Doctrine_Db_EventListener()); {
$this->dbh->setListener(new Doctrine_EventListener());
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener);
try { try {
$ret = $this->dbh->addListener(new Doctrine_Db_TestLogger()); $ret = $this->dbh->addListener(new Doctrine_Connection_TestLogger());
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db); $this->assertTrue($ret instanceof Doctrine_Connection);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
try { try {
$ret = $this->dbh->addListener(new Doctrine_Db_TestValidListener()); $ret = $this->dbh->addListener(new Doctrine_Connection_TestValidListener());
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db); $this->assertTrue($ret instanceof Doctrine_Connection);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
$this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
try { try {
$ret = $this->dbh->addListener(new Doctrine_Db_EventListener_Chain(), 'chain'); $ret = $this->dbh->addListener(new Doctrine_EventListener_Chain(), 'chain');
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db); $this->assertTrue($ret instanceof Doctrine_Connection);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
$this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
$this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_EventListener_Chain);
// replacing // replacing
try { try {
$ret = $this->dbh->addListener(new Doctrine_Db_EventListener_Chain(), 'chain'); $ret = $this->dbh->addListener(new Doctrine_EventListener_Chain(), 'chain');
$this->pass(); $this->pass();
$this->assertTrue($ret instanceof Doctrine_Db); $this->assertTrue($ret instanceof Doctrine_Connection);
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
$this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener()->get(0) instanceof Doctrine_Connection_TestLogger);
$this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener()->get(1) instanceof Doctrine_Connection_TestValidListener);
$this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener()->get('chain') instanceof Doctrine_EventListener_Chain);
} }
public function testListeningEventsWithSingleListener() { public function testListeningEventsWithSingleListener()
$this->dbh->setListener(new Doctrine_Db_TestLogger()); {
$this->dbh->setListener(new Doctrine_Connection_TestLogger());
$listener = $this->dbh->getListener(); $listener = $this->dbh->getListener();
$stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)'); $stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)');
@ -107,38 +125,41 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->dbh->beginTransaction(); $this->dbh->beginTransaction();
$this->assertEqual($listener->pop(), 'onBeginTransaction'); $this->assertEqual($listener->pop(), 'onTransactionBegin');
$this->assertEqual($listener->pop(), 'onPreBeginTransaction'); $this->assertEqual($listener->pop(), 'onPreTransactionBegin');
$this->dbh->query('INSERT INTO entity (id) VALUES (1)'); $this->dbh->exec('INSERT INTO entity (id) VALUES (1)');
$this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreExec');
$this->dbh->commit(); $this->dbh->commit();
$this->assertEqual($listener->pop(), 'onCommit'); $this->assertEqual($listener->pop(), 'onTransactionCommit');
$this->assertEqual($listener->pop(), 'onPreCommit'); $this->assertEqual($listener->pop(), 'onPreTransactionCommit');
$this->assertEqual($listener->pop(), 'onQuery');
$this->assertEqual($listener->pop(), 'onPreQuery');
} }
public function testListeningQueryEventsWithListenerChain() { public function testListeningQueryEventsWithListenerChain()
$this->dbh->query('DROP TABLE entity'); {
$this->dbh->exec('DROP TABLE entity');
$this->dbh->addListener(new Doctrine_Db_TestLogger()); $this->dbh->addListener(new Doctrine_Connection_TestLogger());
$this->dbh->addListener(new Doctrine_Db_TestLogger()); $this->dbh->addListener(new Doctrine_Connection_TestLogger());
$this->dbh->query('CREATE TABLE entity (id INT)'); $this->dbh->exec('CREATE TABLE entity (id INT)');
$listener = $this->dbh->getListener()->get(0); $listener = $this->dbh->getListener()->get(0);
$listener2 = $this->dbh->getListener()->get(1); $listener2 = $this->dbh->getListener()->get(1);
$this->assertEqual($listener->pop(), 'onQuery'); $this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreQuery'); $this->assertEqual($listener->pop(), 'onPreExec');
$this->assertEqual($listener2->pop(), 'onQuery'); $this->assertEqual($listener2->pop(), 'onExec');
$this->assertEqual($listener2->pop(), 'onPreQuery'); $this->assertEqual($listener2->pop(), 'onPreExec');
} }
public function testListeningPrepareEventsWithListenerChain() { public function testListeningPrepareEventsWithListenerChain()
{
$stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)'); $stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)');
$listener = $this->dbh->getListener()->get(0); $listener = $this->dbh->getListener()->get(0);
@ -157,7 +178,8 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener2->pop(), 'onExecute'); $this->assertEqual($listener2->pop(), 'onExecute');
$this->assertEqual($listener2->pop(), 'onPreExecute'); $this->assertEqual($listener2->pop(), 'onPreExecute');
} }
public function testListeningExecEventsWithListenerChain() { public function testListeningExecEventsWithListenerChain()
{
$this->dbh->exec('DELETE FROM entity'); $this->dbh->exec('DELETE FROM entity');
$listener = $this->dbh->getListener()->get(0); $listener = $this->dbh->getListener()->get(0);
$listener2 = $this->dbh->getListener()->get(1); $listener2 = $this->dbh->getListener()->get(1);
@ -167,140 +189,171 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($listener2->pop(), 'onExec'); $this->assertEqual($listener2->pop(), 'onExec');
$this->assertEqual($listener2->pop(), 'onPreExec'); $this->assertEqual($listener2->pop(), 'onPreExec');
} }
public function testListeningTransactionEventsWithListenerChain() { public function testListeningTransactionEventsWithListenerChain()
{
$this->dbh->beginTransaction(); $this->dbh->beginTransaction();
$listener = $this->dbh->getListener()->get(0); $listener = $this->dbh->getListener()->get(0);
$listener2 = $this->dbh->getListener()->get(1); $listener2 = $this->dbh->getListener()->get(1);
$this->assertEqual($listener->pop(), 'onBeginTransaction'); $this->assertEqual($listener->pop(), 'onTransactionBegin');
$this->assertEqual($listener->pop(), 'onPreBeginTransaction'); $this->assertEqual($listener->pop(), 'onPreTransactionBegin');
$this->assertEqual($listener2->pop(), 'onBeginTransaction'); $this->assertEqual($listener2->pop(), 'onTransactionBegin');
$this->assertEqual($listener2->pop(), 'onPreBeginTransaction'); $this->assertEqual($listener2->pop(), 'onPreTransactionBegin');
$this->dbh->query('INSERT INTO entity (id) VALUES (1)'); $this->dbh->exec('INSERT INTO entity (id) VALUES (1)');
$this->dbh->commit(); $this->dbh->commit();
$this->assertEqual($listener->pop(), 'onCommit'); $this->assertEqual($listener->pop(), 'onTransactionCommit');
$this->assertEqual($listener->pop(), 'onPreCommit'); $this->assertEqual($listener->pop(), 'onPreTransactionCommit');
$this->assertEqual($listener->pop(), 'onQuery'); $this->assertEqual($listener->pop(), 'onExec');
$this->assertEqual($listener->pop(), 'onPreQuery'); $this->assertEqual($listener->pop(), 'onPreExec');
$this->dbh->query('DROP TABLE entity'); $this->dbh->exec('DROP TABLE entity');
} }
public function testSetValidEventListener() { public function testSetValidEventListener()
{
try { try {
$this->dbh->setListener(new Doctrine_Db_TestLogger()); $this->dbh->setListener(new Doctrine_Connection_TestLogger());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_TestLogger); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Connection_TestLogger);
try { try {
$this->dbh->setListener(new Doctrine_Db_TestValidListener()); $this->dbh->setListener(new Doctrine_Connection_TestValidListener());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_TestValidListener); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_Connection_TestValidListener);
try { try {
$this->dbh->setListener(new Doctrine_Db_EventListener_Chain()); $this->dbh->setListener(new Doctrine_EventListener_Chain());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener_Chain); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener_Chain);
try { try {
$this->dbh->setListener(new Doctrine_Db_EventListener()); $this->dbh->setListener(new Doctrine_EventListener());
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->fail(); $this->fail();
} }
$this->assertTrue($this->dbh->getListener() instanceof Doctrine_Db_EventListener); $this->assertTrue($this->dbh->getListener() instanceof Doctrine_EventListener);
} }
public function testSetInvalidEventListener() { public function testSetInvalidEventListener()
{
try { try {
$this->dbh->setListener(new Doctrine_Db_TestInvalidListener()); $this->dbh->setListener(new Doctrine_Connection_TestInvalidListener());
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_EventListener_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testInvalidDSN() { public function testInvalidDSN()
{
$manager = Doctrine_Manager::getInstance();
try { try {
$this->dbh = Doctrine_Db::getConnection(''); $this->dbh = $manager->openConnection('');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Exception $e) {
$this->pass(); $this->pass();
} }
try { try {
$this->dbh = Doctrine_Db::getConnection('unknown'); $this->dbh = $manager->openConnection('unknown');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Exception $e) {
$this->pass(); $this->pass();
} }
try { try {
$this->dbh = Doctrine_Db::getConnection(0); $this->dbh = $manager->openConnection(0);
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testInvalidScheme() { public function testInvalidScheme()
{
$manager = Doctrine_Manager::getInstance();
try { try {
$this->dbh = Doctrine_Db::getConnection('unknown://:memory:'); $this->dbh = $manager->openConnection('unknown://:memory:');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testInvalidHost() { public function testInvalidHost()
{
$manager = Doctrine_Manager::getInstance();
try { try {
$this->dbh = Doctrine_Db::getConnection('mysql://user:password@'); $this->dbh = $manager->openConnection('mysql://user:password@');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testInvalidDatabase() { public function testInvalidDatabase()
{
$manager = Doctrine_Manager::getInstance();
try { try {
$this->dbh = Doctrine_Db::getConnection('mysql://user:password@host/'); $this->dbh = $manager->openConnection('mysql://user:password@host/');
$this->fail(); $this->fail();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Exception $e) {
$this->pass(); $this->pass();
} }
} }
public function testGetConnectionPdoLikeDSN() { /**
$this->dbh = Doctrine_Db::getConnection('mysql:host=localhost;dbname=test', 'root', 'password'); public function testGetConnectionPdoLikeDSN()
{
$this->dbh = Doctrine_Manager::openConnection(array('mysql:host=localhost;dbname=test', 'root', 'password'));
$this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test'); $this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test');
$this->assertEqual($this->dbh->getOption('username'), 'root'); $this->assertEqual($this->dbh->getOption('username'), 'root');
$this->assertEqual($this->dbh->getOption('password'), 'password'); $this->assertEqual($this->dbh->getOption('password'), 'password');
$this->dbh = Doctrine_Db::getConnection('sqlite::memory:'); $this->dbh = Doctrine_Connection::getConnection('sqlite::memory:');
$this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:'); $this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:');
$this->assertEqual($this->dbh->getOption('username'), false); $this->assertEqual($this->dbh->getOption('username'), false);
$this->assertEqual($this->dbh->getOption('password'), false); $this->assertEqual($this->dbh->getOption('password'), false);
} }
public function testDriverName() { public function testDriverName()
{
} }
public function testGetConnectionWithPearLikeDSN() { public function testGetConnectionWithPearLikeDSN()
$this->dbh = Doctrine_Db::getConnection('mysql://zYne:password@localhost/test'); {
$this->dbh = Doctrine_Connection::getConnection('mysql://zYne:password@localhost/test');
$this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test'); $this->assertEqual($this->dbh->getOption('dsn'), 'mysql:host=localhost;dbname=test');
$this->assertEqual($this->dbh->getOption('username'), 'zYne'); $this->assertEqual($this->dbh->getOption('username'), 'zYne');
$this->assertEqual($this->dbh->getOption('password'), 'password'); $this->assertEqual($this->dbh->getOption('password'), 'password');
$this->dbh = Doctrine_Db::getConnection('sqlite://:memory:'); $this->dbh = Doctrine_Connection::getConnection('sqlite://:memory:');
$this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:'); $this->assertEqual($this->dbh->getOption('dsn'), 'sqlite::memory:');
$this->assertEqual($this->dbh->getOption('username'), false); $this->assertEqual($this->dbh->getOption('username'), false);
$this->assertEqual($this->dbh->getOption('password'), false); $this->assertEqual($this->dbh->getOption('password'), false);
} }
*/
}
class Doctrine_Connection_TestLogger implements Doctrine_Overloadable {
private $messages = array();
public function __call($m, $a) {
$this->messages[] = $m;
}
public function pop() {
return array_pop($this->messages);
}
public function getAll() {
return $this->messages;
}
} }
class Doctrine_Connection_TestValidListener extends Doctrine_EventListener { }
class Doctrine_Connection_TestInvalidListener { }

View file

@ -20,7 +20,7 @@
*/ */
/** /**
* Doctrine_Db_Profiler_TestCase * Doctrine_Connection_Profiler_TestCase
* *
* @package Doctrine * @package Doctrine
* @subpackage Doctrine_Db * @subpackage Doctrine_Db
@ -31,37 +31,34 @@
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase class Doctrine_Connection_Profiler_TestCase extends Doctrine_UnitTestCase
{ {
protected $dbh; public function prepareTables()
protected $profiler;
public function prepareTables()
{} {}
public function prepareData() public function prepareData()
{} {}
public function testQuery() public function testQuery()
{ {
$this->dbh = Doctrine_Db::getConnection('sqlite::memory:'); $this->conn = Doctrine_Manager::getInstance()->openConnection(array('sqlite::memory:'));
$this->profiler = new Doctrine_Db_Profiler(); $this->profiler = new Doctrine_Connection_Profiler();
$this->dbh->setListener($this->profiler); $this->conn->setListener($this->profiler);
$this->dbh->query('CREATE TABLE test (id INT)'); $this->conn->exec('CREATE TABLE test (id INT)');
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'CREATE TABLE test (id INT)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'CREATE TABLE test (id INT)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::QUERY); $this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXEC);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs())); $this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 1); $this->assertEqual($this->conn->count(), 1);
} }
public function testPrepareAndExecute() public function testPrepareAndExecute()
{ {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt = $this->conn->prepare('INSERT INTO test (id) VALUES (?)');
$event = $this->profiler->lastEvent(); $event = $this->profiler->lastEvent();
$this->assertEqual($event->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($event->getQuery(), 'INSERT INTO test (id) VALUES (?)');
@ -76,18 +73,18 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE); $this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs())); $this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 2); $this->assertEqual($this->conn->count(), 2);
} }
public function testMultiplePrepareAndExecute() public function testMultiplePrepareAndExecute()
{ {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt = $this->conn->prepare('INSERT INTO test (id) VALUES (?)');
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE); $this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs())); $this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$stmt2 = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt2 = $this->conn->prepare('INSERT INTO test (id) VALUES (?)');
$this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)'); $this->assertEqual($this->profiler->lastEvent()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastEvent()->hasEnded()); $this->assertTrue($this->profiler->lastEvent()->hasEnded());
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE); $this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::PREPARE);
@ -101,12 +98,12 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE); $this->assertEqual($this->profiler->lastEvent()->getCode(), Doctrine_Db_Event::EXECUTE);
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs())); $this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
$this->assertEqual($this->dbh->count(), 4); $this->assertEqual($this->conn->count(), 4);
} }
public function testExecuteStatementMultipleTimes() public function testExecuteStatementMultipleTimes()
{ {
try { try {
$stmt = $this->dbh->prepare('INSERT INTO test (id) VALUES (?)'); $stmt = $this->conn->prepare('INSERT INTO test (id) VALUES (?)');
$stmt->execute(array(1)); $stmt->execute(array(1));
$stmt->execute(array(1)); $stmt->execute(array(1));
$this->pass(); $this->pass();
@ -127,7 +124,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase
public function testTransactionRollback() public function testTransactionRollback()
{ {
try { try {
$this->dbh->beginTransaction(); $this->conn->beginTransaction();
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString()); $this->fail($e->__toString());
@ -138,7 +135,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs())); $this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
try { try {
$this->dbh->rollback(); $this->conn->rollback();
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString()); $this->fail($e->__toString());
@ -152,7 +149,7 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase
public function testTransactionCommit() public function testTransactionCommit()
{ {
try { try {
$this->dbh->beginTransaction(); $this->conn->beginTransaction();
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString()); $this->fail($e->__toString());
@ -163,11 +160,11 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase
$this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs())); $this->assertTrue(is_numeric($this->profiler->lastEvent()->getElapsedSecs()));
try { try {
$this->dbh->commit(); $this->conn->commit();
$this->pass(); $this->pass();
} catch(Doctrine_Db_Exception $e) { } catch(Doctrine_Db_Exception $e) {
$this->fail($e->__toString()); $this->fail($e->__toString());
$this->dbh->rollback(); $this->conn->rollback();
} }
$this->assertEqual($this->profiler->lastEvent()->getQuery(), null); $this->assertEqual($this->profiler->lastEvent()->getQuery(), null);