| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Db
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @see Zend_Db_TestSetup
- */
- require_once 'Zend/Db/TestSetup.php';
- /**
- * @category Zend
- * @package Zend_Db
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Db
- * @group Zend_Db_Profiler
- */
- class Zend_Db_Profiler_StaticTest extends Zend_Db_TestSetup
- {
- /**
- * @return void
- */
- public function testProfilerFactoryFalse()
- {
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => false
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got '.get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got '.get_class($prof));
- $this->assertFalse($prof->getEnabled());
- }
- /**
- * @return void
- */
- public function testProfilerFactoryTrue()
- {
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => true
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got '.get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got '.get_class($prof));
- $this->assertTrue($prof->getEnabled());
- }
- /**
- * Ensures that passing the 'profiler' option as a string continues to work as prior to SVN r6172.
- *
- * E.g., 'profiler' => 'true', 'profiler' => '1' results in default profiler enabled.
- *
- * @return void
- */
- public function testProfilerFactoryString()
- {
- $profilerStrings = array(
- 'true',
- '1',
- 'Zend_Db_Profiler_ProfilerCustom'
- );
- foreach ($profilerStrings as $profilerString) {
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => $profilerString
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got ' . get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got ' . get_class($prof));
- $this->assertTrue($prof->getEnabled());
- }
- }
- /**
- * @return void
- */
- public function testProfilerFactoryInstance()
- {
- require_once 'Zend/Db/Profiler/ProfilerCustom.php';
- $profiler = new Zend_Db_Profiler_ProfilerCustom();
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => $profiler
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got ' . get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got ' . get_class($prof));
- $this->assertTrue($prof instanceof Zend_Db_Profiler_ProfilerCustom,
- 'Expected object of type Zend_Db_Profiler_ProfilerCustom, got ' . get_class($prof));
- $this->assertFalse($prof->getEnabled());
- }
- /**
- * @return void
- */
- public function testProfilerFactoryArrayEnabled()
- {
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => array(
- 'enabled' => true
- )
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got '.get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got '.get_class($prof));
- $this->assertTrue($prof->getEnabled());
- }
- /**
- * @return void
- */
- public function testProfilerFactoryArrayClass()
- {
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => array(
- 'class' => 'Zend_Db_Profiler_ProfilerCustom'
- )
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got '.get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got '.get_class($prof));
- $this->assertTrue($prof instanceof Zend_Db_Profiler_ProfilerCustom,
- 'Expected object of type Zend_Db_Profiler_ProfilerCustom, got '.get_class($prof));
- $this->assertFalse($prof->getEnabled());
- }
- /**
- * @return void
- */
- public function testProfilerFactoryArrayInstance()
- {
- require_once 'Zend/Db/Profiler/ProfilerCustom.php';
- $profiler = new Zend_Db_Profiler_ProfilerCustom();
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => array(
- 'instance' => $profiler
- )
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got '.get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got '.get_class($prof));
- $this->assertTrue($prof instanceof Zend_Db_Profiler_ProfilerCustom,
- 'Expected object of type Zend_Db_Profiler_ProfilerCustom, got '.get_class($prof));
- $this->assertFalse($prof->getEnabled());
- }
- /**
- * @return void
- */
- public function testProfilerFactoryConfig()
- {
- require_once 'Zend/Config.php';
- $config = new Zend_Config(array(
- 'class' => 'Zend_Db_Profiler_ProfilerCustom'
- ));
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => $config
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got '.get_class($db));
- $prof = $db->getProfiler();
- $this->assertTrue($prof instanceof Zend_Db_Profiler,
- 'Expected object of type Zend_Db_Profiler, got '.get_class($prof));
- $this->assertTrue($prof instanceof Zend_Db_Profiler_ProfilerCustom,
- 'Expected object of type Zend_Db_Profiler_ProfilerCustom, got '.get_class($prof));
- $this->assertFalse($prof->getEnabled());
- }
- /**
- * Ensures that setting the profiler does not affect whether the profiler is enabled.
- *
- * @return void
- */
- public function testProfilerFactoryEnabledUnaffected()
- {
- require_once 'Zend/Db/Profiler/ProfilerCustom.php';
- $profiler = new Zend_Db_Profiler_ProfilerCustom();
- $profiler->setEnabled(true);
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => $profiler
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got ' . get_class($db));
- $profiler2 = $db->getProfiler();
- $this->assertSame($profiler, $profiler2);
- $this->assertTrue($profiler->getEnabled());
- }
- /**
- * Ensures that an instance of an invalid profiler class results in an exception
- *
- * @return void
- */
- public function testProfilerFactoryInvalidClass()
- {
- $profilerInvalid = new stdClass();
- try {
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => $profilerInvalid
- )
- );
- $this->fail('Expected Zend_Db_Profiler_Exception not thrown');
- } catch (Zend_Db_Profiler_Exception $e) {
- $this->assertContains('Profiler argument must be an instance of', $e->getMessage());
- }
- }
- /**
- * Ensures that the factory can handle an instance of Zend_Config having a profiler instance
- *
- * @return void
- */
- public function testProfilerFactoryConfigInstance()
- {
- require_once 'Zend/Db/Profiler/ProfilerCustom.php';
- $profiler = new Zend_Db_Profiler_ProfilerCustom();
- require_once 'Zend/Config.php';
- $config = new Zend_Config(array('instance' => $profiler));
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => $config
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got ' . get_class($db));
- $profiler2 = $db->getProfiler();
- $this->assertSame($profiler, $profiler2);
- $this->assertFalse($profiler->getEnabled());
- }
- /**
- * Ensures that a provided instance overrides a class definition
- *
- * @return void
- */
- public function testProfilerFactoryInstanceOverridesClass()
- {
- require_once 'Zend/Db/Profiler/ProfilerCustom.php';
- $profiler = new Zend_Db_Profiler_ProfilerCustom();
- $db = Zend_Db::factory('Static',
- array(
- 'dbname' => 'dummy',
- 'profiler' => array(
- 'instance' => $profiler,
- 'class' => 'stdClass'
- )
- )
- );
- $this->assertTrue($db instanceof Zend_Db_Adapter_Abstract,
- 'Expected object of type Zend_Db_Adapter_Abstract, got ' . get_class($db));
- $profiler2 = $db->getProfiler();
- $this->assertSame($profiler, $profiler2);
- $this->assertFalse($profiler->getEnabled());
- }
- /**
- * Ensures that setEnabled() behaves as expected.
- *
- * @return void
- */
- public function testProfilerSetEnabled()
- {
- $prof = $this->_db->getProfiler();
- $this->assertSame($prof->setEnabled(true), $prof);
- $this->assertTrue($prof->getEnabled());
- $this->assertSame($prof->setEnabled(false), $prof);
- $this->assertFalse($prof->getEnabled());
- }
- /**
- * Ensures that setFilterElapsedSecs() behaves as expected.
- *
- * @return void
- */
- public function testProfilerSetFilterElapsedSecs()
- {
- $prof = $this->_db->getProfiler();
- $this->assertSame($prof->setFilterElapsedSecs(), $prof);
- $this->assertNull($prof->getFilterElapsedSecs());
- $this->assertSame($prof->setFilterElapsedSecs(null), $prof);
- $this->assertNull($prof->getFilterElapsedSecs());
- $this->assertSame($prof->setFilterElapsedSecs(3), $prof);
- $this->assertEquals(3, $prof->getFilterElapsedSecs());
- }
- /**
- * Ensures that setFilterQueryType() remembers the setting.
- *
- * @return void
- */
- public function testProfilerSetFilterQueryType()
- {
- $prof = $this->_db->getProfiler();
- $this->assertSame($prof->setFilterQueryType(), $prof);
- $this->assertNull($prof->getFilterQueryType());
- $this->assertSame($prof->setFilterQueryType(null), $prof);
- $this->assertNull($prof->getFilterQueryType());
- $queryTypes = Zend_Db_Profiler::DELETE;
- $this->assertSame($prof->setFilterQueryType($queryTypes), $prof);
- $this->assertEquals($queryTypes, $prof->getFilterQueryType());
- }
- /**
- * Ensures that clear() behaves as expected
- *
- * @return void
- */
- public function testProfilerClear()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $this->assertSame($prof->clear(), $prof);
- $this->assertFalse($prof->getQueryProfiles());
- }
- /**
- * Ensures that queryStart() behaves as expected.
- *
- * @return void
- */
- public function testProfilerQueryStart()
- {
- $prof = $this->_db->getProfiler();
- $this->assertNull($prof->queryStart('sqlDisabled1'));
- $prof->setEnabled(true);
- $queries = array(
- array(
- 'sql' => '',
- 'typeGiven' => null,
- 'typeExpected' => Zend_Db_Profiler::QUERY
- ),
- array(
- 'sql' => '',
- 'typeGiven' => Zend_Db_Profiler::QUERY,
- 'typeExpected' => Zend_Db_Profiler::QUERY
- ),
- array(
- 'sql' => 'something',
- 'typeGiven' => null,
- 'typeExpected' => Zend_Db_Profiler::QUERY
- ),
- array(
- 'sql' => 'INSERT',
- 'typeGiven' => null,
- 'typeExpected' => Zend_Db_Profiler::INSERT
- ),
- array(
- 'sql' => 'sqlInsert',
- 'typeGiven' => Zend_Db_Profiler::INSERT,
- 'typeExpected' => Zend_Db_Profiler::INSERT
- ),
- array(
- 'sql' => 'INSERT',
- 'typeGiven' => Zend_Db_Profiler::UPDATE,
- 'typeExpected' => Zend_Db_Profiler::UPDATE
- ),
- array(
- 'sql' => 'UPDATE',
- 'typeGiven' => null,
- 'typeExpected' => Zend_Db_Profiler::UPDATE
- ),
- array(
- 'sql' => 'sqlUpdate',
- 'typeGiven' => Zend_Db_Profiler::UPDATE,
- 'typeExpected' => Zend_Db_Profiler::UPDATE
- ),
- array(
- 'sql' => 'UPDATE',
- 'typeGiven' => Zend_Db_Profiler::DELETE,
- 'typeExpected' => Zend_Db_Profiler::DELETE
- ),
- array(
- 'sql' => 'DELETE',
- 'typeGiven' => null,
- 'typeExpected' => Zend_Db_Profiler::DELETE
- ),
- array(
- 'sql' => 'sqlDelete',
- 'typeGiven' => Zend_Db_Profiler::DELETE,
- 'typeExpected' => Zend_Db_Profiler::DELETE
- ),
- array(
- 'sql' => 'DELETE',
- 'typeGiven' => Zend_Db_Profiler::SELECT,
- 'typeExpected' => Zend_Db_Profiler::SELECT
- ),
- array(
- 'sql' => 'SELECT',
- 'typeGiven' => null,
- 'typeExpected' => Zend_Db_Profiler::SELECT
- ),
- array(
- 'sql' => 'sqlSelect',
- 'typeGiven' => Zend_Db_Profiler::SELECT,
- 'typeExpected' => Zend_Db_Profiler::SELECT
- ),
- array(
- 'sql' => 'SELECT',
- 'typeGiven' => Zend_Db_Profiler::INSERT,
- 'typeExpected' => Zend_Db_Profiler::INSERT
- )
- );
- foreach ($queries as $key => $query) {
- $this->assertEquals($key, $prof->queryStart($query['sql'], $query['typeGiven']));
- }
- $prof->setEnabled(false);
- $this->assertNull($prof->queryStart('sqlDisabled2'));
- $queryProfiles = $prof->getQueryProfiles(null, true);
- $this->assertEquals(count($queries), count($queryProfiles));
- foreach ($queryProfiles as $queryId => $queryProfile) {
- $this->assertNotNull($queryProfile->getStartedMicrotime());
- $this->assertTrue(isset($queries[$queryId]));
- $this->assertEquals($queries[$queryId]['sql'], $queryProfile->getQuery());
- $this->assertEquals($queries[$queryId]['typeExpected'], $queryProfile->getQueryType());
- }
- }
- /**
- * Ensures that queryEnd() behaves as expected when given invalid query handle.
- *
- * @return void
- */
- public function testProfilerQueryEndHandleInvalid()
- {
- $prof = $this->_db->getProfiler();
- $prof->queryEnd('invalid');
- $prof->setEnabled(true);
- try {
- $prof->queryEnd('invalid');
- $this->fail('Expected Zend_Db_Profiler_Exception not thrown');
- } catch (Zend_Db_Profiler_Exception $e) {
- $this->assertContains('no query with handle', $e->getMessage());
- }
- }
- /**
- * Ensures that queryEnd() throws an exception when the query has already ended.
- *
- * @return void
- */
- public function testProfilerQueryEndAlreadyEnded()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $queryId = $prof->queryStart('sql');
- $prof->queryEnd($queryId);
- try {
- $prof->queryEnd($queryId);
- $this->fail('Expected Zend_Db_Profiler_Exception not thrown');
- } catch (Zend_Db_Profiler_Exception $e) {
- $this->assertContains('has already ended', $e->getMessage());
- }
- }
- /**
- * Ensures that queryEnd() does not keep the query profile if the elapsed time is less than
- * the minimum time allowed by the elapsed seconds filter.
- *
- * @return void
- */
- public function testProfilerQueryEndFilterElapsedSecs()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true)
- ->setFilterElapsedSecs(1);
- $prof->queryEnd($prof->queryStart('sqlTimeShort1'));
- $this->_db->query('sqlTimeShort2');
- $this->_db->setOnQuerySleep(2);
- $this->_db->query('sqlTimeLong');
- $this->_db->setOnQuerySleep(0);
- $this->_db->query('sqlTimeShort3');
- $this->assertEquals(1, count($queryProfiles = $prof->getQueryProfiles()));
- $this->assertTrue(isset($queryProfiles[2]));
- $this->assertEquals('sqlTimeLong', $queryProfiles[2]->getQuery());
- }
- /**
- * Ensures that queryEnd() does not keep the query profile if the query type is not allowed
- * by the query type filter.
- *
- * @return void
- */
- public function testProfilerQueryEndFilterQueryType()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true)
- ->setFilterQueryType(Zend_Db_Profiler::UPDATE);
- $this->_db->query('INSERT');
- $this->_db->query('UPDATE');
- $this->_db->query('DELETE');
- $this->_db->query('SELECT');
- $this->_db->query('UPDATE');
- $this->_db->query('DELETE');
- $this->assertEquals(2, count($prof->getQueryProfiles()));
- }
- /**
- * Ensures that getQueryProfile() throws an exception when given an invalid query handle.
- *
- * @return void
- */
- public function testProfilerGetQueryProfileHandleInvalid()
- {
- try {
- $this->_db->getProfiler()->getQueryProfile('invalid');
- $this->fail('Expected Zend_Db_Profiler_Exception not thrown');
- } catch (Zend_Db_Profiler_Exception $e) {
- $this->assertContains('not found', $e->getMessage());
- }
- }
- /**
- * Ensures that getQueryProfile() behaves as expected when provided a valid handle.
- *
- * @return void
- */
- public function testProfilerGetQueryProfileHandleValid()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $queryId = $prof->queryStart('sql');
- $this->assertTrue(
- $prof->getQueryProfile($queryId) instanceof Zend_Db_Profiler_Query
- );
- }
- /**
- * Ensures that getQueryProfiles() returns only those queries of the specified type(s).
- *
- * @return void
- */
- public function testProfilerGetQueryProfilesFilterQueryType()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $queries = array(
- 'INSERT',
- 'UPDATE',
- 'DELETE',
- 'SELECT'
- );
- foreach ($queries as $query) {
- $this->_db->query($query);
- }
- foreach ($queries as $queryId => $query) {
- $queryProfiles = $prof->getQueryProfiles(constant("Zend_Db_Profiler::$query"));
- $this->assertEquals(1, count($queryProfiles));
- $this->assertTrue(isset($queryProfiles[$queryId]));
- $this->assertEquals($query, $queryProfiles[$queryId]->getQuery());
- }
- }
- /**
- * Ensures that getTotalElapsedSecs() behaves as expected for basic usage.
- *
- * @return void
- */
- public function testProfilerGetTotalElapsedSecsBasic()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $this->_db->setOnQuerySleep(1);
- $numQueries = 3;
- for ($queryCount = 0; $queryCount < $numQueries; ++$queryCount) {
- $this->_db->query("sql $queryCount");
- }
- $this->assertThat(
- $prof->getTotalElapsedSecs(),
- $this->greaterThan($numQueries - 0.1)
- );
- }
- /**
- * Ensures that getTotalElapsedSecs() only counts queries of the specified type(s).
- *
- * @return void
- */
- public function testProfilerGetTotalElapsedSecsFilterQueryType()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $this->_db->query('SELECT');
- $this->_db->query('SELECT');
- $this->_db->setOnQuerySleep(1);
- $this->_db->query('UPDATE');
- $this->_db->setOnQuerySleep(0);
- $this->_db->query('SELECT');
- $this->_db->setOnQuerySleep(1);
- $this->_db->query('UPDATE');
- $this->_db->setOnQuerySleep(0);
- $this->_db->query('SELECT');
- $this->assertThat(
- $prof->getTotalElapsedSecs(Zend_Db_Profiler::SELECT),
- $this->lessThan(1)
- );
- $this->assertThat(
- $prof->getTotalElapsedSecs(Zend_Db_Profiler::UPDATE),
- $this->greaterThan(1.9)
- );
- }
- /**
- * Ensures that getTotalNumQueries() behaves as expected for basic usage.
- *
- * @return void
- */
- public function testProfilerGetTotalNumQueries()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $numQueries = 3;
- for ($queryCount = 0; $queryCount < $numQueries; ++$queryCount) {
- $this->_db->query("sql $queryCount");
- }
- $this->assertEquals($numQueries, $prof->getTotalNumQueries());
- }
- /**
- * Ensures that getTotalNumQueries() only counts queries of the specified type(s).
- *
- * @return void
- */
- public function testProfilerGetTotalNumQueriesFilterQueryType()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $queries = array(
- 'INSERT' => 2,
- 'UPDATE' => 5,
- 'DELETE' => 1,
- 'SELECT' => 3
- );
- foreach ($queries as $querySql => $queryCount) {
- for ($i = 0; $i < $queryCount; ++$i) {
- $this->_db->query("$querySql $i");
- }
- }
- foreach ($queries as $querySql => $queryCount) {
- $this->assertEquals($queryCount, $prof->getTotalNumQueries(constant("Zend_Db_Profiler::$querySql")));
- }
- }
- /**
- * Ensures that getLastQueryProfile() returns false when no queries have been profiled.
- *
- * @return void
- */
- public function testProfilerGetLastQueryProfileFalse()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $this->assertFalse($prof->getLastQueryProfile());
- }
- /**
- * Ensures that getLastQueryProfile() returns the last query profiled, regardless whether it has ended.
- *
- * @return void
- */
- public function testProfilerGetLastQueryProfile()
- {
- $prof = $this->_db->getProfiler()
- ->setEnabled(true);
- $this->_db->query('sql 1');
- $prof->queryStart('sql 2');
- $queryProfile = $prof->getLastQueryProfile();
- $this->assertTrue($queryProfile instanceof Zend_Db_Profiler_Query);
- $this->assertEquals('sql 2', $queryProfile->getQuery());
- $this->assertFalse($queryProfile->getElapsedSecs());
- }
- public function getDriver()
- {
- return 'Static';
- }
- }
|